コード例 #1
0
  @Test
  public void testConstructorAndDispose() throws Exception {
    verifyNoMoreInteractions(m_resultProcessor);

    assertNotNull(m_httpRecording.getParameters());
    assertSame(m_httpRecording.getParameters(), m_httpRecording.getParameters());

    m_httpRecording.dispose();
    m_httpRecording.dispose();

    verify(m_resultProcessor, times(2)).process(m_recordingCaptor.capture());

    final HttpRecordingDocument recording = m_recordingCaptor.getAllValues().get(0);
    final HttpRecordingDocument recording2 = m_recordingCaptor.getAllValues().get(1);

    XMLBeansUtilities.validate(recording);
    XMLBeansUtilities.validate(recording2);

    assertNotSame("We get a copy", recording, recording2);

    final Metadata metadata = recording.getHttpRecording().getMetadata();
    assertTrue(metadata.getVersion().length() > 0);
    assertNotNull(metadata.getTime());
    assertEquals(0, recording.getHttpRecording().getCommonHeadersArray().length);
    assertEquals(0, recording.getHttpRecording().getBaseUriArray().length);
    assertEquals(0, recording.getHttpRecording().getPageArray().length);
    verifyNoMoreInteractions(m_resultProcessor);

    final IOException exception = new IOException("Eat me");
    doThrow(exception).when(m_resultProcessor).process(isA(HttpRecordingDocument.class));

    m_httpRecording.dispose();

    verify(m_logger).error(exception.getMessage(), exception);
  }
コード例 #2
0
  @Test
  public void testAddRequest() throws Exception {
    final EndPoint endPoint3 = new EndPoint("hostC", 80);
    final String[] userComments =
        new String[] {
          "BEGIN ENTER gmail homepage",
          "END ENTER gmail homepage",
          "BEGIN CLICK Sign In",
          "END CLICK Sign In",
        };

    // Request 1
    final RequestType request1 = m_httpRecording.addRequest(m_connectionDetails1, "GET", "/");
    for (final String userComment : userComments) {
      request1.addComment(userComment);
    }
    assertEquals("/", request1.getUri().getUnparsed());
    assertEquals("GET", request1.getMethod().toString());
    assertEquals("GET /", request1.getDescription());
    assertArrayEquals(userComments, request1.getCommentArray());
    assertEquals("END CLICK Sign In", request1.getCommentArray(3));
    assertFalse(request1.isSetSleepTime());
    request1.addNewResponse();
    m_httpRecording.markLastResponseTime();

    // Request 2
    final ConnectionDetails connectionDetails2 = new ConnectionDetails(endPoint1, endPoint2, false);

    final RequestType request2 = m_httpRecording.addRequest(connectionDetails2, "GET", "/foo.gif");
    assertFalse(request2.isSetSleepTime());
    request2.addNewResponse();
    m_httpRecording.markLastResponseTime();
    Thread.sleep(20);

    // Request 3
    final ConnectionDetails connectionDetails3 = new ConnectionDetails(endPoint3, endPoint2, true);

    final RequestType request3 = m_httpRecording.addRequest(connectionDetails3, "GET", "bah.gif");
    assertEquals("bah.gif", request3.getUri().getUnparsed());
    assertTrue(request3.isSetSleepTime());
    request3.addNewResponse().setStatusCode(302);
    assertFalse(request3.isSetAnnotation());

    final RequestType request4 = m_httpRecording.addRequest(connectionDetails3, "GET", "bah.gif");
    request4.addNewResponse().setStatusCode(301);
    assertFalse(request4.isSetAnnotation());

    final RequestType request5 = m_httpRecording.addRequest(connectionDetails3, "GET", "bah.gif");
    request5.addNewResponse().setStatusCode(307);
    assertFalse(request5.isSetAnnotation());

    // Ignored because it doesn't have a response.
    m_httpRecording.addRequest(connectionDetails3, "GET", "bah.gif");

    m_httpRecording.dispose();

    verify(m_resultProcessor).process(m_recordingCaptor.capture());

    final HttpRecordingDocument recording = m_recordingCaptor.getValue();

    XMLBeansUtilities.validate(recording);

    verifyNoMoreInteractions(m_resultProcessor);

    final HTTPRecordingType result = recording.getHttpRecording();
    assertEquals(0, result.getCommonHeadersArray().length);

    assertEquals(2, result.getBaseUriArray().length);
    assertEquals("hostb", result.getBaseUriArray(0).getHost());
    assertEquals("https", result.getBaseUriArray(1).getScheme().toString());

    assertEquals(2, result.getPageArray().length);

    final PageType page0 = result.getPageArray(0);
    assertEquals(2, page0.getRequestArray().length);
    assertEquals(
        result.getBaseUriArray(0).getUriId(), page0.getRequestArray(1).getUri().getExtends());
    assertEquals("/foo.gif", page0.getRequestArray(1).getUri().getPath().getTextArray(0));
    assertFalse(page0.getRequestArray(1).isSetAnnotation());

    final PageType page1 = result.getPageArray(1);
    assertEquals(3, page1.getRequestArray().length);
    assertEquals(0, page1.getRequestArray(0).getHeaders().sizeOfHeaderArray());
    assertTrue(page1.getRequestArray(0).isSetAnnotation());
    assertTrue(page1.getRequestArray(1).isSetAnnotation());
    assertTrue(page1.getRequestArray(2).isSetAnnotation());
  }