Skip to content

Commit

Permalink
FIXUP: add a test for nested lists and lists of scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenny Burdette committed Sep 12, 2019
1 parent d7109aa commit 5880924
Showing 1 changed file with 44 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ void setupSchema() {
objects.add(new Object());
objects.add(new Object());
return objects;
}))
}).dataFetcher("listOfLists", env -> {
ArrayList<ArrayList<Object>> lists = new ArrayList<>(2);
lists.add(new ArrayList<>(2));
lists.add(new ArrayList<>(2));
lists.get(0).add(new Object());
lists.get(0).add(new Object());
lists.get(1).add(new Object());
lists.get(1).add(new Object());
return lists;
})
.dataFetcher("listOfScalars", env -> new String[]{"one", "two", "three"}))
.type("Widget", builder ->
// Widget.foo works normally, Widget.bar always throws an error
builder.dataFetcher("foo", env -> "hello world")
Expand All @@ -58,7 +68,7 @@ void setupSchema() {

@Test
void testTracing() throws InvalidProtocolBufferException {
Map<String, Object> result = graphql.execute("{ widgets { foo, baz: bar } }").toSpecification();
Map<String, Object> result = graphql.execute("{ widgets { foo, baz: bar }, listOfLists { foo }, listOfScalars }").toSpecification();

Object extensions = result.get("extensions");
assertTrue(extensions instanceof Map);
Expand All @@ -72,7 +82,9 @@ void testTracing() throws InvalidProtocolBufferException {
assertTrue(trace.getEndTime().getSeconds() > 0, "End time has seconds");
assertTrue(trace.getEndTime().getNanos() > 0, "End time has nanoseconds");
assertTrue(trace.getDurationNs() > 0, "DurationNs is greater than zero");
assertEquals(1, trace.getRoot().getChildCount());
assertEquals(3, trace.getRoot().getChildCount());

// widgets

Reports.Trace.Node widgets = trace.getRoot().getChild(0);
assertTrue(widgets.getStartTime() > 0, "Field start time is greater than zero");
Expand Down Expand Up @@ -110,5 +122,34 @@ void testTracing() throws InvalidProtocolBufferException {
assertEquals(18, error.getLocation(0).getColumn());
assertEquals(1, error.getLocation(0).getLine());

// listOfLists

Reports.Trace.Node listOfLists = trace.getRoot().getChild(1);
assertEquals(0, listOfLists.getChild(0).getIndex());
assertEquals(2, listOfLists.getChild(0).getChildCount());
assertEquals(1, listOfLists.getChild(1).getIndex());
assertEquals(2, listOfLists.getChild(1).getChildCount());

assertEquals(0, listOfLists.getChild(0).getChild(0).getIndex());
assertEquals(1, listOfLists.getChild(0).getChild(0).getChildCount());
assertEquals(0, listOfLists.getChild(0).getChild(1).getIndex());
assertEquals(1, listOfLists.getChild(0).getChild(1).getChildCount());

Reports.Trace.Node deeplyNestedFoo = listOfLists.getChild(0).getChild(0).getChild(0);
assertTrue(deeplyNestedFoo.getStartTime() > 0, "Field start time is greater than zero");
assertTrue(deeplyNestedFoo.getEndTime() > 0, "Field end time is greater than zero");
assertEquals("Widget", deeplyNestedFoo.getParentType());
assertEquals("String", deeplyNestedFoo.getType());
assertEquals("foo", deeplyNestedFoo.getResponseName());
assertEquals(0, deeplyNestedFoo.getErrorCount());

// listOfScalars

Reports.Trace.Node listOfScalars = trace.getRoot().getChild(2);
assertTrue(listOfScalars.getStartTime() > 0, "Field start time is greater than zero");
assertTrue(listOfScalars.getEndTime() > 0, "Field end time is greater than zero");
assertEquals("Query", listOfScalars.getParentType());
assertEquals("[String]", listOfScalars.getType());
assertEquals("listOfScalars", listOfScalars.getResponseName());
}
}

0 comments on commit 5880924

Please sign in to comment.