@Test public void runtime() throws Exception { ODataContext context = mockContext(ODataHttpMethod.GET); List<RuntimeMeasurement> runtimeMeasurements = new ArrayList<RuntimeMeasurement>(); runtimeMeasurements.add(mockRuntimeMeasurement("method", 1000, 42000)); runtimeMeasurements.add(mockRuntimeMeasurement("inner", 2000, 5000)); runtimeMeasurements.add(mockRuntimeMeasurement("inner", 7000, 12000)); runtimeMeasurements.add(mockRuntimeMeasurement("inner", 13000, 16000)); runtimeMeasurements.add(mockRuntimeMeasurement("inner2", 14000, 15000)); runtimeMeasurements.add(mockRuntimeMeasurement("child", 17000, 21000)); runtimeMeasurements.add(mockRuntimeMeasurement("second", 45000, 99000)); when(context.getRuntimeMeasurements()).thenReturn(runtimeMeasurements); final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.OK, null, null); ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null, ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse(); String entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals(EXPECTED.replace("null}}", "null," + "\"runtime\":[{\"class\":\"class\",\"method\":\"method\",\"duration\":{\"value\":41,\"unit\":\"µs\"}," + "\"children\":[{\"class\":\"class\",\"method\":\"inner\",\"duration\":{\"value\":8,\"unit\":\"µs\"}}," + "{\"class\":\"class\",\"method\":\"inner\",\"duration\":{\"value\":3,\"unit\":\"µs\"},\"children\":[" + "{\"class\":\"class\",\"method\":\"inner2\",\"duration\":{\"value\":1,\"unit\":\"µs\"}}]}," + "{\"class\":\"class\",\"method\":\"child\",\"duration\":{\"value\":4,\"unit\":\"µs\"}}]}," + "{\"class\":\"class\",\"method\":\"second\",\"duration\":{\"value\":54,\"unit\":\"µs\"}}]}}"), entity); response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null, ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse(); entity = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertTrue(entity.contains("54&nbsp;&micro;s")); }
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; }