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();
}
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;
}
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() + "]");
}
}
}
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 + "]");
}
}
}
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() + "]");
}
}
}
Aggregations