@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)); } }
/** * Creates a TextPage for this WebResponse. * * @param webResponse the page's source * @param webWindow the WebWindow to place the TextPage in * @return the newly created TextPage */ protected TextPage createTextPage(final WebResponse webResponse, final WebWindow webWindow) { final TextPage newPage = new TextPage(webResponse, webWindow); webWindow.setEnclosedPage(newPage); return newPage; }
/** * Returns the content of this page. * * @return the content of this page */ public String getContent() { return getWebResponse().getContentAsString(); } }
@Test @SpecAssertion(section = PROCESS_INJECTION_TARGET_EE, id = "ec") public void testWrappedInjectionTargetUsedForServletListener() throws Exception { TextPage page = invokeContextPath("test?type=listener", TextPage.class); assertTrue(page.getContent().contains(Sheep.class.getName())); assertTrue(page.getContent().contains("true")); }
@Test(groups = {INTEGRATION, ASYNC_SERVLET}) @SpecAssertions({ @SpecAssertion(section = SESSION_CONTEXT_EE, id = "ad") }) public void testSessionContextActiveOnComplete() throws Exception { WebClient webClient = new WebClient(); webClient.getPage(getPath(AsyncServlet.TEST_COMPLETE)); TextPage results = webClient.getPage(contextPath + "Status"); assertTrue(results.getContent().contains("onComplete: true")); String id = extractSimpleSessionBeanId(results.getContent()); assertNotNull(id); assertFalse(id.isEmpty()); }
@Test(groups = INTEGRATION) @SpecAssertion(section = CONVERSATION_CONTEXT_EE, id = "ua") public void testConversationBusy() throws Exception { WebClient client = new WebClient(); client.setThrowExceptionOnFailingStatusCode(true); TextPage initPage = client.getPage(contextPath + "introspect?mode=" + IntrospectServlet.MODE_INIT); String cid = extractCid(initPage.getContent()); assertNotNull(cid); assertFalse(cid.isEmpty()); String jsessionid = client.getCookieManager().getCookie(JSESSIONID).getValue(); assertNotNull(jsessionid); assertFalse(jsessionid.isEmpty());
/** * The conversation context should not be active before the conversation is associated with the servlet request. * * @throws Exception */ @Test(groups = INTEGRATION) @SpecAssertion(section = CONVERSATION_CONTEXT_EE, id = "d") public void testConversationActivation() throws Exception { WebClient client = new WebClient(); client.setThrowExceptionOnFailingStatusCode(true); // Init the long-running conversation TextPage initPage = client.getPage(contextPath + "introspect?mode=" + IntrospectServlet.MODE_INIT); String cid = extractCid(initPage.getContent()); assertNotNull(cid); assertFalse(cid.isEmpty()); TextPage resultPage = client.getPage(contextPath + "introspect?mode=" + IntrospectServlet.MODE_INSPECT + "&cid=" + cid); assertFalse(Boolean.valueOf(resultPage.getContent())); }
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]); }
private void verifyNonexistentConversationExceptionThrown(Page page) { if(page instanceof TextPage) { TextPage textPage = (TextPage) page; assertTrue(textPage.getContent().contains("NonexistentConversationException thrown properly")); assertTrue(textPage.getContent().contains("Conversation.isTransient: true")); assertTrue(textPage.getContent().contains("Cloud: " + Cloud.NAME)); } else { fail("Unexpected response type: "+page.getClass().getName()); } } }
protected String beginConversation(WebClient client, boolean resetSequence) throws IOException { if (resetSequence) { client.getPage(getPath("/resetSequence", null)); } TextPage initialPage = client.getPage(getPath("/begin", null)); String content = initialPage.getContent(); assertTrue(content.contains("message: Hello")); assertTrue(content.contains("transient: false")); return getCid(content); }
/** * Makes sure @WebMethod(name="") has the intended effect of occupying the root of the object in the URL space. */ public void testIndexDispatchByName() throws Exception { WebClient wc = new WebClient(); TextPage p = wc.getPage(new URL(url, "indexDispatchByName")); assertEquals("Hello world", p.getContent()); }
WebClient c = new WebClient(BrowserVersion.INTERNET_EXPLORER_6); TextPage tp = c.getPage("yoururl"); String content = tp.getContent();
/** * Get the content page as a text String. * * @return the text */ public String getPageAsText() { if (getContentPage() instanceof HtmlPage) return ((HtmlPage)getContentPage()).asXml(); if (getContentPage() instanceof TextPage) return ((TextPage)getContentPage()).getContent(); if (getContentPage() instanceof XmlPage) return ((XmlPage)getContentPage()).asXml(); if (getContentPage() instanceof JavaScriptPage) return ((JavaScriptPage)getContentPage()).getContent(); throw new IllegalStateException("This page can not be converted to text. Page type is " + getContentPage().getClass().getName()); }
@Test @SpecAssertion(section = PROCESS_INJECTION_TARGET_EE, id = "ee") public void testWrappedInjectionTargetUsedForTagLibraryListener() throws Exception { TextPage page = invokeContextPath("test?type=taglibrary", TextPage.class); assertTrue(page.getContent().contains("true")); }
public void testArbitraryWebMethodName() throws Exception { WebClient wc = new WebClient(); TextPage p = wc.getPage(new URL(url, "arbitraryWebMethodName")); assertEquals("I'm index", p.getContent()); p = wc.getPage(new URL(url, "arbitraryWebMethodName/theNeedful")); assertEquals("DTN", p.getContent()); }
@Override public boolean isSatisfied() { TextPage info = null; try { info = webClient.getPage(contextPath + "info"); } catch (IOException e) { e.printStackTrace(); return false; } Matcher matcher = Pattern.compile("(Foo destroyed:)(\\w+)").matcher(info.getContent()); if (matcher.find()) { String value = matcher.group(2); return Integer.valueOf(value) == 2 ? true : false; } return false; } }).start();
@Override public String getPageText() { Page page = win.getEnclosedPage(); if (page instanceof HtmlPage) { return ((HtmlPage) page).getBody().asText(); } if (page instanceof TextPage) { return ((TextPage) page).getContent(); } if (page instanceof JavaScriptPage) { return ((JavaScriptPage) page).getContent(); } if (page instanceof XmlPage) { return ((XmlPage) page).getContent(); } if (page instanceof UnexpectedPage) { return ((UnexpectedPage) page).getWebResponse() .getContentAsString(); } throw new RuntimeException( "Unexpected error in getPageText(). This method need to be updated."); }
@Test(groups = INTEGRATION) @SpecAssertion(section = APPLICATION_CONTEXT_EE, id = "e") public void testApplicationContextSharedBetweenServletRequests() throws Exception { WebClient webClient = new WebClient(); webClient.setThrowExceptionOnFailingStatusCode(true); TextPage firstRequestResult = webClient.getPage(contextPath + "IntrospectApplication"); assertNotNull(firstRequestResult.getContent()); assertTrue(Double.parseDouble(firstRequestResult.getContent()) != 0); // Make a second request and make sure the same context is used TextPage secondRequestResult = webClient.getPage(contextPath + "IntrospectApplication"); assertNotNull(secondRequestResult.getContent()); // should be same random number assertEquals(Double.parseDouble(secondRequestResult.getContent()), Double.parseDouble(firstRequestResult.getContent())); }
@Test @SpecAssertion(section = PROCESS_INJECTION_TARGET_EE, id = "ef") public void testWrappedInjectionTargetUsedForEjbInterceptor() throws Exception { TextPage page = invokeContextPath("test?type=interceptor", TextPage.class); assertTrue(page.getContent().contains("true")); }
public void testOverloads() throws Exception { TextPage p = new WebClient().getPage(new URL(url, "overloaded/x")); assertEquals("doX(StaplerRequest)", p.getContent()); } public final Object overloaded = new Overloaded();