Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for deployment on multiple virtual servers
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
- Loading branch information
Showing
3 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...tests/application/src/main/java/org/glassfish/main/test/app/deploy/SimpleApplication.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,31 @@ | ||
/* | ||
* 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.test.app.deploy; | ||
|
||
import jakarta.ws.rs.ApplicationPath; | ||
import jakarta.ws.rs.core.Application; | ||
|
||
import java.util.Set; | ||
|
||
@ApplicationPath("") | ||
public class SimpleApplication extends Application { | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
return Set.of(SimpleResource.class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...er/tests/application/src/main/java/org/glassfish/main/test/app/deploy/SimpleResource.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,30 @@ | ||
/* | ||
* 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.test.app.deploy; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
@Path("/") | ||
public class SimpleResource { | ||
|
||
@GET | ||
public Response getResponse() { | ||
return Response.ok().build(); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...lication/src/test/java/org/glassfish/main/test/app/deploy/DeployOnVirtualServersTest.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,89 @@ | ||
/* | ||
* 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.test.app.deploy; | ||
|
||
import java.io.File; | ||
|
||
import org.glassfish.main.itest.tools.asadmin.Asadmin; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import static java.lang.System.Logger.Level.INFO; | ||
import static org.glassfish.main.itest.tools.GlassFishTestEnvironment.getAsadmin; | ||
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public class DeployOnVirtualServersTest { | ||
|
||
private static final System.Logger LOG = System.getLogger(DeployOnVirtualServersTest.class.getName()); | ||
|
||
private static final String APP_NAME = DeployOnVirtualServersTest.class.getSimpleName() + "App"; | ||
|
||
private static final Asadmin ASADMIN = getAsadmin(); | ||
|
||
@TempDir | ||
private static File tempDir; | ||
private static File warFile; | ||
|
||
@BeforeAll | ||
public static void prepareDeployment() { | ||
// Create virtual servers | ||
assertThat(ASADMIN.exec("create-virtual-server", "--hosts", "localhost", "vserver1"), asadminOK()); | ||
assertThat(ASADMIN.exec("create-virtual-server", "--hosts", "localhost", "vserver2"), asadminOK()); | ||
|
||
WebArchive webArchive = ShrinkWrap.create(WebArchive.class) | ||
.addClass(SimpleResource.class) | ||
.addClass(SimpleApplication.class) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
|
||
LOG.log(INFO, webArchive.toString(true)); | ||
|
||
warFile = new File(tempDir, APP_NAME + ".war"); | ||
|
||
webArchive.as(ZipExporter.class).exportTo(warFile, true); | ||
} | ||
|
||
@AfterAll | ||
public static void deleteVirtualServers() { | ||
// Delete virtual servers | ||
ASADMIN.exec("delete-virtual-server", "vserver1"); | ||
ASADMIN.exec("delete-virtual-server", "vserver2"); | ||
} | ||
|
||
@AfterEach | ||
public void undeploy() { | ||
assertThat(ASADMIN.exec("undeploy", APP_NAME), asadminOK()); | ||
} | ||
|
||
@Test | ||
public void testDefaultDeploy() { | ||
// By default deploy on all virtual servers except __asadmin | ||
assertThat(ASADMIN.exec("deploy", warFile.getAbsolutePath()), asadminOK()); | ||
} | ||
|
||
@Test | ||
public void testDeployWithExplicitVirtualServersList() { | ||
assertThat(ASADMIN.exec("deploy", "--virtualservers", "server,vserver1", warFile.getAbsolutePath()), asadminOK()); | ||
} | ||
} |