Search in sources :

Example 26 with GlassFish

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

the class ExtSharedServiceEnableDisableTest 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.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/ext-shared-service-enable-disable-test.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    // Obtaining the IP address of the DAS
    String ip_address = "127.0.0.1";
    try {
        Enumeration netint_enum = NetworkInterface.getNetworkInterfaces();
        for (Iterator it = Collections.list(netint_enum).iterator(); it.hasNext(); ) {
            NetworkInterface netint = (NetworkInterface) it.next();
            if (netint.getName().equals("virbr0")) {
                Enumeration inetAddresses = netint.getInetAddresses();
                if (inetAddresses.hasMoreElements()) {
                    InetAddress inetAddress = (InetAddress) inetAddresses.nextElement();
                    ip_address = inetAddress.toString();
                    ip_address = ip_address.substring(1, ip_address.length());
                    break;
                }
            }
        }
    } catch (SocketException socketException) {
        socketException.printStackTrace();
    }
    Deployer deployer = null;
    String appName = null;
    try {
        {
            // start-database
            ServiceLocator habitat = Globals.getDefaultHabitat();
            ServerContext serverContext = habitat.getService(ServerContext.class);
            String[] startdbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "start-database", "--dbhome", serverContext.getInstallRoot().getAbsolutePath() + File.separator + "databases", "--dbhost", ip_address };
            ProcessExecutor startDatabase = new ProcessExecutor(startdbArgs);
            try {
                startDatabase.execute();
            } catch (ExecException e) {
                e.printStackTrace();
            }
        }
        // Create the shared & external services first, as these services will be referenced by the application
        createSharedAndExternalServices(ip_address);
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandRunner commandRunner = glassfish.getCommandRunner();
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure PaaS-ext-shared-service-enable-disable-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 + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
        testSharedAndExternalService();
        // 4. Access the app to make sure PaaS-ext-shared-service-enable-disable-test app is correctly
        // provisioned after running Shared-Services test
        get("http://" + instanceIP + ":" + HTTP_PORT + "/ext-shared-service-enable-disable-test/list", "Here is a list of animals in the zoo.");
    // 5. Undeploy the Zoo catalogue application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            deleteSharedAndExternalService();
            {
                // stop-database
                ServiceLocator habitat = Globals.getDefaultHabitat();
                ServerContext serverContext = habitat.getService(ServerContext.class);
                String[] stopDbArgs = { serverContext.getInstallRoot().getAbsolutePath() + File.separator + "bin" + File.separator + "asadmin" + (OS.isWindows() ? ".bat" : ""), "stop-database", "--dbhost", ip_address };
                ProcessExecutor stopDatabase = new ProcessExecutor(stopDbArgs);
                try {
                    stopDatabase.execute();
                } catch (ExecException e) {
                    e.printStackTrace();
                }
            }
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                System.out.println(commandResult.getOutput().toString());
                if (commandResult.getOutput().contains("Nothing to list")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) ExecException(com.sun.enterprise.util.ExecException) ProcessExecutor(com.sun.enterprise.util.ProcessExecutor) ExecException(com.sun.enterprise.util.ExecException) CommandResult(org.glassfish.embeddable.CommandResult) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServerContext(org.glassfish.internal.api.ServerContext) GlassFish(org.glassfish.embeddable.GlassFish) File(java.io.File) CommandRunner(org.glassfish.embeddable.CommandRunner) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 27 with GlassFish

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

the class BookStoreTest 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.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/bookstore2.war");
    // archive location.
    Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    CommandRunner commandRunner = glassfish.getCommandRunner();
    try {
        // Create Java EE shared service.
        CommandResult createSharedServiceResult = commandRunner.run("create-shared-service", "--characteristics", "service-type=JavaEE", "--configuration", "min.clustersize=2:max.clustersize=4", "--servicetype", "JavaEE", "JavaEE_Shared_Service");
        System.out.println("\ncreate-shared-service command output [ " + createSharedServiceResult.getOutput() + "]");
        // List services to check for the shared service
        CommandResult listSharedServicesResult = commandRunner.run("list-services", "--scope", "shared", "--output", "service-name, state");
        System.out.println("\nlist-services command output [ " + listSharedServicesResult.getOutput() + "]");
        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-bookstore 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 + "/bookstore2/BookStoreServlet", "Please wait while accessing the bookstore database.....");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore2/BookStoreServlet?title=Advanced+guide+for+developing+PaaS+components&authors=Shalini+M&price=100%24", "Here are the list of books available in our store:");
        get("http://" + instanceIP + ":" + HTTP_PORT + "/bookstore2/BookStoreServlet", "Advanced guide for developing PaaS components");
    // 4. Undeploy the Bookstore application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            CommandResult deleteResult = commandRunner.run("delete-shared-service", "JavaEE_Shared_Service");
            System.out.println("\ndelete-shared-service command output [" + deleteResult.getOutput() + "]");
            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");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) 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 28 with GlassFish

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

the class MQSharedServiceTest 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.
    // TODO :: use mvn apis to get the
    File archive = new File("/tmp/ejb30-hello-mdb-ear.ear");
    // archive location.
    org.junit.Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        // Create the shared services first, as these services will be referenced by the application
        createSharedServices();
        deployer = glassfish.getDeployer();
        System.out.println("Deployer: " + deployer);
        System.out.println("archive: " + archive);
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandRunner commandRunner = glassfish.getCommandRunner();
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. Access the app to make sure mq-shared-service-test app is correctly
        // provisioned.
        String HTTP_PORT = (System.getProperty("http.port") != null) ? System.getProperty("http.port") : "28080";
        String instanceIP = getLBIPAddress(glassfish);
        System.out.println("HTTP_PORT : " + HTTP_PORT);
        get("http://" + instanceIP + ":" + HTTP_PORT + "/web/mdbtest", "filterMessage=nulltestattribute=null, initParams:");
    // 4. Undeploy the MQ application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            deleteSharedService();
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                System.out.println(commandResult.getOutput().toString());
                if (commandResult.getOutput().contains("Nothing to list")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) 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 29 with GlassFish

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

the class BasicSharedServiceTest 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.
    File archive = new File(System.getProperty("basedir") + // TODO :: use mvn apis to get the
    "/target/basic-shared-service-test.war");
    // archive location.
    org.junit.Assert.assertTrue(archive.exists());
    Deployer deployer = null;
    String appName = null;
    try {
        // Create the shared services first, as these services will be referenced by the application
        createSharedServices();
        deployer = glassfish.getDeployer();
        appName = deployer.deploy(archive);
        System.err.println("Deployed [" + appName + "]");
        Assert.assertNotNull(appName);
        CommandRunner commandRunner = glassfish.getCommandRunner();
        CommandResult result = commandRunner.run("list-services");
        System.out.println("\nlist-services command output [ " + result.getOutput() + "]");
        // 3. 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-shared-service-test/list", "Here is a list of animals in the zoo.");
        testSharedService();
        // 4. Access the app to make sure PaaS-basic-shared-service-test app is correctly
        // provisioned after running Shared-Services test
        get("http://" + instanceIP + ":" + HTTP_PORT + "/basic-shared-service-test/list", "Here is a list of animals in the zoo.");
    // 5. Undeploy the Zoo catalogue application .
    } finally {
        if (appName != null) {
            deployer.undeploy(appName);
            System.err.println("Undeployed [" + appName + "]");
            deleteSharedService();
            try {
                boolean undeployClean = false;
                CommandResult commandResult = glassfish.getCommandRunner().run("list-services");
                System.out.println(commandResult.getOutput().toString());
                if (commandResult.getOutput().contains("Nothing to list")) {
                    undeployClean = true;
                }
                Assert.assertTrue(undeployClean);
            } catch (Exception e) {
                System.err.println("Couldn't varify whether undeploy succeeded");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) GlassFish(org.glassfish.embeddable.GlassFish) 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 30 with GlassFish

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

the class BasicPaaSTest 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)

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