Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFCORE-5861] Test case to verify JPMS settings works with non-modula…
…r CLI client launching an embedded server Jira Issue: https://issues.redhat.com/browse/WFCORE-5861
- Loading branch information
Showing
13 changed files
with
273 additions
and
32 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
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
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
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
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
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
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
129 changes: 129 additions & 0 deletions
129
...va/org/jboss/as/test/manualmode/management/cli/JbossCliClientJarJPMSSettingsTestCase.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,129 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2022 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.as.test.manualmode.management.cli; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.PropertyPermission; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.JarFile; | ||
import java.util.jar.Manifest; | ||
|
||
import org.jboss.as.test.integration.management.cli.CliProcessWrapper; | ||
import org.jboss.as.test.manualmode.management.cli.jpms.JPMSTestActivator; | ||
import org.jboss.as.test.shared.PermissionUtils; | ||
import org.jboss.as.test.shared.TestSuiteEnvironment; | ||
import org.jboss.msc.service.ServiceActivator; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.jboss.shrinkwrap.impl.base.exporter.zip.ZipExporterImpl; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Launches a non-modular CLI client and deploys an application that requires specific JPMS settings. This test case is used to | ||
* verify that jboss-cli-client.jar is able to run properly without requiring the user to add JVM modular settings when it | ||
* launches an embedded server. | ||
*/ | ||
public class JbossCliClientJarJPMSSettingsTestCase { | ||
private static final Path SERVER_HOME = Paths.get(TestSuiteEnvironment.getSystemProperty("jboss.dist")); | ||
private static CliProcessWrapper cli; | ||
private static File cliTestAppJar; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
cli = new CliProcessWrapper(false).addCliArgument("--no-color-output").addCliArgument("--timeout=30000"); | ||
cli.executeInteractive(); | ||
cliTestAppJar = createTestArchive("jpms-test-app.jar"); | ||
} | ||
|
||
@AfterClass | ||
public static void cleanup() throws Exception { | ||
cli.destroyProcess(); | ||
Files.deleteIfExists(cliTestAppJar.toPath()); | ||
} | ||
|
||
@Test | ||
public void testManifestEntries() throws Exception { | ||
JarFile clientJar = new JarFile( | ||
SERVER_HOME.resolve("bin").resolve("client").resolve("jboss-cli-client.jar").toString()); | ||
Manifest manifest = clientJar.getManifest(); | ||
Attributes mainAttribs = manifest.getMainAttributes(); | ||
String addOpens = mainAttribs.getValue("Add-Opens"); | ||
Assert.assertTrue("Unexpected value for Manifest Add-Opens. Current: " + addOpens, | ||
addOpens.contains("java.base/java.util")); | ||
} | ||
|
||
@Test | ||
public void testDeploymentRequiringJMPSSettings() throws Exception { | ||
String line = "embed-server --admin-only=false --jboss-home=" + SERVER_HOME.toAbsolutePath(); | ||
cli.pushLineAndWaitForResults(line); | ||
Assert.assertTrue("The CLI message that describes it is running on a non-modular environment was not found: \n" + cli.getOutput(), cli.getOutput().contains("non-modular")); | ||
cli.clearOutput(); | ||
|
||
// ensure there is no deployment yet | ||
cli.pushLineAndWaitForResults("deployment-info --name=" + cliTestAppJar.getName()); | ||
Assert.assertTrue("Apparently the deployment already exists: \n" + cli.getOutput(), cli.getOutput().contains("WFLYCTL0216")); | ||
cli.clearOutput(); | ||
|
||
// ensure that properties added by the deployment are not there | ||
cli.pushLineAndWaitForResults("/core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)"); | ||
Assert.assertTrue(JPMSTestActivator.DEFAULT_SYS_PROP_NAME + " name has been found after getting current System Properties. \n" + cli.getOutput(), !cli.getOutput().contains(JPMSTestActivator.DEFAULT_SYS_PROP_NAME)); | ||
Assert.assertTrue(JPMSTestActivator.DEFAULT_SYS_PROP_VALUE + " value has been found after getting current System Properties. \n" + cli.getOutput(), !cli.getOutput().contains(JPMSTestActivator.DEFAULT_SYS_PROP_VALUE)); | ||
cli.clearOutput(); | ||
|
||
// deploy and verify | ||
cli.pushLineAndWaitForResults("deploy " + cliTestAppJar.getAbsolutePath()); | ||
cli.pushLineAndWaitForResults("deployment-info --name=" + cliTestAppJar.getName()); | ||
Assert.assertTrue("The deployment Failed: \n" + cli.getOutput(), !cli.getOutput().contains("WFLYCTL0216")); | ||
cli.clearOutput(); | ||
|
||
// verifies the activator was executed | ||
cli.pushLineAndWaitForResults("/core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)"); | ||
Assert.assertTrue(JPMSTestActivator.DEFAULT_SYS_PROP_NAME + " name has not been found after getting current System Properties. \n" + cli.getOutput(), cli.getOutput().contains(JPMSTestActivator.DEFAULT_SYS_PROP_NAME)); | ||
Assert.assertTrue(JPMSTestActivator.DEFAULT_SYS_PROP_VALUE + " value has not been found after getting current System Properties. \n" + cli.getOutput(), cli.getOutput().contains(JPMSTestActivator.DEFAULT_SYS_PROP_VALUE)); | ||
cli.clearOutput(); | ||
|
||
// undeploy | ||
cli.pushLineAndWaitForResults("undeploy " + cliTestAppJar.getAbsolutePath()); | ||
cli.pushLineAndWaitForResults("deployment-info --name=" + cliTestAppJar.getName()); | ||
Assert.assertTrue("The undeploy Failed: \n" + cli.getOutput(), cli.getOutput().contains("WFLYCTL0216")); | ||
|
||
cli.pushLineAndWaitForResults("stop-embedded-server"); | ||
} | ||
|
||
public static File createTestArchive(String archiveName) { | ||
JavaArchive jar = ShrinkWrap.create(JavaArchive.class, archiveName); | ||
jar.addClass(JPMSTestActivator.class); | ||
jar.addAsServiceProvider(ServiceActivator.class, JPMSTestActivator.class); | ||
jar.addAsManifestResource(new StringAsset("Dependencies: org.jboss.msc\n"), "MANIFEST.MF"); | ||
jar.addAsManifestResource( | ||
PermissionUtils.createPermissionsXmlAsset(new PropertyPermission("test.deployment.trivial.prop", "write")), | ||
"permissions.xml"); | ||
|
||
final String tempDir = TestSuiteEnvironment.getTmpDir(); | ||
File file = new File(tempDir, jar.getName()); | ||
new ZipExporterImpl(jar).exportTo(file, true); | ||
return file; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ode/src/test/java/org/jboss/as/test/manualmode/management/cli/jpms/JPMSTestActivator.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,46 @@ | ||
package org.jboss.as.test.manualmode.management.cli.jpms; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.EnumMap; | ||
|
||
import org.jboss.msc.Service; | ||
import org.jboss.msc.service.ServiceActivator; | ||
import org.jboss.msc.service.ServiceActivatorContext; | ||
import org.jboss.msc.service.ServiceController; | ||
import org.jboss.msc.service.ServiceName; | ||
import org.jboss.msc.service.ServiceRegistryException; | ||
import org.jboss.msc.service.StartContext; | ||
import org.jboss.msc.service.StartException; | ||
import org.jboss.msc.service.StopContext; | ||
|
||
public class JPMSTestActivator implements ServiceActivator, Service { | ||
public static final ServiceName SERVICE_NAME = ServiceName.of("test", "deployment", "trivial"); | ||
public static final String DEFAULT_SYS_PROP_NAME = "test.deployment.trivial.prop"; | ||
public static final String DEFAULT_SYS_PROP_VALUE = "default-value"; | ||
|
||
@Override | ||
public void activate(ServiceActivatorContext serviceActivatorContext) throws ServiceRegistryException { | ||
// requires opens java.base/java.util | ||
for (Field field : EnumMap.class.getDeclaredFields()) { | ||
if (field.getType() == Class.class) { | ||
field.setAccessible(true); | ||
} | ||
} | ||
|
||
serviceActivatorContext.getServiceTarget() | ||
.addService(SERVICE_NAME) | ||
.setInstance(this) | ||
.setInitialMode(ServiceController.Mode.ACTIVE) | ||
.install(); | ||
} | ||
|
||
@Override | ||
public void start(StartContext context) throws StartException { | ||
System.setProperty(DEFAULT_SYS_PROP_NAME, DEFAULT_SYS_PROP_VALUE); | ||
} | ||
|
||
@Override | ||
public void stop(StopContext context) { | ||
System.clearProperty(DEFAULT_SYS_PROP_NAME); | ||
} | ||
} |
Oops, something went wrong.