Refine search
@Test public void verifyExampleInClassLevelJavadoc() throws Exception { Assume.group(TestGroup.PERFORMANCE); WebClient webClient = new WebClient(); MockMvc mockMvc = MockMvcBuilders.standaloneSetup().build(); MockMvcWebConnection mockConnection = new MockMvcWebConnection(mockMvc, webClient); WebRequestMatcher cdnMatcher = new UrlRegexRequestMatcher(".*?//code.jquery.com/.*"); WebConnection httpConnection = new HttpWebConnection(webClient); webClient.setWebConnection( new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection))); Page page = webClient.getPage("http://code.jquery.com/jquery-1.11.0.min.js"); assertThat(page.getWebResponse().getStatusCode(), equalTo(200)); assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString())); }
@Test(groups = INTEGRATION) @SpecAssertion(section = FIELDS_INITIALIZER_METHODS_EE, id = "br") public void testFilterInitCalledAfterResourceInjection() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); webClient.getPage(contextPath + "TestFilter?test=resource"); webClient.getPage(contextPath + "TestFilter?test=ejb"); }
@Test(groups = INTEGRATION) @SpecAssertion(section = FIELDS_INITIALIZER_METHODS_EE, id = "bo") public void testServletInitCalledAfterResourceInjection() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); webClient.getPage(contextPath + "Test/Servlet?test=resource"); webClient.getPage(contextPath + "Test/Servlet?test=ejb"); }
/** * Runs the sanity check. * @throws Exception if anything goes wrong */ private static void runSanityCheck() throws Exception { try (WebClient webClient = new WebClient()) { final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net/index.html"); page.executeJavaScript("document.location"); System.out.println("Sanity check complete."); } }
@Test @SpecAssertion(section = CONVERSATION_CONTEXT_EE, id = "bd") 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)); }
public static JsonObject getPageAsJSONObject(String path, URL url, WebClient client) throws IOException { if (client == null) { client = new WebClient(); } JsonReader jsonReader = Json.createReader(client.getPage(url.toString().concat(path)).getWebResponse().getContentAsStream()); return jsonReader.readObject(); }
@Test(groups = INTEGRATION) @SpecAssertion(section = SESSION_CONTEXT_EE, id = "ae") public void testSessionScopeActiveDuringServletRequestListenerCall() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); // Create session webClient.getPage(contextPath + "introspect"); // Invalidate session webClient.getPage(contextPath + "introspect?mode=invalidate"); // Verify result TextPage page = webClient.getPage(contextPath + "introspect?mode=verify"); assertTrue(Boolean.valueOf(page.getContent())); }
@Test public void testOnStartAsyncCalledSuccesfully() throws Exception { WebClient webClient = new WebClient(); webClient.getPage(getPath(AsyncServlet.TEST_LOOP)); Page results = webClient.getPage(contextPath + "Status"); assertTrue(results.getWebResponse().getContentAsString().contains("onComplete: true")); assertTrue(results.getWebResponse().getContentAsString().contains("onStartAsync: true")); }
@Test @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "ga") public void testInitializedApplicationScopedEventObserved() throws IOException { WebClient client = new WebClient(); TextPage page1 = client.getPage(context + "/" + TEST1_ARCHIVE_NAME + "/ping"); TextPage page2 = client.getPage(context + "/" + TEST2_ARCHIVE_NAME + "/ping"); Assert.assertTrue(page1.getContent().toString().contains(ObserverNames.OBSERVER2_NAME)); Assert.assertTrue(page2.getContent().toString().contains(ObserverNames.OBSERVER3_NAME)); } }
@Test @Ignore //enable when WELD-1774 is fixed public void testOnErrorCalledSuccesfully() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(false); webClient.getPage(getPath(AsyncServlet.TEST_ERROR)); Page results = webClient.getPage(contextPath + "Status"); assertTrue(results.getWebResponse().getContentAsString(), results.getWebResponse().getContentAsString().contains("onError: true")); }
@Test @SpecAssertion(section = OBSERVER_ORDERING, id = "b") public void testContextLifecycleEventOrdering() throws IOException { WebClient client = new WebClient(); TextPage page = client.getPage(contextPath); Assert.assertTrue(page.getContent().toString().contains("Initialized observer sequence: " + seq)); TextPage page2 = client.getPage(contextPath); Assert.assertTrue(page2.getContent().toString().contains("Initialized observer sequence: " + seq + seq)); Assert.assertTrue(page2.getContent().toString().contains("Destroyed observer sequence: " + seq)); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "ae") public void testApplicationContextActiveOnComplete() throws Exception { WebClient webClient = new WebClient(); // make async request webClient.getPage(getPath(AsyncServlet.TEST_COMPLETE)); // check the status servlet results TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onComplete: true")); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertion(section = REQUEST_CONTEXT_EE, id = "ad") public void testRequestContextActiveOnStartAsync() throws Exception { WebClient webClient = new WebClient(); webClient.getPage(getPath(AsyncServlet.TEST_LOOP)); TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onStartAsync: true")); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "ae") public void testApplicationContextActiveOnStartAsync() throws Exception { WebClient webClient = new WebClient(); webClient.getPage(getPath(AsyncServlet.TEST_LOOP)); TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onStartAsync: true")); assertTrue(results.getContent().contains("onComplete: true")); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "ae") public void testApplicationContextActiveOnTimeout() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(false); webClient.getPage(getPath(AsyncServlet.TEST_TIMEOUT)); TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onTimeout: true")); }
@Test(groups = INTEGRATION) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "aa") public void testApplicationScopeActiveDuringServiceMethod() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); webClient.getPage(contextPath + "TestServlet?test=servlet"); }
@Test(groups = INTEGRATION) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "af") public void testApplicationScopeActiveDuringServletRequestListenerInvocation() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); webClient.getPage(contextPath + "TestServlet?test=servletRequestListener"); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertion(section = REQUEST_CONTEXT_EE, id = "ad") public void testRequestContextActiveOnError() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(false); webClient.getPage(getPath(AsyncServlet.TEST_ERROR)); TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onError: true")); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "ae") public void testApplicationContextActiveOnError() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(false); webClient.getPage(getPath(AsyncServlet.TEST_ERROR)); TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onError: true")); }
@Test(groups = INTEGRATION) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "ab") public void testApplicationScopeActiveDuringDoFilterMethod() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); webClient.getPage(contextPath + "SimplePage.html"); }