Skip to content

Commit

Permalink
Merge pull request #4633 from kabir/WFCORE-5464-expression-resolver-p…
Browse files Browse the repository at this point in the history
…olicy

[WFCORE-5464] Upgrade JBoss DMR and test expressions resolved fro…
  • Loading branch information
jmesnil committed Aug 25, 2021
2 parents 39517a1 + 7fae4fd commit bfc83ff
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
<artifact name="${org.jboss:jboss-dmr}"/>
</resources>


<dependencies>
<module name="org.jboss.logging"/>
</dependencies>
</module>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<version.org.jboss.classfilewriter>1.2.5.Final</version.org.jboss.classfilewriter>
<version.org.jboss.invocation>1.6.3.Final</version.org.jboss.invocation>
<version.org.jboss.jandex>2.2.3.Final</version.org.jboss.jandex>
<version.org.jboss.jboss-dmr>1.5.1.Final</version.org.jboss.jboss-dmr>
<version.org.jboss.jboss-dmr>1.6.1.Final</version.org.jboss.jboss-dmr>
<version.org.jboss.jboss-vfs>3.2.15.Final</version.org.jboss.jboss-vfs>
<version.org.jboss.logging.commons-logging-jboss-logging>1.0.0.Final</version.org.jboss.logging.commons-logging-jboss-logging>
<version.org.jboss.logging.jboss-logging>3.4.2.Final</version.org.jboss.logging.jboss-logging>
Expand Down
2 changes: 2 additions & 0 deletions testsuite/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@

<environmentVariables>
<JBOSS_HOME>${wildfly.home}</JBOSS_HOME>
<!-- Used in one of the tests -->
<TEST_ENVIRONMENT_VARIABLE>Hello world</TEST_ENVIRONMENT_VARIABLE>
</environmentVariables>

<systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2021 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.wildfly.core.test.standalone.mgmt;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;

import javax.inject.Inject;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.core.testrunner.ManagementClient;
import org.wildfly.core.testrunner.WildflyTestRunner;

/**
* This uses the TEST_ENVIRONMENT_VARIABLE environment variable set up in pom.xml
*
* @author <a href="mailto:kabir.khan@jboss.com">Kabir Khan</a>
*/
@RunWith(WildflyTestRunner.class)
public class ResolveExpressionFromEnvironmentVariableTestCase {

@Inject
private static ManagementClient managementClient;

@Test
public void testResolveExpressionFromEnvironmentVariable() throws Exception {
checkExpression("Hello world", "${test.environment-variable}");
}

@Test
public void testResolveExpressionFromEnvironmentVariableOverriddenBySystemProperty() throws Exception {
PathAddress propAddr = PathAddress.pathAddress("system-property", "test.environment-variable");
ModelNode addProp = Util.createAddOperation(propAddr);
addProp.get(VALUE).set("Hola mundo");
managementClient.executeForResult(addProp);
try {
checkExpression("Hola mundo", "${test.environment-variable}");
} finally {
ModelNode removeProp = Util.createRemoveOperation(propAddr);
managementClient.executeForResult(removeProp);
}
}


@Test
public void testResolveExpressionFromLegacyEnvironmentVariable() throws Exception {
PathAddress propAddr = PathAddress.pathAddress("system-property", "test.environment-variable");
ModelNode addProp = Util.createAddOperation(propAddr);
addProp.get(VALUE).set("Hola mundo");
managementClient.executeForResult(addProp);
try {
checkExpression("Hello world", "${env.TEST_ENVIRONMENT_VARIABLE}");
} finally {
ModelNode removeProp = Util.createRemoveOperation(propAddr);
managementClient.executeForResult(removeProp);
}
}

private void checkExpression(String expected, String expression) throws Exception {
ModelNode op = new ModelNode();
op.get(OP).set("resolve-expression");
op.get(OP_ADDR).setEmptyList();
op.get("expression").set(expression);
ModelNode result = managementClient.executeForResult(op);
Assert.assertEquals(expected, result.asString());
}
}

0 comments on commit bfc83ff

Please sign in to comment.