@Test public void uri() throws Exception { final ODataContext context = mockContext(ODataHttpMethod.GET); final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null); UriInfo uriInfo = mock(UriInfo.class); final FilterExpression filter = UriParser.parseFilter(null, null, "true"); when(uriInfo.getFilter()).thenReturn(filter); final OrderByExpression orderBy = UriParser.parseOrderBy(null, null, "true"); when(uriInfo.getOrderBy()).thenReturn(orderBy); List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>(); NavigationPropertySegment segment = mock(NavigationPropertySegment.class); EdmNavigationProperty navigationProperty = mock(EdmNavigationProperty.class); when(navigationProperty.getName()).thenReturn("nav"); when(segment.getNavigationProperty()).thenReturn(navigationProperty); ArrayList<NavigationPropertySegment> segments = new ArrayList<NavigationPropertySegment>(); segments.add(segment); expand.add(segments); when(uriInfo.getExpand()).thenReturn(expand); SelectItem select1 = mock(SelectItem.class); SelectItem select2 = mock(SelectItem.class); EdmProperty property = mock(EdmProperty.class); when(property.getName()).thenReturn("property"); when(select1.getProperty()).thenReturn(property); when(select2.getProperty()).thenReturn(property); when(select2.getNavigationPropertySegments()).thenReturn(segments); when(uriInfo.getSelect()).thenReturn(Arrays.asList(select1, select2)); ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null, ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse(); String entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals(EXPECTED.replace("null}}", "null," + "\"uri\":{\"filter\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"}," + "\"orderby\":{\"nodeType\":\"order collection\"," + "\"orders\":[{\"nodeType\":\"ORDER\",\"sortorder\":\"asc\"," + "\"expression\":{\"nodeType\":\"LITERAL\",\"type\":\"Edm.Boolean\",\"value\":\"true\"}}]}," + "\"expandSelect\":{\"all\":false,\"properties\":[\"property\"]," + "\"links\":[{\"nav\":{\"all\":false,\"properties\":[\"property\"],\"links\":[]}}]}}}}"), entity); response = new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, null, ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse(); entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertTrue(entity.contains("Edm.Boolean")); assertTrue(entity.contains("asc")); }
public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
      final Exception exception, final String debugValue); }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
      final Exception exception, final String debugValue); ODataResponse wrapResponse(); }
ODataDebugResponseWrapper { public ODataResponse wrapResponse() { try { final List<DebugInfo> parts = createParts(); ODataResponseBuilder builder = ODataResponse.status(HttpStatusCodes.OK) .entity(isJson ? wrapInJson(parts) : wrapInHtml(parts)) .contentHeader(isJson ? HttpContentType.APPLICATION_JSON_UTF8 : HttpContentType.TEXT_HTML); if (isDownload) { builder.header("Content-Disposition", "attachment; filename=OData-Response." + new Date().toString().replace(' ', '_').replace(':', '.') + ".html"); } return builder.build(); } catch (final ODataException e) { throw new ODataRuntimeException("Should not happen", e); } catch (final IOException e) { throw new ODataRuntimeException("Should not happen", e); } } ODataDebugResponseWrapper(final ODataContext context, final ODataResponse response, final UriInfo uriInfo,
      final Exception exception, final String debugValue); ODataResponse wrapResponse(); static final String ODATA_DEBUG_QUERY_PARAMETER; static final String ODATA_DEBUG_JSON; static final String ODATA_DEBUG_HTML; static final String ODATA_DEBUG_DOWNLOAD; }