DebugTabUri implements DebugTab { @Override public String getName() { return "URI"; } DebugTabUri(final UriInfo uriInfo); @Override String getName(); @Override void appendJson(final JsonGenerator gen); @Override void appendHtml(final Writer writer);  }
@Test public void select() throws Exception { EdmProperty edmProperty = mock(EdmProperty.class); when(edmProperty.getName()).thenReturn("property"); final DebugTabUri tab = new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new SelectOptionImpl().setSelectItems(Arrays.asList( (SelectItem) new SelectItemImpl().setStar(true), new SelectItemImpl().setResourcePath( new UriInfoImpl().setKind(UriInfoKind.resource) .addResourcePart(new UriResourcePrimitivePropertyImpl(edmProperty))))))); assertEquals("{\"kind\":\"all\",\"select\":[\"*\",\"property\"]}", createJson(tab)); assertEquals("<h2>Kind</h2>\n" + "<p>all</p>\n" + "<h2>Selected Properties</h2>\n" + "<ul>\n" + "<li>*</li>\n" + "<li>property</li>\n" + "</ul>\n", createHtml(tab)); }
@Test public void expand() throws Exception { EdmNavigationProperty edmProperty = mock(EdmNavigationProperty.class); when(edmProperty.getName()).thenReturn("property"); final DebugTabUri tab = new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new ExpandOptionImpl().addExpandItem( new ExpandItemImpl().setResourcePath( new UriInfoImpl().setKind(UriInfoKind.resource) .addResourcePart(new UriResourceNavigationPropertyImpl(edmProperty))) .setSystemQueryOption(new LevelsOptionImpl().setValue(1))))); assertEquals("{\"kind\":\"all\",\"expand\":[{\"expandPath\":[" + "{\"uriResourceKind\":\"navigationProperty\",\"segment\":\"property\",\"isCollection\":false}]," + "\"levels\":1}]}", createJson(tab)); final String html = createHtml(tab); assertThat(html, allOf( startsWith("<h2>Kind</h2>\n" + "<p>all</p>\n" + "<h2>Expand Option</h2>\n" + "<ul>\n" + "<li class=\"json\">"), containsString("navigationProperty"), containsString("property"), containsString("isCollection"), containsString("false"))); assertThat(html, allOf(containsString("levels"), endsWith("</li>\n</ul>\n"))); }
@Test public void filter() throws Exception { final DebugTabUri tab = new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new FilterOptionImpl().setExpression( new BinaryImpl(new LiteralImpl("1", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64)), BinaryOperatorKind.GT, new LiteralImpl("2", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte)), EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean))))); assertEquals("{\"kind\":\"all\",\"filter\":{" + "\"nodeType\":\"binary\",\"operator\":\"gt\",\"type\":\"Boolean\"," + "\"left\":{\"nodeType\":\"literal\",\"type\":\"Edm.Int64\",\"value\":\"1\"}," + "\"right\":{\"nodeType\":\"literal\",\"type\":\"Edm.SByte\",\"value\":\"2\"}}}", createJson(tab)); assertThat(createHtml(tab), allOf( startsWith("<h2>Kind</h2>\n" + "<p>all</p>\n" + "<h2>Filter Option</h2>\n" + "<ul>\n" + "<li class=\"json\">"), containsString("nodeType"), containsString("binary"), containsString("operator"), containsString("gt"))); assertThat(createHtml(tab), allOf( containsString("literal"), containsString("Int64"), containsString("SByte"), containsString("2"), endsWith("</li>\n</ul>\n"))); assertEquals("{\"kind\":\"all\",\"filter\":{" + "\"nodeType\":\"method\",\"operator\":\"ceiling\",\"type\":\"Number\"," + "\"parameters\":[{\"nodeType\":\"literal\",\"type\":\"Edm.Decimal\",\"value\":\"1.5\"}]}}", createJson(new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new FilterOptionImpl().setExpression( new MethodImpl(MethodKind.CEILING, Arrays.asList( (Expression) new LiteralImpl("1.5", EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal))))))))); EdmEntityType edmEntityType = mock(EdmEntityType.class); when(edmEntityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("ns", "entityType")); EdmProperty edmProperty = mock(EdmProperty.class); when(edmProperty.getName()).thenReturn("property"); assertEquals("{\"kind\":\"all\",\"filter\":{" + "\"nodeType\":\"member\",\"type\":\"unknown\",\"typeFilter\":\"ns.entityType\"," + "\"resourceSegments\":[{\"nodeType\":\"primitiveProperty\",\"name\":\"property\",\"type\":\"unknown\"}]}}", createJson(new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new FilterOptionImpl().setExpression( new MemberImpl(new UriInfoImpl().setKind(UriInfoKind.resource) .addResourcePart(new UriResourcePrimitivePropertyImpl(edmProperty)), edmEntityType)))))); }
@Test public void apply() throws Exception { EdmProperty edmProperty = mock(EdmProperty.class); when(edmProperty.getName()).thenReturn("property"); final DebugTabUri tab = new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new ApplyOptionImpl().add(new AggregateImpl().addExpression( new AggregateExpressionImpl() .setPath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourcePrimitivePropertyImpl(edmProperty))) .setStandardMethod(StandardMethod.AVERAGE) .setAlias("average"))))); assertEquals("{\"kind\":\"all\",\"apply\":[{\"kind\":\"AGGREGATE\",\"aggregate\":[{" + "\"path\":[{\"uriResourceKind\":\"primitiveProperty\",\"segment\":\"property\",\"isCollection\":false}]," + "\"standardMethod\":\"AVERAGE\",\"as\":\"average\"}]}]}", createJson(tab)); final String html = createHtml(tab); assertThat(html, allOf( startsWith("<h2>Kind</h2>\n" + "<p>all</p>\n" + "<h2>Apply Option</h2>\n" + "<ul>\n" + "<li class=\"json\">"), containsString("kind"), containsString("AGGREGATE"), containsString("aggregate"), containsString("path"))); assertThat(html, allOf( containsString("primitiveProperty"), containsString("property"), containsString("standardMethod"), containsString("AVERAGE"))); assertThat(html, allOf( containsString("as"), containsString("average"), endsWith("</li>\n</ul>\n"))); assertEquals("{\"kind\":\"all\",\"apply\":[{\"kind\":\"GROUP_BY\",\"groupBy\":[{" + "\"path\":[{\"uriResourceKind\":\"primitiveProperty\",\"segment\":\"property\",\"isCollection\":false}]," + "\"isRollupAll\":true}]}]}", createJson(new DebugTabUri(new UriInfoImpl().setKind(UriInfoKind.all) .setSystemQueryOption(new ApplyOptionImpl().add(new GroupByImpl().addGroupByItem( new GroupByItemImpl().setIsRollupAll() .setPath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( new UriResourcePrimitivePropertyImpl(edmProperty))))))))); }