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

[WFARQ-170] Add a server setup task for setting system properties and… #451

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* Copyright 2022 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -17,44 +17,59 @@
* limitations under the License.
*/

package org.wildfly.arquillian.integration.test.junit5.server.setup;
package org.jboss.as.arquillian.setup;

import java.util.Map;

import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder;
import org.jboss.dmr.ModelNode;

/**
* A setup task for Arquillian tests which set system properties in WildFly and remove them when the test is complete.
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
public class SystemPropertyServerSetupTask implements ServerSetupTask {
public final Map<String, String> properties;
public abstract class SystemPropertyServerSetupTask implements ServerSetupTask {

private final Map<String, String> properties;

public SystemPropertyServerSetupTask(final Map<String, String> properties) {
this.properties = Map.copyOf(properties);
/**
* Creates a new setup task which defines the provided properties.
*
* @param properties the properties to add
*/
protected SystemPropertyServerSetupTask(final Map<String, String> properties) {
this.properties = properties;
}

@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create();
for (var entry : properties.entrySet()) {
final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
for (Map.Entry<String, String> entry : properties.entrySet()) {
final ModelNode address = Operations.createAddress("system-property", entry.getKey());
final ModelNode op = Operations.createAddOperation(address);
op.get("value").set(entry.getValue());
builder.addStep(op);
}
executeOperation(managementClient, builder.build());
executeOperation(managementClient, builder.build(),
(result) -> String.format("Failed to add system properties %s%n%s", properties,
Operations.getFailureDescription(result)
.asString()));
}

@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {
final Operations.CompositeOperationBuilder builder = Operations.CompositeOperationBuilder.create();
for (var entry : properties.entrySet()) {
final CompositeOperationBuilder builder = CompositeOperationBuilder.create();
for (Map.Entry<String, String> entry : properties.entrySet()) {
final ModelNode address = Operations.createAddress("system-property", entry.getKey());
builder.addStep(Operations.createRemoveOperation(address));
}
executeOperation(managementClient, builder.build());
executeOperation(managementClient, builder.build(),
(result) -> String.format("Failed to remove system properties %s%n%s", properties,
Operations.getFailureDescription(result)
.asString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.arquillian.setup.SystemPropertyServerSetupTask;
import org.jboss.as.controller.client.helpers.ClientConstants;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.dmr.ModelNode;
Expand Down