Search in sources :

Example 6 with GlassFish

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

the class HelloWorldTest method test.

@Test
public void test() throws Exception {
    // Bootstrap GlassFish DAS in embedded mode.
    GlassFish glassfish = bootstrap();
    // Deploy the PaaS app and verify it.
    runTests(glassfish);
    // Re-deploy the PaaS app and verify it.
    String testScenarios = System.getProperty("test.scenarios");
    if (testScenarios == null || "all".contains(testScenarios.toLowerCase())) {
        runTests(glassfish);
    }
    // 5. Stop the GlassFish DAS
    glassfish.dispose();
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) Test(org.junit.Test)

Example 7 with GlassFish

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

the class HelloWorldTest method bootstrap.

private GlassFish bootstrap() throws Exception {
    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);
    return glassfish;
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties)

Example 8 with GlassFish

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

the class CoffeeTest 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/external_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. Generate and run Derby VM
        CommandResult createDerbyVMResult = commandRunner.run("create-derby-vm", "--servicecharacteristics", "service-type=Database");
        System.out.println("\ncreate-derby-vm command output [ " + createDerbyVMResult.getOutput() + "]");
        String derbyIP = (createDerbyVMResult.getOutput().split("\n"))[1];
        System.out.println("Derby IP = " + derbyIP);
        // 2.2. Create the shared DB service
        CommandResult createExternalServiceResult = commandRunner.run("create-external-service", "--configuration", "ip-address=" + derbyIP + ":databasename=foo:connectionAttributes=;'create=true':port=1527:user=APP:password=APP:host=" + derbyIP + ":classname=org.apache.derby.jdbc.ClientXADataSource:resourcetype=javax.sql.XADataSource", "--servicetype", "Database", "coffee-service");
        System.out.println("\ncreate-external-service command output [ " + createExternalServiceResult.getOutput() + "]");
        // 2.3. List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
        // 2.4. 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 + "/external_db_service_test/CoffeeServlet", "Coffee ID");
    // 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 External DB Service.
            CommandResult deleteResult = commandRunner.run("delete-external-service", "coffee-service");
            System.out.println("\ndelete-external-service command output [" + deleteResult.getOutput() + "]");
            // 4.2. Delete generated derby VM
            CommandResult deleteDerbyVMResult = commandRunner.run("delete-derby-vm");
            System.out.println("\ndelete-derby-vm command output [ " + deleteDerbyVMResult.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 9 with GlassFish

use of org.glassfish.embeddable.GlassFish 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 10 with GlassFish

use of org.glassfish.embeddable.GlassFish 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)

Aggregations

GlassFish (org.glassfish.embeddable.GlassFish)44 GlassFishProperties (org.glassfish.embeddable.GlassFishProperties)29 Test (org.junit.Test)27 Deployer (org.glassfish.embeddable.Deployer)24 File (java.io.File)23 PrintStream (java.io.PrintStream)21 CommandRunner (org.glassfish.embeddable.CommandRunner)18 CommandResult (org.glassfish.embeddable.CommandResult)17 JarFile (java.util.jar.JarFile)12 GlassFishException (org.glassfish.embeddable.GlassFishException)6 IOException (java.io.IOException)4 URI (java.net.URI)4 ScatteredArchive (org.glassfish.embeddable.archive.ScatteredArchive)3 HttpListener (org.glassfish.embeddable.web.HttpListener)3 WebContainer (org.glassfish.embeddable.web.WebContainer)3 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ArrayList (java.util.ArrayList)2 InitialContext (javax.naming.InitialContext)2 BootstrapProperties (org.glassfish.embeddable.BootstrapProperties)2 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1