Skip to content

Commit

Permalink
[WFCORE-6972]: Fixing the tests to support community schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
  • Loading branch information
ehsavoie committed Oct 1, 2024
1 parent efa4443 commit 7b82390
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ public static void setupDomain() throws Exception {
public void testDomainReadConfigAsXmlFile() throws Exception {
DomainClient domainClient = domainPrimaryLifecycleUtil.getDomainClient();
ModelNode request = new ModelNode();
request.get(OP).set("read-config-as-xml-file");
request.get(OP).set("write-config");
request.get(OP_ADDR).setEmptyList();
domainClient.execute(request);
String expectedXml = loadXMLConfigurationFile( new File(domainPrimaryLifecycleUtil.getConfiguration().getDomainDirectory()).toPath().resolve("configuration").resolve("testing-domain-standard.xml"));

request = new ModelNode();
request.get(OP).set("read-config-as-xml-file");
request.get(OP_ADDR).setEmptyList();
OperationResponse opResponse = domainClient.executeOperation(Operation.Factory.create(request), OperationMessageHandler.DISCARD);
String xml = validateOperationResponse(opResponse);
String expectedXml = loadXMLConfigurationFile(Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainConfigFile()));
Path expected = new File("target", "expected-domain.xml").toPath();
Files.write(expected, Collections.singletonList(expectedXml));
Path result = new File("target", "result-domain.xml").toPath();
Files.write(result, Collections.singletonList(xml));
Assert.assertEquals(expectedXml, xml);
Expand All @@ -69,9 +71,12 @@ public void testDomainReadConfigAsXmlFile() throws Exception {
public void testDomainReadConfigAsXmlFileWithCli() throws Exception {
WildFlyManagedConfiguration config = domainPrimaryLifecycleUtil.getConfiguration();
try (CLIWrapper cli = new CLIWrapper(config.getHostControllerManagementAddress(), config.getHostControllerManagementPort(), true)) {
cli.sendLine(":write-config");

Path result = new File("target", "result-domain-cli.xml").toPath();
cli.sendLine("attachment save --operation=:read-config-as-xml-file --file=" + result.toString());
String expectedXml = loadXMLConfigurationFile(Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainConfigFile()));
Path expectedXmlPath = Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-domain-standard.xml");
String expectedXml = loadXMLConfigurationFile(expectedXmlPath);
Path expected = new File("target", "expected-domain.xml").toPath();
Files.write(expected, Collections.singletonList(expectedXml));
Assert.assertEquals(expectedXml, Files.readString(result));
Expand All @@ -81,25 +86,37 @@ public void testDomainReadConfigAsXmlFileWithCli() throws Exception {

@Test
public void testHostReadConfigAsXmlFile() throws Exception {

DomainClient domainClient = domainPrimaryLifecycleUtil.getDomainClient();
ModelNode request = new ModelNode();
request.get(OP).set("read-config-as-xml-file");
request.get(OP).set("write-config");
request.get(OP_ADDR).setEmptyList().add(HOST, "primary");
domainClient.execute(request);
Path expectedXmlPath = Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-host-primary.xml");
String expectedXml = loadXMLConfigurationFile(expectedXmlPath);

request = new ModelNode();
request.get(OP).set("read-config-as-xml-file");
request.get(OP_ADDR).setEmptyList().add(HOST, "primary");
OperationResponse opResponse = domainClient.executeOperation(Operation.Factory.create(request), OperationMessageHandler.DISCARD);
String xml = validateOperationResponse(opResponse);
String expectedXml = loadXMLHostConfigurationFile(Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getHostConfigFile()), "primary");
Path expected = new File("target", "expected-primary.xml").toPath();
Files.write(expected, Collections.singletonList(expectedXml));
Path result = new File("target", "result-primary.xml").toPath();
Files.write(result, Collections.singletonList(xml));
Assert.assertEquals(expectedXml, xml);

request = new ModelNode();
request.get(OP).set("write-config");
request.get(OP_ADDR).setEmptyList().add(HOST, "secondary");
domainClient.execute(request);
expectedXmlPath = Paths.get(domainSecondaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-host-secondary.xml");
expectedXml = loadXMLConfigurationFile(expectedXmlPath);

request = new ModelNode();
request.get(OP).set("read-config-as-xml-file");
request.get(OP_ADDR).setEmptyList().add(HOST, "secondary");
opResponse = domainClient.executeOperation(Operation.Factory.create(request), OperationMessageHandler.DISCARD);
xml = validateOperationResponse(opResponse);
expectedXml = loadXMLHostConfigurationFile(Paths.get(domainSecondaryLifecycleUtil.getConfiguration().getHostConfigFile()), "secondary");
expected = new File("target", "expected-secondary.xml").toPath();
Files.write(expected, Collections.singletonList(expectedXml));
result = new File("target", "result-secondary.xml").toPath();
Expand All @@ -111,20 +128,20 @@ public void testHostReadConfigAsXmlFile() throws Exception {
public void testHostReadConfigAsXmlFileWithCli() throws Exception {
WildFlyManagedConfiguration config = domainPrimaryLifecycleUtil.getConfiguration();
try (CLIWrapper cli = new CLIWrapper(config.getHostControllerManagementAddress(), config.getHostControllerManagementPort(), true)) {
String expectedXml = loadXMLHostConfigurationFile(Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getHostConfigFile()), "primary");
Path expected = new File("target", "expected-primary.xml").toPath();
Files.write(expected, Collections.singletonList(expectedXml));
cli.sendLine("/host=primary/:write-config");
Path expectedXmlPath = Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-host-primary.xml");
String expectedXml = loadXMLConfigurationFile(expectedXmlPath);
Path result = new File("target", "result-primary-cli.xml").toPath();
cli.sendLine("attachment save --operation=/host=primary/:read-config-as-xml-file --file=" + result.toString());
Assert.assertEquals(expectedXml, Files.readString(result));
cli.quit();
}
try (CLIWrapper cli = new CLIWrapper(config.getHostControllerManagementAddress(), config.getHostControllerManagementPort(), true)) {
cli.sendLine("/host=secondary/:write-config");
Path result = new File("target", "result-secondary-cli.xml").toPath();
cli.sendLine("attachment save --operation=/host=secondary/:read-config-as-xml-file --file=" + result.toString());
String expectedXml = loadXMLHostConfigurationFile(Paths.get(domainSecondaryLifecycleUtil.getConfiguration().getHostConfigFile()), "secondary");
Path expected = new File("target", "expected-secondary.xml").toPath();
Files.write(expected, Collections.singletonList(expectedXml));
Path expectedXmlPath = Paths.get(domainSecondaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-host-secondary.xml");
String expectedXml = loadXMLConfigurationFile(expectedXmlPath);
Assert.assertEquals(expectedXml, Files.readString(result));
cli.quit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ManagementReadXmlTestCase {

@BeforeClass
public static void setupDomain() throws Exception {
DomainTestSuite.stopSupport();
testSupport = DomainTestSuite.createSupport(ManagementReadXmlTestCase.class.getSimpleName());
domainPrimaryLifecycleUtil = testSupport.getDomainPrimaryLifecycleUtil();
domainSecondaryLifecycleUtil = testSupport.getDomainSecondaryLifecycleUtil();
Expand Down Expand Up @@ -150,15 +151,20 @@ private static void prepareExpectedServerConfiguration(String server, boolean pr

@Test
public void testDomainReadConfigAsXml() throws Exception {

DomainClient domainClient = domainPrimaryLifecycleUtil.getDomainClient();
ModelNode request = new ModelNode();
request.get(OP).set("read-config-as-xml");
request.get(OP).set("write-config");
request.get(OP_ADDR).setEmptyList();

DomainClient domainClient = domainPrimaryLifecycleUtil.getDomainClient();
ModelNode response = domainClient.execute(request);
validateResponse(response, true);
Path expectedXmlPath = Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-domain-standard.xml");

request = new ModelNode();
request.get(OP).set("read-config-as-xml");
request.get(OP_ADDR).setEmptyList();
response = domainClient.execute(request);
String xml = validateResponse(response, true).asString().replace('\'', '\"');
String expectedXml = loadXMLConfigurationFile(Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainConfigFile()));
String expectedXml = loadXMLConfigurationFile(expectedXmlPath);
Assert.assertEquals(expectedXml, xml);
}

Expand All @@ -167,18 +173,33 @@ public void testHostReadConfigAsXml() throws Exception {

DomainClient domainClient = domainPrimaryLifecycleUtil.getDomainClient();
ModelNode request = new ModelNode();
request.get(OP).set("read-config-as-xml");
request.get(OP).set("write-config");
request.get(OP_ADDR).setEmptyList().add(HOST, "primary");

ModelNode response = domainClient.execute(request);
validateResponse(response, true);
Path expectedXmlPath = Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-host-primary.xml");

request = new ModelNode();
request.get(OP).set("read-config-as-xml");
request.get(OP_ADDR).setEmptyList().add(HOST, "primary");
response = domainClient.execute(request);
String xml = validateResponse(response, true).asString().replace('\'', '\"');
String expectedXml = loadXMLHostConfigurationFile(Paths.get(domainPrimaryLifecycleUtil.getConfiguration().getHostConfigFile()), "primary");
String expectedXml = loadXMLConfigurationFile(expectedXmlPath);
Assert.assertEquals(expectedXml, xml);

request = new ModelNode();
request.get(OP_ADDR).setEmptyList().add(HOST, "secondary");
request.get(OP).set("write-config");
response = domainClient.execute(request);
validateResponse(response, true);
expectedXmlPath = Paths.get(domainSecondaryLifecycleUtil.getConfiguration().getDomainDirectory()).resolve("configuration").resolve("testing-host-secondary.xml");

request = new ModelNode();
request.get(OP).set("read-config-as-xml");
request.get(OP_ADDR).setEmptyList().add(HOST, "secondary");
response = domainClient.execute(request);
xml = validateResponse(response, true).asString().replace('\'', '\"');
expectedXml = loadXMLHostConfigurationFile(Paths.get(domainSecondaryLifecycleUtil.getConfiguration().getHostConfigFile()), "secondary");
expectedXml = loadXMLConfigurationFile(expectedXmlPath);
Assert.assertEquals(expectedXml, xml);
}

Expand Down Expand Up @@ -231,10 +252,4 @@ protected static String loadXMLConfigurationFile(Path file) throws Exception {
.trim();
}
}

protected static String loadXMLHostConfigurationFile(Path file, String hostName) throws Exception {
return loadXMLConfigurationFile(file)
.replace(hostName + "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", hostName + "\"")
.trim();
}
}
2 changes: 1 addition & 1 deletion testsuite/domain/src/test/resources/base-server-config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<server xmlns="urn:jboss:domain:community:20.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:domain:community:20.0 wildfly-config_community_20_0.xsd">
<server xmlns="urn:jboss:domain:20.0">
<extensions>
<extension module="org.jboss.as.jmx"/>
<extension module="org.jboss.as.logging"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
~ SPDX-License-Identifier: Apache-2.0
-->

<domain xmlns="urn:jboss:domain:community:20.0">
<domain xmlns="urn:jboss:domain:20.0">

<extensions>
<extension module="org.jboss.as.jmx"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
~ SPDX-License-Identifier: Apache-2.0
-->

<host xmlns="urn:jboss:domain:community:20.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:domain:community:20.0 wildfly-config_community_20_0.xsd"
<host xmlns="urn:jboss:domain:20.0"
name="primary" organization="core-primary">

<extensions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
~ SPDX-License-Identifier: Apache-2.0
-->

<host xmlns="urn:jboss:domain:community:20.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:domain:community:20.0 wildfly-config_community_20_0.xsd"
name="secondary">
<host xmlns="urn:jboss:domain:20.0" name="secondary">

<extensions>
<extension module="org.jboss.as.jmx"/>
Expand Down

0 comments on commit 7b82390

Please sign in to comment.