Search in sources :

Example 1 with ScatteredEnterpriseArchive

use of org.glassfish.embeddable.archive.ScatteredEnterpriseArchive in project Payara by payara.

the class ScatteredArchiveTest method test.

@Test
public void test() throws Exception {
    GlassFishProperties props = new GlassFishProperties();
    props.setPort("http-listener", 8080);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
    glassfish.start();
    // Test Scattered Web Archive
    ScatteredArchive sa = new ScatteredArchive("scatteredarchive", ScatteredArchive.Type.WAR, new File("src/main/webapp"));
    sa.addClassPath(new File("target/classes"));
    sa.addClassPath(new File("src/main/resources"));
    URI warURI = sa.toURI();
    printContents(warURI);
    // Deploy archive
    Deployer deployer = glassfish.getDeployer();
    String appname = deployer.deploy(warURI);
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "scatteredarchive");
    // Now create a http listener and access the app.
    WebContainer webcontainer = glassfish.getService(WebContainer.class);
    HttpListener listener = new HttpListener();
    listener.setId("my-listener");
    listener.setPort(9090);
    webcontainer.addWebListener(listener);
    get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
    get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    deployer.undeploy(appname);
    // Test Scattered RA
    ScatteredArchive rar = new ScatteredArchive("scatteredra", ScatteredArchive.Type.RAR);
    rar.addClassPath(new File("target/classes"));
    rar.addMetadata(new File("src/main/config/ra.xml"));
    URI rarURI = rar.toURI();
    printContents(rarURI);
    appname = deployer.deploy(rarURI);
    System.out.println("Deployed RAR [" + appname + "]");
    Assert.assertEquals(appname, "scatteredra");
    // Test Scattered Enterprise Archive.
    ScatteredEnterpriseArchive ear = new ScatteredEnterpriseArchive("sear");
    ear.addArchive(warURI, "sa.war");
    ear.addArchive(rarURI);
    ear.addMetadata(new File("src/main/config/application.xml"));
    URI earURI = ear.toURI();
    printContents(earURI);
    appname = deployer.deploy(earURI);
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "sear");
    get("http://localhost:9090/satest", "Hi, my name is Bhavani. What's yours?");
    get("http://localhost:9090/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    get("http://localhost:8080/satest/ScatteredArchiveTestServlet", "Hi from ScatteredArchiveTestServlet");
    glassfish.dispose();
}
Also used : ScatteredArchive(org.glassfish.embeddable.archive.ScatteredArchive) WebContainer(org.glassfish.embeddable.web.WebContainer) ScatteredEnterpriseArchive(org.glassfish.embeddable.archive.ScatteredEnterpriseArchive) HttpListener(org.glassfish.embeddable.web.HttpListener) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) URI(java.net.URI) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Aggregations

File (java.io.File)1 URI (java.net.URI)1 JarFile (java.util.jar.JarFile)1 Deployer (org.glassfish.embeddable.Deployer)1 GlassFish (org.glassfish.embeddable.GlassFish)1 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)1 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)1 ScatteredEnterpriseArchive (org.glassfish.embeddable.archive.ScatteredEnterpriseArchive)1 HttpListener (org.glassfish.embeddable.web.HttpListener)1 WebContainer (org.glassfish.embeddable.web.WebContainer)1 Test (org.junit.Test)1