@Test public void testEmptyDocument() throws IOException { try { decodeString("{}"); fail("Expected IOException"); } catch (IOException e) { // expected case } }
@Test public void testDocWithNoTraces() throws IOException { final String json = buildJson(new String[0], new String[0], "test", 0L); Trace trace = decodeString(json); assertEquals(0, trace.getTraceMap().size()); assertEquals(0, trace.getRelationships().size()); }
@Test public void testDocWitInvalidParentReference() throws IOException { final String json = buildJson(new String[] { traceStr(1, "name", ResultType.UNFINISHED, false) }, new String[] { hierStr(2, 1) }, "test", 0L); try { decodeString(json); fail("Expected IOException"); } catch (IOException e) { // expected case } }
@Test public void testDocWitInvalidPredecessorReference() throws IOException { final String json = buildJson(new String[] { traceStr(1, "name", ResultType.UNFINISHED, false) }, new String[] { orderStr(2, 1) }, "test", 0L); try { decodeString(json); fail("Expected IOException"); } catch (IOException e) { // expected case } }
@Test public void testDocWitInvalidChildReference() throws IOException { final String json = buildJson(new String[] { traceStr(1, "name", ResultType.UNFINISHED, false) }, new String[] { hierStr(1, 2) }, "test", 0L); try { decodeString(json); fail("Expected IOException"); } catch (IOException e) { // expected case } }
@Test public void testDocWitInvalidSuccessorReference() { final String json = buildJson(new String[] { traceStr(1, "name", ResultType.UNFINISHED, false) }, new String[] { orderStr(1, 2) }, "test", 0L); try { decodeString(json); fail("Expected IOException"); } catch (IOException e) { // expected case } }
@Test public void testDocWithTraceHavingTaskType() throws IOException { final String json = buildJson(new String[] {traceStr(1, "name", ResultType.UNFINISHED, false, TaskType.FUSION.getName())}, new String[0], "test", 0L); Trace decodedTrace = decodeString(json); assertEquals(decodedTrace.getTraceMap().get(1L).getTaskType(), TaskType.FUSION.getName()); }
@Test public void testCustomBuilding() throws IOException { final String json = buildJson( new String[] { traceStr(1, "parent", ResultType.UNFINISHED, false), traceStr(2, "child", ResultType.UNFINISHED, false), traceStr(3, "predecessor", ResultType.UNFINISHED, false) }, new String[] { hierStr(1, 2), orderStr(3, 1) }, "test", 0L); final Trace trace; try { trace = decodeString(json); } catch (IOException e) { fail("JSON parse failed. Document:\n" + json + "\nError: " + e.toString()); return; } assertEquals("parent", trace.getTraceMap().get(1L).getName()); assertEquals(ResultType.UNFINISHED, trace.getTraceMap().get(1L).getResultType()); assertEquals(2, trace.getRelationships().size()); String childName = null; String predecessorName = null; for (TraceRelationship rel : trace.getRelationships()) { if (rel.getRelationhsip() == Relationship.PARENT_OF) { childName = trace.getTraceMap().get(rel.getTo()).getName(); } else if (rel.getRelationhsip() == Relationship.SUCCESSOR_OF) { predecessorName = trace.getTraceMap().get(rel.getTo()).getName(); } } assertEquals("child", childName); assertEquals("predecessor", predecessorName); }