Search in sources :

Example 36 with GlassFish

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

the class MultipleSPETest 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-bookstore application. Deployment should fail
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/basic-spe-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNull(appName);
    } catch (Exception e) {
        System.out.println("$$$$$$$$$$$$$$$$Exception$$$$$$");
    } finally {
        // 3. Register one of the plugins as the default S.P.E
        ServiceLocator habitat = Globals.getDefaultHabitat();
        org.glassfish.api.admin.CommandRunner commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        ActionReport report = habitat.getService(ActionReport.class);
        org.glassfish.api.admin.CommandRunner.CommandInvocation invocation = commandRunner.getCommandInvocation("register-service-provisioning-engine", report);
        ParameterMap parameterMap = new ParameterMap();
        parameterMap.add("type", "Database");
        parameterMap.add("defaultservice", "true");
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Registered a default SPE :" + !report.hasFailures());
        // 4. Deploy the application. Deployment should succeed.
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        // 5. Access the app to make sure PaaS-basic-shared-service-test 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 + "/basic-spe-test/list", "Here is a list of animals in the zoo.");
        // Retrieve the  port number used by the connection pool
        invocation = commandRunner.getCommandInvocation("get", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "server.resources.jdbc-connection-pool.jdbc/__multiple_spe_paas_sample.property.PortNumber");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                if (commandResult.getOutput().contains("Nothing to list.")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
        commandRunner = habitat.getService(org.glassfish.api.admin.CommandRunner.class);
        invocation = commandRunner.getCommandInvocation("unregister-service-provisioning-engine", report);
        parameterMap = new ParameterMap();
        parameterMap.add("DEFAULT", "org.glassfish.paas.mydbplugin.MyDBPlugin");
        invocation.parameters(parameterMap).execute();
        Assert.assertFalse(report.hasFailures());
        System.out.println("Unregistered the default SPE :" + !report.hasFailures());
    }
}
Also used : PrintStream(java.io.PrintStream) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) PaaSDeploymentException(org.glassfish.paas.orchestrator.PaaSDeploymentException) IOException(java.io.IOException) Exception(java.lang.Exception) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) 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) Test(org.junit.Test)

Example 37 with GlassFish

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

the class BasicPaaSServiceMetadataTest 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 38 with GlassFish

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

the class BasicPaaSServiceMetadataTest 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 39 with GlassFish

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

the class Util method runCommand.

public static void runCommand(String commandLine, String serverId) throws Exception {
    GlassFish glassfish = gfMap.get(serverId);
    if (glassfish == null) {
        throw new Exception("Embedded GlassFish [" + serverId + "] not running");
    }
    if (commandLine == null) {
        throw new Exception("Command can not be null");
    }
    String[] split = commandLine.split(" ");
    String command = split[0].trim();
    String[] commandParams = null;
    if (split.length > 1) {
        commandParams = new String[split.length - 1];
        for (int i = 1; i < split.length; i++) {
            commandParams[i - 1] = split[i].trim();
        }
    }
    CommandRunner cr = glassfish.getCommandRunner();
    CommandResult result = commandParams == null ? cr.run(command) : cr.run(command, commandParams);
    System.out.println("Executed command [" + commandLine + "]. Output : \n" + result.getOutput());
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishException(org.glassfish.embeddable.GlassFishException) CommandResult(org.glassfish.embeddable.CommandResult)

Example 40 with GlassFish

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

the class Util method undeploy.

public static void undeploy(String appName, String serverId) throws Exception {
    GlassFish glassfish = gfMap.get(serverId);
    if (glassfish == null) {
        throw new Exception("Embedded GlassFish [" + serverId + "] not running");
    }
    if (appName == null) {
        throw new Exception("Application name can not be null");
    }
    Deployer deployer = glassfish.getDeployer();
    deployer.undeploy(appName);
    System.out.println("Undeployed [" + appName + "]");
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) GlassFishException(org.glassfish.embeddable.GlassFishException) Deployer(org.glassfish.embeddable.Deployer)

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