use of org.ops4j.pax.web.itest.base.WaitCondition2 in project org.ops4j.pax.web by ops4j.
the class AbstractWhiteboardDSRestartIntegrationTest method testWhiteBoardRootRestart.
@Test
public void testWhiteBoardRootRestart() throws Exception {
// find Whiteboard-bundle
final Bundle whiteBoardBundle = Arrays.stream(ctx.getBundles()).filter(bundle -> "org.ops4j.pax.web.pax-web-extender-whiteboard".equalsIgnoreCase(bundle.getSymbolicName())).findFirst().orElseThrow(() -> new AssertionError("no Whiteboard bundle found"));
// stop Whiteboard bundle
whiteBoardBundle.stop();
new WaitCondition2("Check if Whiteboard bundle gets stopped", () -> whiteBoardBundle.getState() == Bundle.RESOLVED).waitForCondition(10000, 500, () -> fail("Whiteboard bundle did not stop in time"));
// start Whiteboard bundle again
initServletListener();
whiteBoardBundle.start();
new WaitCondition2("Check if Whiteboard bundle gets activated", () -> whiteBoardBundle.getState() == Bundle.ACTIVE).waitForCondition(10000, 500, () -> fail("Whiteboard bundle did not start in time"));
// also wait till the servlet is registered
waitForServletListener();
Thread.sleep(1500);
// Test
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Response must contain 'Hello from SimpleServlet'", resp -> resp.contains("Hello from SimpleServlet")).doGETandExecuteTest("http://127.0.0.1:8181/simple-servlet");
// Test
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Response must contain 'Hello from ServletWithContext'", resp -> resp.contains("Hello from ServletWithContext")).doGETandExecuteTest("http://127.0.0.1:8181/context/servlet");
}
use of org.ops4j.pax.web.itest.base.WaitCondition2 in project org.ops4j.pax.web by ops4j.
the class AbstractWhiteboardRestartIntegrationTest method testWhiteBoardRootRestart.
@Test
public void testWhiteBoardRootRestart() throws Exception {
// find Whiteboard-bundle
final Bundle whiteBoardBundle = Arrays.stream(ctx.getBundles()).filter(bundle -> "org.ops4j.pax.web.pax-web-extender-whiteboard".equalsIgnoreCase(bundle.getSymbolicName())).findFirst().orElseThrow(() -> new AssertionError("no Whiteboard bundle found"));
// stop Whiteboard bundle
whiteBoardBundle.stop();
new WaitCondition2("Check if Whiteboard bundle gets stopped", () -> whiteBoardBundle.getState() == Bundle.RESOLVED).waitForCondition(10000, 500, () -> fail("Whiteboard bundle did not stop in time"));
// start Whiteboard bundle again
whiteBoardBundle.start();
new WaitCondition2("Check if Whiteboard bundle gets activated", () -> whiteBoardBundle.getState() == Bundle.ACTIVE).waitForCondition(10000, 500, () -> fail("Whiteboard bundle did not start in time"));
// Test
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Response must contain 'Hello Whiteboard Extender'", resp -> resp.contains("Hello Whiteboard Extender")).doGETandExecuteTest("http://127.0.0.1:8181/root");
}
use of org.ops4j.pax.web.itest.base.WaitCondition2 in project org.ops4j.pax.web by ops4j.
the class AbstractWarJsfResourcehandlerIntegrationTest method testJsfResourceHandler.
/**
* Does multiple assertions in one test since container-startup is slow
* <p/>
* <ul>
* <li>Check if pax-web-resources-jsf is started</li>
* <li>Check if application under test (jsf-application-myfaces) is started
* <li>Test actual resource-handler
* <ul>
* <li>Test for occurence of 'Hello JSF' (jsf-application-myfaces)</li>
* <li>Test for occurence of 'Standard Header' (jsf-resourcebundle)</li>
* <li>Test for occurence of 'iceland.jpg' from library 'default' in version '2_0' (jsf-resourcebundle)</li>
* <li>Test for occurence of 'Customized Footer' (jsf-resourcebundle)</li>
* <li>Access a resource (image) via HTTP which gets loaded from a other bundle (jsf-resourcebundle)</li>
* </ul>
* </li>
* <li>Test localized resource
* <ul>
* <li>Test for occurence of 'flag.png' from library 'layout' with default locale 'en' which resolves to 'iceland' (default in faces-config)</li>
* <li>Test for occurence of 'flag.png' from library 'layout' with default locale 'de' which resolves to 'germany'</li>
* </ul>
* </li>
* <li>Test resource-overide
* <ul>
* <li>Install another bundle (jsf-resourcebundle-override) which also serves template/footer.xhtml</li>
* <li>Test for occurence of 'Overriden Footer' (jsf-resourcebundle-override)</li>
* <li>Test for occurence of 'iceland.jpg' from library 'default' in version '3_0' (jsf-resourcebundle-override)</li>
* <li>Uninstall the previously installed bundle</li>
* <li>Test again, this time for occurence of 'Customized Footer' (jsf-resourcebundle)</li>
* </ul>
* </li>
* <li>
* Test {@link OsgiResource#userAgentNeedsUpdate(FacesContext)}
* with an If-Modified-Since header
* </li>
* <li>Test servletmapping with prefix (faces/*) rather than extension for both, page and image serving</li>
* </ul>
*/
@Test
public void testJsfResourceHandler() throws Exception {
final String pageUrl = "http://127.0.0.1:8181/osgi-resourcehandler-myfaces/index.xhtml";
final String imageUrl = "http://127.0.0.1:8181/osgi-resourcehandler-myfaces/javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0";
// prepare Bundle
initWebListener();
installAndStartBundle(mavenBundle().groupId("org.ops4j.pax.web.samples").artifactId("jsf-resourcehandler-myfaces").versionAsInProject().getURL());
waitForWebListener();
new WaitCondition2("pax-web-resources-extender done scanning for webresources-bundles", () -> {
try {
HttpTestClientFactory.createDefaultTestClient().doGETandExecuteTest(imageUrl);
return true;
} catch (AssertionError | Exception e) {
return false;
}
}).waitForCondition(20000, 1000, () -> fail("Image not served in time. pax-web-resources-extender not finished"));
// start testing
BundleMatchers.isBundleActive("org.ops4j.pax.web.pax-web-resources-extender", bundleContext);
BundleMatchers.isBundleActive("org.ops4j.pax.web.pax-web-resources-jsf", bundleContext);
BundleMatchers.isBundleActive("jsf-resourcehandler-resourcebundle", bundleContext);
BundleMatchers.isBundleActive("jsf-resourcehandler-myfaces", bundleContext);
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Some Content shall be included from the jsf-application-bundle to test internal view-resources", resp -> StringUtils.contains(resp, "Hello Included Content")).withResponseAssertion("Standard header shall be loaded from resourcebundle to test external view-resources", resp -> StringUtils.contains(resp, "Standard Header")).withResponseAssertion("Images shall be loaded from resourcebundle to test external resources", resp -> StringUtils.contains(resp, "iceland.jpg")).withResponseAssertion("Customized footer shall be loaded from resourcebundle to test external view-resources", resp -> StringUtils.contains(resp, "Customized Footer")).withResponseAssertion("Image-URL must be created from OsgiResource", resp -> StringUtils.contains(resp, "/osgi-resourcehandler-myfaces/javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0")).withResponseAssertion("Flag-URL must be served from iceland-folder", resp -> StringUtils.contains(resp, "/osgi-resourcehandler-myfaces/javax.faces.resource/flag.png.xhtml?type=osgi&loc=iceland&ln=layout")).doGETandExecuteTest(pageUrl);
// Test German image
HttpTestClientFactory.createDefaultTestClient().addRequestHeader("Accept-Language", "de").withReturnCode(200).withResponseAssertion("Flag-URL must be served from germany-folder", resp -> StringUtils.contains(resp, "/osgi-resourcehandler-myfaces/javax.faces.resource/flag.png.xhtml?type=osgi&loc=germany&ln=layout")).doGETandExecuteTest(pageUrl);
// test resource serving for image
HttpTestClientFactory.createDefaultTestClient().doGETandExecuteTest(imageUrl);
// Install override bundle
String bundlePath = mavenBundle().groupId("org.ops4j.pax.web.samples").artifactId("jsf-resourcehandler-resourcebundle-override").versionAsInProject().getURL();
Bundle installedResourceBundle = installAndStartBundle(bundlePath);
BundleMatchers.isBundleActive(installedResourceBundle.getSymbolicName(), bundleContext);
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Overriden footer shall be loaded from resourcebundle-override to test external view-resources which are overriden", resp -> StringUtils.contains(resp, "Overriden Footer")).withResponseAssertion("Iceland-Picture shall be found in version 3.0 from resourcebunde-override", resp -> StringUtils.contains(resp, "javax.faces.resource/images/iceland.jpg.xhtml?type=osgi&ln=default&lv=2_0&rv=3_0.jpg")).doGETandExecuteTest(pageUrl);
// uninstall overriding bundle
installedResourceBundle.stop();
new WaitCondition2("Customized footer shall be loaded from resourcebundle", () -> {
try {
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Customized footer shall be loaded from resourcebundle", resp -> StringUtils.contains(resp, "Customized Footer")).doGETandExecuteTest(pageUrl);
return true;
} catch (AssertionError | Exception e) {
return false;
}
}).waitForCondition(5000, 1000, () -> fail("After uninstalling 'jsf-resourcehandler-resourcebundle-override' " + "the customized foot must be loaded again."));
// Test If-Modified-Since
ZonedDateTime now = ZonedDateTime.of(LocalDateTime.now(), ZoneId.of(ZoneId.SHORT_IDS.get("ECT")));
// "Modified-Since should mark response with 304"
HttpTestClientFactory.createDefaultTestClient().withReturnCode(304).addRequestHeader("If-Modified-Since", now.format(DateTimeFormatter.RFC_1123_DATE_TIME)).doGETandExecuteTest(imageUrl);
// Test second faces-mapping which uses a prefix (faces/*)
final String pageUrlWithPrefixMapping = "http://127.0.0.1:8181/osgi-resourcehandler-myfaces/faces/index.xhtml";
final String imageUrlWithPrefixMapping = "http://127.0.0.1:8181/osgi-resourcehandler-myfaces/faces/javax.faces.resource/images/iceland.jpg?type=osgi&ln=default&lv=2_0";
HttpTestClientFactory.createDefaultTestClient().doGETandExecuteTest(imageUrlWithPrefixMapping);
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Image-URL must be created from OsgiResource. This time the second servlet-mapping (faces/*) must be used.", resp -> StringUtils.contains(resp, "/osgi-resourcehandler-myfaces/faces/javax.faces.resource/images/iceland.jpg?type=osgi&ln=default&lv=2_0")).doGETandExecuteTest(pageUrlWithPrefixMapping);
}
use of org.ops4j.pax.web.itest.base.WaitCondition2 in project org.ops4j.pax.web by ops4j.
the class AbstractWhiteboardDSRestartIntegrationTest method testWhiteBoardSampleBundleRestart.
@Test
public void testWhiteBoardSampleBundleRestart() throws Exception {
// Test
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Response must contain 'Hello from ServletWithContext'", resp -> resp.contains("Hello from ServletWithContext")).doGETandExecuteTest("http://127.0.0.1:8181/context/servlet");
// find Whiteboard-bundle
final Bundle whiteBoardSampleBundle = Arrays.stream(ctx.getBundles()).filter(bundle -> "org.ops4j.pax.web.samples.whiteboard-ds".equalsIgnoreCase(bundle.getSymbolicName())).findFirst().orElseThrow(() -> new AssertionError("no Whiteboard Sample bundle found"));
// stop Whiteboard bundle
whiteBoardSampleBundle.stop();
new WaitCondition2("Check if Whiteboard Sample bundle gets stopped", () -> whiteBoardSampleBundle.getState() == Bundle.RESOLVED).waitForCondition(10000, 500, () -> fail("Whiteboard Sample bundle did not stop in time"));
// start Whiteboard bundle again
whiteBoardSampleBundle.start();
new WaitCondition2("Check if Whiteboard Sample bundle gets activated", () -> whiteBoardSampleBundle.getState() == Bundle.ACTIVE).waitForCondition(10000, 500, () -> fail("Whiteboard Sample bundle did not start in time"));
// Test
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Response must contain 'Hello from SimpleServlet'", resp -> resp.contains("Hello from SimpleServlet")).doGETandExecuteTest("http://127.0.0.1:8181/simple-servlet");
// Test
HttpTestClientFactory.createDefaultTestClient().withResponseAssertion("Response must contain 'Hello from ServletWithContext'", resp -> resp.contains("Hello from ServletWithContext")).doGETandExecuteTest("http://127.0.0.1:8181/context/servlet");
}
Aggregations