diff options
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/pl/edu/mimuw/cloudatlas/model/ValueDurationTest.java (renamed from src/test/java/pl/edu/mimuw/cloudatlas/ValueDurationTest.java) | 0 | ||||
-rw-r--r-- | src/test/java/pl/edu/mimuw/cloudatlas/model/ZMITest.java | 72 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/ValueDurationTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/model/ValueDurationTest.java index 9db36eb..9db36eb 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/ValueDurationTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/model/ValueDurationTest.java diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/model/ZMITest.java b/src/test/java/pl/edu/mimuw/cloudatlas/model/ZMITest.java new file mode 100644 index 0000000..fa419f5 --- /dev/null +++ b/src/test/java/pl/edu/mimuw/cloudatlas/model/ZMITest.java @@ -0,0 +1,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()); + } +} |