From 7ccb0494ee8e422cf405f3480d8501bdfc45647c Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Sat, 29 May 2021 11:29:27 +0200 Subject: [PATCH] Added cluster tests. --- .../resources/ui/images/cluster_node_icon.png | Bin 0 -> 803 bytes .../resources/ui/images/shard_node_icon.png | Bin 0 -> 795 bytes .../serialization/ClusterSerializerTest.java | 50 +++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/ui/images/cluster_node_icon.png create mode 100644 src/main/resources/ui/images/shard_node_icon.png 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 0000000000000000000000000000000000000000..93e7c270fbb168ce43ca0ff6ac1399d5b53ea59c GIT binary patch literal 803 zcmV+;1Kj+HP)=X!LUOLo{5YZtzbV*hbBBQ+&9wP7(iqOGZhoBT94}zV-$PC1tX+vz=c^y_`*PR`v zo$==XHt)Uf{r~TM@B6-ieFVTtTH`BejR(mQ4YIh&;2w$s_v_6e^)9qc?Qq}|AQ6XC ziE&w~Cy(Lf)FEwfwWH!F&wxhYKv9@b)U}veId7nG_aX7^^L-`z=%sFnGI77fnMMu z5C>2t>qX%$K=@qt6$knR`f5bC3Oui_fn_fW?-|ev0rf$=b9f4f8o>obod5!g4Xgqh zfM1I-zIz3@o`RpZwXOev;!zKq1Xp1SgcH66-V-?Nu;4fEe<5e;Qf^oWYxylxujNc#+!JyD hdsq*L5wnkS{001Z*iYuC9&7*r002ovPDHLkV1jGleK~z|U?Uq4E6k!y{e{Xip-6#nx$XKG56r@X35P0Yi5vlkPLSfB{MK$F{Q?x*TEIn-Pvh$ zW^ev)^WOX3|Mz|Kee(_M$cNfzHQGL_Q9nHlUxO{~ip3p2J!HEB%_*%x_ymY;aH8*s zOl+r*>k71uX_;d}RaAHelmolOrXN+u$rSC8mFo(aDIGzvfk7+7>&MlS253)dizqMh z%3FHlG5~9P1B-f~S)igfE|-gWgxvsCnGMPY+jsGMER{ zhrdRI?`{Q-r{LDK)*2aFL}*p0^Z@{nR(Pet)4rqfu_(a3lt$9ZC4n}DdY`7w62=7* zE6cp>KQ2p<^9q)PD&RrM%mI{Bs&qyo9NJ*Y(TzE+EVmd!sVfn}m|=6V` zcW$s?1;oNEfjK~xE^{+KSa2N+yj8fOLdbxMYVii6(gcop_l`V{U?duu9$Ol-vSk8pQoD_JMSN=Y50RC(M zC?qPDsq2Z$OxI!gws(fJD38|jtE-HA?zyl! literal 0 HcmV?d00001 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."); + } }