Example #1
0
 @Test
 public void testResponse() throws Exception {
   WebClient webClient = new WebClient();
   TextPage page = webClient.getPage(url);
   assertEquals("Pong", page.getContent());
   webClient.closeAllWindows();
 }
 private void assertComponentInstancesNotEqual(String mode) throws Exception {
   WebClient webClient = new WebClient();
   webClient.setThrowExceptionOnFailingStatusCode(true);
   TextPage page = webClient.getPage(contextPath + "test?mode=" + mode);
   String[] ids = page.getContent().split(":");
   System.out.println(Arrays.toString(ids));
   assertEquals(ids.length, 2);
   assertNotEquals(ids[0], ids[1]);
 }
  /**
   * The request context is destroyed at the end of the servlet request, after the service() method
   * and all doFilter() methods, and all requestDestroyed() notifications return.
   */
  @Test
  @SpecAssertions({
    @SpecAssertion(section = REQUEST_CONTEXT_EE, id = "ba"),
    @SpecAssertion(section = REQUEST_CONTEXT_EE, id = "bb"),
    @SpecAssertion(section = REQUEST_CONTEXT_EE, id = "bc")
  })
  public void testRequestScopeIsDestroyedAfterServletRequest() throws Exception {

    WebClient webClient = new WebClient();
    webClient.setThrowExceptionOnFailingStatusCode(true);

    // First request - response content contains SimpleRequestBean id
    TextPage firstRequestResult = webClient.getPage(contextPath + "introspect");
    assertNotNull(firstRequestResult.getContent());
    // Make a second request and make sure the same context is not there (compare SimpleRequestBean
    // ids)
    TextPage secondRequestResult = webClient.getPage(contextPath + "introspect");
    assertNotNull(secondRequestResult.getContent());
    assertNotEquals(
        secondRequestResult.getContent().trim(), firstRequestResult.getContent().trim());

    // Make sure request context is destroyed after service(), doFilter(), requestDestroyed()
    webClient.getPage(contextPath + "introspect?mode=collect");
    ActionSequence correctSequence =
        new ActionSequence()
            .add(IntrospectServlet.class.getName())
            .add(IntrospectFilter.class.getName())
            .add(TestServletRequestListener.class.getName())
            .add(ContextDestructionObserver.class.getName());
    TextPage destroyRequestResult = webClient.getPage(contextPath + "introspect?mode=verify");
    assertNotNull(destroyRequestResult.getContent());
    assertEquals(destroyRequestResult.getContent(), correctSequence.toString());
  }
  @Test
  @SpecAssertions({@SpecAssertion(section = CONVERSATION_CONTEXT, id = "bc")})
  public void testLifecycleEventFired() throws Exception {

    WebClient webClient = new WebClient();

    // Begin new long-running conversation
    TextPage page = webClient.getPage(contextPath + "test?action=begin");
    assertTrue(page.getContent().contains("cid:" + ConversationScopedBean.CID));

    // Invalidate HTTP session - destroy non-attached long-running conversation
    page = webClient.getPage(contextPath + "test?action=invalidate");

    // Get the info
    page = webClient.getPage(contextPath + "test?action=info");
    assertTrue(page.getContent().contains("destroyed cid:" + ConversationScopedBean.CID));
  }
 /**
  * Test cm server.
  *
  * @throws FailingHttpStatusCodeException the failing http status code exception
  * @throws MalformedURLException the malformed url exception
  * @throws IOException Signals that an I/O exception has occurred.
  */
 @Test
 public void testCMServer()
     throws FailingHttpStatusCodeException, MalformedURLException, IOException {
   final Properties settings = new Properties();
   settings.load(ApplicationStartupTest.class.getResourceAsStream("/test.properties"));
   final WebClient webClient = new WebClient();
   final Page page =
       webClient.getPage(
           "http://localhost:"
               + settings.getProperty("cargo.port")
               + settings.getProperty("cmserver.context")
               + "/diagnostics.ep");
   assertEquals(HTTP_STATUS_OK, page.getWebResponse().getStatusCode());
   assertTrue(page instanceof TextPage);
   TextPage textPage = (TextPage) page;
   assertEquals("I am alive!", textPage.getContent());
   webClient.closeAllWindows();
 }
  @Test
  public void testLifecycleEventFiredForTransientConversation() throws Exception {
    WebClient client = new WebClient();

    {
      TextPage page = client.getPage(url + "/display");
      assertTrue(
          page.getContent(),
          page.getContent()
              .contains("Initialized conversations:1")); // the current transient conversation
      assertTrue(
          page.getContent(),
          page.getContent().contains("Destroyed conversations:0")); // not destroyed yet
    }

    {
      TextPage page = client.getPage(url + "/display");
      assertTrue(page.getContent().contains("Initialized conversations:2"));
      assertTrue(page.getContent(), page.getContent().contains("Destroyed conversations:1"));
    }
  }