-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
- Loading branch information
Showing
9 changed files
with
446 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...edded/tests/src/main/java/org/glassfish/main/extras/embedded/test/app/ejb/RemoteBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.extras.embedded.test.app.ejb; | ||
|
||
import jakarta.ejb.Stateless; | ||
|
||
@Stateless | ||
public class RemoteBean implements RemoteInterface { | ||
|
||
@Override | ||
public String getMessage() { | ||
// Returns Java version | ||
return Runtime.version().toString(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../tests/src/main/java/org/glassfish/main/extras/embedded/test/app/ejb/RemoteInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.extras.embedded.test.app.ejb; | ||
|
||
import jakarta.ejb.Remote; | ||
|
||
@Remote | ||
public interface RemoteInterface { | ||
|
||
String getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...java/org/glassfish/main/extras/embedded/test/all/deployment/RemoteDeploymentTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.extras.embedded.test.all.deployment; | ||
|
||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
|
||
import org.glassfish.embeddable.BootstrapProperties; | ||
import org.glassfish.embeddable.GlassFish; | ||
import org.glassfish.embeddable.GlassFishException; | ||
import org.glassfish.embeddable.GlassFishProperties; | ||
import org.glassfish.embeddable.GlassFishRuntime; | ||
import org.glassfish.main.extras.embedded.test.app.ejb.RemoteInterface; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
import static java.lang.String.format; | ||
import static org.glassfish.tests.utils.ServerUtils.getFreePort; | ||
import static org.glassfish.tests.utils.ServerUtils.runCommand; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class RemoteDeploymentTestBase { | ||
|
||
private static final String LOOKUP_STRING = | ||
"java:global/%s/RemoteBean!org.glassfish.main.extras.embedded.test.app.ejb.RemoteInterface"; | ||
|
||
protected GlassFish glassfish; | ||
|
||
@BeforeEach | ||
public void startup() throws GlassFishException { | ||
GlassFishRuntime glassfishRuntime = GlassFishRuntime.bootstrap(new BootstrapProperties()); | ||
glassfish = glassfishRuntime.newGlassFish(new GlassFishProperties()); | ||
assertThat(glassfish.getStatus(), equalTo(GlassFish.Status.INIT)); | ||
|
||
glassfish.start(); | ||
while (glassfish.getStatus() == GlassFish.Status.STARTING) { | ||
Thread.yield(); | ||
} | ||
assertThat(glassfish.getStatus(), equalTo(GlassFish.Status.STARTED)); | ||
|
||
runCommand( | ||
glassfish, | ||
"set", | ||
"configs.config.server-config.iiop-service.iiop-listener.orb-listener-1.port=" + getFreePort()); | ||
runCommand( | ||
glassfish, | ||
"set", | ||
"configs.config.server-config.iiop-service.iiop-listener.SSL.port=" + getFreePort()); | ||
runCommand( | ||
glassfish, | ||
"set", | ||
"configs.config.server-config.iiop-service.iiop-listener.SSL_MUTUALAUTH.port=" + getFreePort()); | ||
} | ||
|
||
@AfterEach | ||
public void shutdown() throws GlassFishException { | ||
glassfish.stop(); | ||
while (glassfish.getStatus() == GlassFish.Status.STOPPING) { | ||
Thread.yield(); | ||
} | ||
assertThat(glassfish.getStatus(), equalTo(GlassFish.Status.STOPPED)); | ||
|
||
glassfish.dispose(); | ||
assertThat(glassfish.getStatus(), equalTo(GlassFish.Status.DISPOSED)); | ||
} | ||
|
||
protected File createFileFor(Archive<?> archive, String appName) throws IOException { | ||
File tempDir = Files.createTempDirectory(appName).toFile(); | ||
File appFile = new File(tempDir, appName + extensionFor(archive)); | ||
archive.as(ZipExporter.class).exportTo(appFile, true); | ||
tempDir.deleteOnExit(); | ||
return appFile; | ||
} | ||
|
||
private String extensionFor(Archive<?> archive) { | ||
String extension = ".jar"; | ||
if (archive instanceof WebArchive) { | ||
extension = ".war"; | ||
} else if (archive instanceof EnterpriseArchive) { | ||
extension = ".ear"; | ||
} | ||
return extension; | ||
} | ||
|
||
protected String getResult(final String appName) throws NamingException { | ||
InitialContext initialContext = new InitialContext(); | ||
RemoteInterface remoteBean = (RemoteInterface) initialContext.lookup(getLookupString(appName)); | ||
return remoteBean.getMessage(); | ||
} | ||
|
||
protected String getResult(final String appName, final String moduleName) throws NamingException { | ||
InitialContext initialContext = new InitialContext(); | ||
RemoteInterface remoteBean = (RemoteInterface) initialContext.lookup(getLookupString(appName, moduleName)); | ||
return remoteBean.getMessage(); | ||
} | ||
|
||
private String getLookupString(final String appName) { | ||
return format(LOOKUP_STRING, appName); | ||
} | ||
|
||
private String getLookupString(final String appName, final String moduleName) { | ||
return format(LOOKUP_STRING, appName + "/" + moduleName); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...a/org/glassfish/main/extras/embedded/test/all/deployment/ear/RemoteEarDeploymentTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2023 Contributors to the Eclipse Foundation. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.extras.embedded.test.all.deployment.ear; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
import javax.naming.NamingException; | ||
|
||
import org.glassfish.embeddable.Deployer; | ||
import org.glassfish.embeddable.GlassFishException; | ||
import org.glassfish.main.extras.embedded.test.all.deployment.RemoteDeploymentTestBase; | ||
import org.glassfish.main.extras.embedded.test.app.ejb.RemoteBean; | ||
import org.glassfish.main.extras.embedded.test.app.ejb.RemoteInterface; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static java.lang.System.Logger.Level.INFO; | ||
import static java.lang.System.Logger.Level.WARNING; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class RemoteEarDeploymentTest extends RemoteDeploymentTestBase { | ||
|
||
private static final System.Logger LOG = System.getLogger(RemoteEarDeploymentTest.class.getName()); | ||
|
||
private static final String APP_NAME = "RemoteEar"; | ||
|
||
private static final String WAR_MODULE_NAME = "RemoteWar"; | ||
|
||
private static final String WAR_FILE_NAME = WAR_MODULE_NAME + ".war"; | ||
|
||
private static final String LIB_FILE_NAME = "RemoteLib.jar"; | ||
|
||
@Test | ||
public void testDeployAndUndeployApplication() throws GlassFishException, IOException, NamingException { | ||
Deployer deployer = glassfish.getDeployer(); | ||
File ejbFile = createDeployment(); | ||
try { | ||
assertThat(deployer.deploy(ejbFile), equalTo(APP_NAME)); | ||
assertThat(getResult(APP_NAME, WAR_MODULE_NAME), equalTo(Runtime.version().toString())); | ||
} finally { | ||
try { | ||
Files.deleteIfExists(ejbFile.toPath()); | ||
} catch (IOException e) { | ||
LOG.log(WARNING, "An error occurred while remove temp file " + ejbFile.getAbsolutePath(), e); | ||
} | ||
deployer.undeploy(APP_NAME); | ||
} | ||
} | ||
|
||
private File createDeployment() throws IOException { | ||
JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, LIB_FILE_NAME) | ||
.addClass(RemoteInterface.class); | ||
|
||
WebArchive webArchive = ShrinkWrap.create(WebArchive.class, WAR_FILE_NAME) | ||
.addClass(RemoteBean.class) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
|
||
EnterpriseArchive enterpriseArchive = ShrinkWrap.create(EnterpriseArchive.class) | ||
.addAsLibrary(javaArchive) | ||
.addAsModule(webArchive); | ||
|
||
LOG.log(INFO, enterpriseArchive.toString(true)); | ||
|
||
return createFileFor(enterpriseArchive, APP_NAME); | ||
} | ||
} |
Oops, something went wrong.