Search in sources :

Example 6 with Deployer

use of org.glassfish.embeddable.Deployer in project Payara by payara.

the class EmployeeTest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + "/target/multiple_app_scoped_service_test.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2. Deploy app
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS app is correctly provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/multiple_app_scoped_service_test/EmployeeServlet", "Employee ID");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/multiple_app_scoped_service_test/EmployeeServlet", "Employee Salary");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult) Test(org.junit.Test)

Example 7 with Deployer

use of org.glassfish.embeddable.Deployer in project Payara by payara.

the class EmployeeTest method test.

@Test
public void test() throws Exception {
    // 1. Bootstrap GlassFish DAS in embedded mode.
    GlassFishProperties glassFishProperties = new GlassFishProperties();
    glassFishProperties.setInstanceRoot(System.getenv("S1AS_HOME") + "/domains/domain1");
    glassFishProperties.setConfigFileReadOnly(false);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassFishProperties);
    PrintStream sysout = System.out;
    glassfish.start();
    System.setOut(sysout);
    // 2. Deploy the PaaS application.
    File archive = new File(System.getProperty("basedir") + "/target/multiple_shared_db_service_test.war");
    // TODO :: use mvn apis to get the archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // 2.1. Create the shared DB services
        CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database", "--configuration", "database.name=hr_database:database.init.sql=/tmp/init.hr-service.sql", "--servicetype", "Database", "hr-service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
        CommandResult createSharedServiceResult1 = commandRunner.run("create-shared-service", "--characteristics", "service-type=Database:product-vendor=MySQL", "--configuration", "database.name=salary_database:database.init.sql=/tmp/init.salary-service.sql", "--servicetype", "Database", "salary-service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult1.getOutput() + "]");
        // 2.2. List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services", "--scope", "shared");
        System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
        // 2.3. Deploy app
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS app is correctly provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/multiple_shared_db_service_test/EmployeeServlet", "Employee ID");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/multiple_shared_db_service_test/EmployeeServlet", "Employee Salary");
    // 4. Undeploy the PaaS application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            System.out.println("Destroying the resources created");
            // 4.1. Delete Shared DB Service.
            CommandResult deletehrResult = commandRunner.run("delete-shared-service", "hr-service");
            System.out.println("\ndelete-shared-service hr-service command output [" + deletehrResult.getOutput() + "]");
            CommandResult deletesalResult = commandRunner.run("delete-shared-service", "salary-service");
            System.out.println("\ndelete-shared-service salary-service command output [" + deletesalResult.getOutput() + "]");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) JarFile(java.util.jar.JarFile) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) CommandResult(org.glassfish.embeddable.CommandResult) Test(org.junit.Test)

Example 8 with Deployer

use of org.glassfish.embeddable.Deployer in project Payara by payara.

the class BasicCDITest 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("cdi_basic", 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, "cdi_basic");
    // 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:8080/cdi_basic/BasicCDITestServlet", "All CDI beans have been injected.");
    deployer.undeploy(appname);
    glassfish.dispose();
}
Also used : ScatteredArchive(org.glassfish.embeddable.archive.ScatteredArchive) WebContainer(org.glassfish.embeddable.web.WebContainer) 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)

Example 9 with Deployer

use of org.glassfish.embeddable.Deployer in project Payara by payara.

the class EmbeddedTest method test.

/*
    public static void main(String[] args) {
        EmbeddedTest test = new EmbeddedTest();
        System.setProperty("basedir", System.getProperty());
        test.test();        
    }
*/
@Test
public void test() throws Exception {
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish();
    glassfish.start();
    Deployer deployer = glassfish.getDeployer();
    URI uri = new File(System.getProperty("user.dir"), "target/classes").toURI();
    System.out.println("Deploying [" + uri + "]");
    deployer.deploy(uri);
    InitialContext ic = new InitialContext();
    System.out.println("Looking up SampleEJB.");
    SampleEjb sampleEjb = (SampleEjb) ic.lookup("java:global/classes/SampleEjb");
    System.out.println("Invoking SampleEjb [" + sampleEjb + "]");
    Assert.assertEquals(sampleEjb.saySomething(), "Hello World");
    System.out.println("SampleEjb tested successfully");
    System.out.println("Looking up TimerEjb.");
    TimerEjb timerEjb = (TimerEjb) ic.lookup("java:global/classes/TimerEjb");
    System.out.println("Invoking TimerEjb [" + timerEjb + "]");
    timerEjb.createTimer();
    System.out.println("Verifying TimerEjb [" + timerEjb + "]");
    Thread.sleep(4000);
    boolean result = timerEjb.verifyTimer();
    Assert.assertTrue(result);
    System.out.println("TimerEJB tested successfully.");
    glassfish.stop();
    glassfish.dispose();
    System.out.println("EmbeddedTest completed.");
}
Also used : SampleEjb(org.glassfish.tests.embedded.ejb.basic.SampleEjb) GlassFish(org.glassfish.embeddable.GlassFish) URI(java.net.URI) File(java.io.File) TimerEjb(org.glassfish.tests.embedded.ejb.basic.TimerEjb) Deployer(org.glassfish.embeddable.Deployer) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 10 with Deployer

use of org.glassfish.embeddable.Deployer in project Payara by payara.

the class EJBTest method test.

@Test
public void test() throws Exception {
    glassfish = GlassFishRuntime.bootstrap().newGlassFish();
    glassfish.start();
    Deployer deployer = glassfish.getDeployer();
    URI uri = new File(System.getProperty("user.dir"), "target/remoteejb.jar").toURI();
    System.out.println("Deploying [" + uri + "]");
    deployer.deploy(uri);
    InitialContext ic = new InitialContext();
    System.out.println("Looking up SampleEJB.");
    SampleEjb sampleEjb = (SampleEjb) ic.lookup("java:global/remoteejb/SampleEjb");
    System.out.println("Invoking SampleEjb [" + sampleEjb + "]");
    Assert.assertEquals(sampleEjb.saySomething(), "Hello World");
    System.out.println("SampleEjb tested successfully");
    System.out.println("Looking up TimerEjb.");
    TimerEjb timerEjb = (TimerEjb) ic.lookup("java:global/remoteejb/TimerEjb");
    System.out.println("Invoking TimerEjb [" + timerEjb + "]");
    timerEjb.createTimer();
    System.out.println("Verifying TimerEjb [" + timerEjb + "]");
    Thread.sleep(4000);
    boolean result = timerEjb.verifyTimer();
    Assert.assertTrue(result);
    System.out.println("TimerEJB tested successfully.");
    // ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
    // try {
    System.out.println("Looking up RemoteEJB.");
    // Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    RemoteEJBInf remoteEjb = (RemoteEJBInf) ic.lookup("java:global/remoteejb/RemoteEJB");
    System.out.println("Invoking RemoteEJB [" + remoteEjb + "]");
    Assert.assertEquals(remoteEjb.sayHi(), "Hi Bhavani");
    System.out.println("RemoteEjb tested successfully");
    // } finally {
    // Thread.currentThread().setContextClassLoader(oldCL);
    // }
    glassfish.stop();
    glassfish.dispose();
    System.out.println("EmbeddedTest completed.");
}
Also used : RemoteEJBInf(org.glassfish.tests.embedded.ejb.remoteejb.RemoteEJBInf) SampleEjb(org.glassfish.tests.embedded.ejb.remoteejb.SampleEjb) URI(java.net.URI) File(java.io.File) TimerEjb(org.glassfish.tests.embedded.ejb.remoteejb.TimerEjb) Deployer(org.glassfish.embeddable.Deployer) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

Deployer (org.glassfish.embeddable.Deployer)33 File (java.io.File)32 GlassFish (org.glassfish.embeddable.GlassFish)24 Test (org.junit.Test)24 CommandRunner (org.glassfish.embeddable.CommandRunner)22 CommandResult (org.glassfish.embeddable.CommandResult)21 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)21 PrintStream (java.io.PrintStream)16 JarFile (java.util.jar.JarFile)13 URI (java.net.URI)6 IOException (java.io.IOException)4 InitialContext (javax.naming.InitialContext)4 GlassFishException (org.glassfish.embeddable.GlassFishException)4 URL (java.net.URL)3 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 NamingException (javax.naming.NamingException)2 SampleEjb (org.glassfish.distributions.test.ejb.SampleEjb)2 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)2