ConnectionDetailsView extends JPanel { public void setHttpData(@Nullable HttpData httpData) { setBackground(JBColor.background()); myTabs.forEach(tab -> tab.populateFor(httpData)); setVisible(httpData != null); revalidate(); repaint(); } ConnectionDetailsView(@NotNull NetworkProfilerStageView stageView); void setHttpData(@Nullable HttpData httpData);  }
@Test public void viewerForRequestPayloadIsPresentWhenRequestPayloadIsNotNull() { myView = new ConnectionDetailsView(myStageView); myTransportService.addFile(TEST_REQUEST_PAYLOAD_ID, ByteString.copyFromUtf8("Dummy Content")); HttpData data = new HttpData.Builder(DEFAULT_DATA).setRequestPayloadId(TEST_REQUEST_PAYLOAD_ID).setResponseFields(RESPONSE_HEADERS).build(); assertThat(HttpDataComponentFactory.findPayloadViewer(findTab(myView, RequestTabContent.class).findPayloadBody())).isNull(); myView.setHttpData(data); assertThat(HttpDataComponentFactory.findPayloadViewer(findTab(myView, RequestTabContent.class).findPayloadBody())).isNotNull(); }
@Test public void viewerForRequestPayloadIsAbsentWhenRequestPayloadIsNull() { myView = new ConnectionDetailsView(myStageView); HttpData data = new HttpData.Builder(DEFAULT_DATA).setResponseFields(RESPONSE_HEADERS).build(); myView.setHttpData(data); assertThat(HttpDataComponentFactory.findPayloadViewer(findTab(myView, RequestTabContent.class).findPayloadBody())).isNull(); }
@Test public void requestPayloadHasBothParsedViewAndRawDataView() { myView = new ConnectionDetailsView(myStageView); HttpData data = new HttpData.Builder(DEFAULT_DATA).setRequestFields("Content-Type = application/x-www-form-urlencoded") .setResponseFields(RESPONSE_HEADERS).setRequestPayloadId(TEST_REQUEST_PAYLOAD_ID) .build(); myTransportService.addFile(TEST_REQUEST_PAYLOAD_ID, ByteString.copyFromUtf8("a=1&b=2")); myView.setHttpData(data); JComponent payloadBody = findTab(myView, RequestTabContent.class).findPayloadBody(); assertThat(payloadBody).isNotNull(); assertThat(new TreeWalker(payloadBody).descendantStream().anyMatch(c -> c.getName().equals("View Parsed"))).isTrue(); assertThat(new TreeWalker(payloadBody).descendantStream().anyMatch(c -> c.getName().equals("View Source"))).isTrue(); }
@Test public void responsePayloadHasBothParsedViewAndRawDataView() { myView = new ConnectionDetailsView(myStageView); HttpData data = new HttpData.Builder(DEFAULT_DATA).setResponseFields("null = HTTP/1.1 302 Found\n Content-Type = application/x-www-form-urlencoded") .setResponsePayloadId(TEST_RESPONSE_PAYLOAD_ID).build(); myTransportService.addFile(TEST_RESPONSE_PAYLOAD_ID, ByteString.copyFromUtf8("a=1&b=2")); myView.setHttpData(data); JComponent payloadBody = findTab(myView, ResponseTabContent.class).findPayloadBody(); assertThat(payloadBody).isNotNull(); assertThat(new TreeWalker(payloadBody).descendantStream().anyMatch(c -> c.getName().equals("View Parsed"))).isTrue(); assertThat(new TreeWalker(payloadBody).descendantStream().anyMatch(c -> c.getName().equals("View Source"))).isTrue(); }
@Test public void viewIsVisibleWhenDataIsNotNull() { myView.setVisible(false); myView.setHttpData(DEFAULT_DATA); assertThat(myView.isVisible()).isTrue(); }
@Test public void viewIsNotVisibleWhenDataIsNull() { myView.setVisible(true); myView.setHttpData(null); assertThat(myView.isVisible()).isFalse(); }
@Test public void viewerExistsWhenPayloadIsPresent() { myTransportService.addFile(TEST_RESPONSE_PAYLOAD_ID, ByteString.copyFromUtf8("Dummy Content")); HttpData data = new HttpData.Builder(DEFAULT_DATA) .setResponseFields(RESPONSE_HEADERS) .setResponsePayloadId(TEST_RESPONSE_PAYLOAD_ID) .build(); assertThat(findTab(myView, OverviewTabContent.class).findResponsePayloadViewer()).isNull(); myView.setHttpData(data); assertThat(findTab(myView, OverviewTabContent.class).findResponsePayloadViewer()).isNotNull(); }
@Test public void contentTypeHasProperValueFromData() { assertThat(findTab(myView, OverviewTabContent.class).findContentTypeValue()).isNull(); HttpData data = new HttpData.Builder(DEFAULT_DATA).setResponseFields(RESPONSE_HEADERS).build(); myView.setHttpData(data); JLabel value = findTab(myView, OverviewTabContent.class).findContentTypeValue(); assertThat(value.getText()).isEqualTo("111"); }
@Test public void contentTypeIsAbsentWhenDataHasNoContentTypeValue() { myView.setHttpData(DEFAULT_DATA); assertThat(findTab(myView, OverviewTabContent.class).findContentTypeValue()).isNull(); }
@Test public void initiatingThreadFieldIsPresent() { myView.setHttpData(DEFAULT_DATA); assertThat(DEFAULT_DATA.getJavaThreads()).hasSize(1); assertThat(findTab(myView, OverviewTabContent.class).findInitiatingThreadValue()).isNotNull(); assertThat(findTab(myView, OverviewTabContent.class).findOtherThreadsValue()).isNull(); }
@Test public void otherThreadsFieldIsPresent() { HttpData data = new HttpData.Builder(DEFAULT_DATA).addJavaThread(new HttpData.JavaThread(2, "thread2")).build(); assertThat(data.getJavaThreads()).hasSize(2); myView.setHttpData(data); assertThat(findTab(myView, OverviewTabContent.class).findOtherThreadsValue()).isNotNull(); }
@Test public void urlHasProperValueFromData() { assertThat(findTab(myView, OverviewTabContent.class).findUrlValue()).isNull(); myView.setHttpData(DEFAULT_DATA); JTextArea value = findTab(myView, OverviewTabContent.class).findUrlValue(); assertThat(value.getText()).isEqualTo("dumbUrl"); }
@Test public void sizeHasProperValueFromData() { assertThat(findTab(myView, OverviewTabContent.class).findSizeValue()).isNull(); HttpData data = new HttpData.Builder(DEFAULT_DATA).setResponseFields(RESPONSE_HEADERS).build(); myView.setHttpData(data); JLabel value = findTab(myView, OverviewTabContent.class).findSizeValue(); assertThat(value.getText()).isEqualTo("222 B"); }
@Test public void timingFieldIsPresent() { assertThat(findTab(myView, OverviewTabContent.class).findTimingBar()).isNull(); myView.setHttpData(DEFAULT_DATA); assertThat(findTab(myView, OverviewTabContent.class).findTimingBar()).isNotNull(); }
@Test public void headerSectionIsSorted() { HttpData data = new HttpData.Builder(DEFAULT_DATA).setRequestFields(TEST_HEADERS).build(); myView.setHttpData(data); TabContent tabContent = findTab(myView, RequestTabContent.class); String text = firstDescendantWithType(tabContent.getComponent(), JTextPane.class).getText(); assertUiContainsLabelAndValue(text, "123", "numeric-value"); assertUiContainsLabelAndValue(text, "apple", "apple-value"); assertUiContainsLabelAndValue(text, "border", "border-value"); assertUiContainsLabelAndValue(text, "car", "car-value"); assertThat(text.indexOf("123")).isGreaterThan(-1); assertThat(text.indexOf("123")).isLessThan(text.indexOf("apple")); assertThat(text.indexOf("apple")).isLessThan(text.indexOf("border")); assertThat(text.indexOf("border")).isLessThan(text.indexOf("car")); }
@Test public void callStackViewHasProperValueFromData() { AspectObserver observer = new AspectObserver(); final int[] stackFramesChangedCount = {0}; StackTraceView stackTraceView = findTab(myView, CallStackTabContent.class).getStackTraceView(); stackTraceView.getModel().addDependency(observer) .onChange(StackTraceModel.Aspect.STACK_FRAMES, () -> stackFramesChangedCount[0]++); assertThat(stackFramesChangedCount[0]).isEqualTo(0); assertThat(stackTraceView.getModel().getCodeLocations()).hasSize(0); myView.setHttpData(DEFAULT_DATA); assertThat(stackFramesChangedCount[0]).isEqualTo(1); StackTrace stackTrace = new StackTrace(DEFAULT_DATA); assertThat(stackTraceView.getModel().getCodeLocations()).isEqualTo(stackTrace.getCodeLocations()); }
@Test public void callStackNavigationChangesProfilerMode() { HttpData data = new HttpData.Builder(DEFAULT_DATA).build(); myView.setHttpData(data); StackTrace stackTrace = new StackTrace(data); assertThat(stackTrace.getTrace()).isEqualTo(data.getTrace()); assertThat(stackTrace.getCodeLocations()).hasSize(1); myStage.getTimeline().getSelectionRange().set(0, 10); boolean[] modeChanged = {false}; AspectObserver observer = new AspectObserver(); myStage.getStudioProfilers().addDependency(observer).onChange(ProfilerAspect.MODE, () -> modeChanged[0] = true); assertThat(modeChanged[0]).isFalse(); assertThat(myStage.getProfilerMode()).isEqualTo(ProfilerMode.EXPANDED); StackTraceView stackTraceView = findTab(myView, CallStackTabContent.class).getStackTraceView(); stackTraceView.getModel().setSelectedIndex(0); assertThat(modeChanged[0]).isTrue(); assertThat(myStage.getProfilerMode()).isEqualTo(ProfilerMode.NORMAL); }