blob: fa419f5f1c9dc018032e75478e8e1c6d9f240f3f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package pl.edu.mimuw.cloudatlas.model;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import org.junit.Test;
import static org.junit.Assert.*;
public class ZMITest {
@Test
public void testSimpleSerialization1() {
ZMI zmi = new ZMI();
AttributesMap attributes = zmi.getAttributes();
attributes.add("foo", new ValueInt(42l));
serializationTest(zmi);
}
@Test
public void testSimpleSerialization2() {
ZMI zmi = new ZMI();
AttributesMap attributes = zmi.getAttributes();
attributes.add("foo", new ValueInt(42l));
attributes.add("bar", new ValueDuration("+1 11:43:45.342"));
serializationTest(zmi);
}
@Test
public void testHierarchySerialization() {
ZMI root = new ZMI();
AttributesMap rootAttributes = root.getAttributes();
rootAttributes.add("foo", new ValueInt(42l));
rootAttributes.add("bar", new ValueDuration("+1 11:43:45.342"));
ZMI son1 = new ZMI(root);
root.addSon(son1);
AttributesMap son1Attributes = son1.getAttributes();
son1Attributes.add("foo", new ValueInt(43l));
son1Attributes.add("bar", new ValueDuration("+1 12:43:47.342"));
ZMI son2 = new ZMI(root);
root.addSon(son2);
AttributesMap son2Attributes = son2.getAttributes();
son2Attributes.add("foo", new ValueInt(47l));
son2Attributes.add("bar", new ValueDuration("+1 15:45:43.342"));
ZMI grandson1 = new ZMI(son1);
son1.addSon(grandson1);
AttributesMap grandson1Attributes = grandson1.getAttributes();
grandson1Attributes.add("foo", new ValueInt(52l));
grandson1Attributes.add("bar", new ValueDuration("-2 15:45:43.342"));
serializationTest(root);
serializationTest(son1);
serializationTest(grandson1);
}
private void serializationTest(ZMI zmi) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
zmi.serialize(out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
ZMI zmi2 = ZMI.deserialize(in);
assertEquals(zmi.toString(), zmi2.toString());
}
}
|