Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the CommandBuilderTest to pass on Java 24+. #12

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Path;
Expand All @@ -33,18 +34,25 @@ class CommandBuilderTest {

@Test
void jBossModulesBuilder() {
final int featureVersion = Runtime.version().feature();
// Set up a standalone command builder
final JBossModulesCommandBuilder commandBuilder = JBossModulesCommandBuilder.of(WILDFLY_HOME, "org.jboss.as.launcher.test")
.addJavaOption("-Djava.security.manager")
.addJavaOption("-Djava.net.preferIPv4Stack=true")
.addJavaOption("-Djava.net.preferIPv4Stack=false")
.addModuleOption("-javaagent:test-agent1.jar")
.addServerArgument("--server=test");

if (featureVersion < 24) {
commandBuilder.addJavaOption("-Djava.security.manager");
} else {
assertThrows(IllegalArgumentException.class, () -> commandBuilder.addJavaOption("-Djava.security.manager"));
assertThrows(IllegalArgumentException.class, () -> commandBuilder.setUseSecurityManager(true));
}

// Get all the commands
List<String> commands = commandBuilder.buildArguments();

assertTrue(commands.contains("-secmgr"), "Missing -secmgr option");
assertEquals(featureVersion < 24, commands.contains("-secmgr"), "Missing -secmgr option");

assertTrue(commands.stream().anyMatch(entry -> entry.matches("-javaagent:.*jboss-modules.jar$")), "Missing jboss-modules.jar");
assertTrue(commands.contains("-javaagent:test-agent1.jar"), "Missing test-agent1.jar");
Expand All @@ -68,18 +76,25 @@ void jBossModulesBuilder() {

@Test
void standaloneBuilder() {
final int featureVersion = Runtime.version().feature();
// Set up a standalone command builder
final StandaloneCommandBuilder commandBuilder = StandaloneCommandBuilder.of(WILDFLY_HOME)
.setAdminOnly()
.setBindAddressHint("0.0.0.0")
.setDebug(true, 5005)
.setServerConfiguration("standalone-full.xml")
.addJavaOption("-Djava.security.manager")
.addJavaOption("-Djava.net.preferIPv4Stack=true")
.addJavaOption("-Djava.net.preferIPv4Stack=false")
.addModuleOption("-javaagent:test-agent1.jar")
.setBindAddressHint("management", "0.0.0.0");

if (featureVersion < 24) {
commandBuilder.addJavaOption("-Djava.security.manager");
} else {
assertThrows(IllegalArgumentException.class, () -> commandBuilder.addJavaOption("-Djava.security.manager"));
assertThrows(IllegalArgumentException.class, () -> commandBuilder.setUseSecurityManager(true));
}

// Get all the commands
List<String> commands = commandBuilder.buildArguments();

Expand All @@ -93,7 +108,7 @@ void standaloneBuilder() {

assertTrue(commands.contains("-c=standalone-full.xml"), "Missing server configuration file override");

assertTrue(commands.contains("-secmgr"), "Missing -secmgr option");
assertEquals(featureVersion < 24, commands.contains("-secmgr"), "Missing -secmgr option");

assertTrue(commands.stream().anyMatch(entry -> entry.matches("-javaagent:.*jboss-modules.jar$")), "Missing jboss-modules.jar");
assertTrue(commands.contains("-javaagent:test-agent1.jar"), "Missing test-agent1.jar");
Expand Down Expand Up @@ -186,16 +201,23 @@ void bootableJarBuilder() {

@Test
void domainBuilder() {
final int featureVersion = Runtime.version().feature();
// Set up a standalone command builder
final DomainCommandBuilder commandBuilder = DomainCommandBuilder.of(WILDFLY_HOME)
.setAdminOnly()
.setBindAddressHint("0.0.0.0")
.setMasterAddressHint("0.0.0.0")
.setDomainConfiguration("domain.xml")
.setHostConfiguration("host.xml")
.addProcessControllerJavaOption("-Djava.security.manager")
.setBindAddressHint("management", "0.0.0.0");

if (featureVersion < 24) {
commandBuilder.addJavaOption("-Djava.security.manager");
} else {
assertThrows(IllegalArgumentException.class, () -> commandBuilder.addJavaOption("-Djava.security.manager"));
assertThrows(IllegalArgumentException.class, () -> commandBuilder.setUseSecurityManager(true));
}

// Get all the commands
List<String> commands = commandBuilder.buildArguments();

Expand All @@ -209,7 +231,7 @@ void domainBuilder() {

assertTrue(commands.contains("-c=domain.xml"), "Missing server configuration file override");

assertTrue(commands.contains("-secmgr"), "Missing -secmgr option");
assertEquals(featureVersion < 24, commands.contains("-secmgr"), "Missing -secmgr option");

// If we're using Java 9+ ensure the modular JDK options were added
testModularJvmArguments(commands, 2);
Expand Down Expand Up @@ -280,7 +302,7 @@ void arguments() {
}

private void testEnhancedSecurityManager(final Collection<String> command, final int expectedCount) {
// If we're using Java 12+ ensure enhanced security manager option was added
// If we're using Java 12+, but less than 24 ensure enhanced security manager option was added
if (Jvm.current().enhancedSecurityManagerAvailable()) {
assertArgumentExists(command, "-Djava.security.manager=allow", expectedCount);
} else {
Expand Down