diff --git a/src/main/resources/ui/images/cluster_node_icon.png b/src/main/resources/ui/images/cluster_node_icon.png new file mode 100644 index 0000000..93e7c27 Binary files /dev/null and b/src/main/resources/ui/images/cluster_node_icon.png differ diff --git a/src/main/resources/ui/images/shard_node_icon.png b/src/main/resources/ui/images/shard_node_icon.png new file mode 100644 index 0000000..efa63a5 Binary files /dev/null and b/src/main/resources/ui/images/shard_node_icon.png differ diff --git a/src/test/java/nl/andrewlalis/crystalkeep/model/serialization/ClusterSerializerTest.java b/src/test/java/nl/andrewlalis/crystalkeep/model/serialization/ClusterSerializerTest.java index 67fcb49..8248f8a 100644 --- a/src/test/java/nl/andrewlalis/crystalkeep/model/serialization/ClusterSerializerTest.java +++ b/src/test/java/nl/andrewlalis/crystalkeep/model/serialization/ClusterSerializerTest.java @@ -1,5 +1,6 @@ package nl.andrewlalis.crystalkeep.model.serialization; +import nl.andrewlalis.crystalkeep.model.Cluster; import nl.andrewlalis.crystalkeep.model.Shard; import nl.andrewlalis.crystalkeep.model.shards.LoginCredentialsShard; import nl.andrewlalis.crystalkeep.model.shards.TextShard; @@ -10,6 +11,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -41,7 +43,7 @@ public class ClusterSerializerTest { assertEquals( s1.getName(), new String(Arrays.copyOfRange(data, 4, 4 + s1.getName().length())), - "First letter of shard name does not match expected." + "Shard name does not match expected." ); Shard loadedS1 = ClusterSerializer.readShard(new ByteArrayInputStream(data)); @@ -51,4 +53,50 @@ public class ClusterSerializerTest { byte[] data2 = bos.toByteArray(); assertArrayEquals(data, data2, "Serialized data from a shard should not change."); } + + private static List testClusterIOData() { + List clusters = new ArrayList<>(); + clusters.add(new Cluster("test")); + + Cluster c1 = new Cluster("c1"); + c1.addCluster(new Cluster("c2")); + clusters.add(c1); + + Cluster c2 = new Cluster("c2"); + c2.addShard(new TextShard("testing", LocalDateTime.now(), "Hello world!")); + clusters.add(c2); + + Cluster c3 = new Cluster("c3"); + Cluster c3Nested = new Cluster("nested"); + c3Nested.addShard(new LoginCredentialsShard("login", LocalDateTime.now(), "andrew", "secret password")); + c3.addCluster(c3Nested); + clusters.add(c3); + return clusters; + } + + @ParameterizedTest + @MethodSource("testClusterIOData") + public void testClusterIO(Cluster c) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ClusterSerializer.writeCluster(c, bos); + byte[] data = bos.toByteArray(); + assertNotEquals(0, data.length, "Serialized cluster should never result in empty bytes."); + assertEquals( + c.getName().length(), + ByteUtils.toInt(Arrays.copyOfRange(data, 0, 4)), + "Serialized cluster name length does not match expected." + ); + assertEquals( + c.getName(), + new String(Arrays.copyOfRange(data, 4, 4 + c.getName().length())), + "Cluster name does not match expected." + ); + + Cluster loaded = ClusterSerializer.readCluster(new ByteArrayInputStream(data), null); + assertEquals(c, loaded, "Loaded cluster should equal original cluster."); + bos.reset(); + ClusterSerializer.writeCluster(loaded, bos); + byte[] data2 = bos.toByteArray(); + assertArrayEquals(data, data2, "Serialized cluster should not change."); + } }