Search in sources :

Example 31 with GlassFish

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

the class BasicPaaSTest 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 32 with GlassFish

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

the class LifeCycleTest method test.

@Test
public void test() throws GlassFishException {
    runtime = GlassFishRuntime.bootstrap();
    GlassFish instance1 = runtime.newGlassFish();
    logger.info("Instance1 created" + instance1);
    instance1.start();
    logger.info("Instance1 started #1");
    sleep();
    instance1.stop();
    logger.info("Instance1 stopped #1");
    instance1.start();
    logger.info("Instance1 started #2");
    sleep();
    instance1.stop();
    logger.info("Instance1 stopped #2");
    instance1.dispose();
    logger.info("Instance1 disposed");
    checkDisposed();
    GlassFishProperties props = new GlassFishProperties();
    props.setProperty("glassfish.embedded.tmpdir", System.getProperty("user.dir"));
    GlassFish instance2 = runtime.newGlassFish(props);
    logger.info("instance2 created" + instance2);
    instance2.start();
    logger.info("Instance2 started #1");
    sleep();
    instance2.stop();
    logger.info("Instance2 stopped #1");
    instance2.start();
    logger.info("Instance2 started #2");
    sleep();
    instance2.stop();
    logger.info("Instance2 stopped #2");
    instance2.dispose();
    logger.info("Instance2 disposed");
    checkDisposed();
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) Test(org.junit.Test)

Example 33 with GlassFish

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

Example 34 with GlassFish

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

the class RunAdminCommandsTest method test.

@Test
public void test() throws Exception {
    GlassFishProperties props = new GlassFishProperties();
    props.setPort("http-listener", 9090);
    GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(props);
    glassfish.start();
    // Bind the command runner in JNDI tree with your own mapped-name.
    CommandRunner cr = glassfish.getCommandRunner();
    new InitialContext().bind("org.glassfish.embeddable.CommandRunner", cr);
    // Deploy archive
    Deployer deployer = glassfish.getDeployer();
    String appname = deployer.deploy(new File("target/servlet_runs_admin_cmds.war"));
    System.out.println("Deployed [" + appname + "]");
    Assert.assertEquals(appname, "servlet_runs_admin_cmds");
    get("http://localhost:9090/servlet_runs_admin_cmds", "JDBC connection pool sample_derby_pool created successfully");
    deployer.undeploy(appname);
    glassfish.dispose();
}
Also used : GlassFish(org.glassfish.embeddable.GlassFish) CommandRunner(org.glassfish.embeddable.CommandRunner) File(java.io.File) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) InitialContext(javax.naming.InitialContext) Deployer(org.glassfish.embeddable.Deployer) Test(org.junit.Test)

Example 35 with GlassFish

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

the class VerifierMain method main.

public static void main(String[] args) throws GlassFishException, IOException {
    VerifierFrameworkContext verifierFrameworkContext = new Initializer(args).getVerificationContext();
    // Since in gui mode, we don't get a chance to clean up, we need to install a shutdown hook
    addShutdownHook();
    gfr = GlassFishRuntime.bootstrap();
    GlassFishProperties gfp = new GlassFishProperties();
    gfp.setProperty(StartupContext.TIME_ZERO_NAME, (new Long(System.currentTimeMillis())).toString());
    final String VERIFIER_MODULE = "org.glassfish.verifier";
    gfp.setProperty(StartupContext.STARTUP_MODULE_NAME, VERIFIER_MODULE);
    // gfp.setConfigFileURI("file:/tmp/domain.xml");
    GlassFish gf = gfr.newGlassFish(gfp);
    gf.start();
    int failedCount = -1;
    Verifier verifier = gf.getService(Verifier.class);
    if (verifierFrameworkContext.isUsingGui()) {
        MainFrame mf = new MainFrame(verifierFrameworkContext.getJarFileName(), true, verifier);
        mf.setSize(800, 600);
        mf.setVisible(true);
    } else {
        LocalStringManagerImpl smh = StringManagerHelper.getLocalStringsManager();
        try {
            verifier.init(verifierFrameworkContext);
            verifier.verify();
        } catch (Exception e) {
            LogRecord logRecord = new LogRecord(Level.SEVERE, smh.getLocalString(verifier.getClass().getName() + // NOI18N
            ".verifyFailed", // NOI18N
            "Could not verify successfully."));
            logRecord.setThrown(e);
            verifierFrameworkContext.getResultManager().log(logRecord);
        }
        verifier.generateReports();
        failedCount = verifierFrameworkContext.getResultManager().getFailedCount() + verifierFrameworkContext.getResultManager().getErrorCount();
        System.exit(failedCount);
    }
}
Also used : LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) LogRecord(java.util.logging.LogRecord) GlassFish(org.glassfish.embeddable.GlassFish) GlassFishProperties(org.glassfish.embeddable.GlassFishProperties) MainFrame(com.sun.enterprise.tools.verifier.gui.MainFrame) GlassFishException(org.glassfish.embeddable.GlassFishException) IOException(java.io.IOException)

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