Skip to content

Commit

Permalink
[WFCORE-3991] Test coverage for read-config-as-features
Browse files Browse the repository at this point in the history
  • Loading branch information
rjanik114 committed Aug 13, 2018
1 parent e7df14c commit 9d37ca7
Show file tree
Hide file tree
Showing 4 changed files with 695 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public class ModelDescriptionConstants {
public static final String HTTP_UPGRADE = "http-upgrade";
public static final String HTTP_UPGRADE_ENABLED = "http-upgrade-enabled";
public static final String HTTP_INTERFACE = "http-interface";
public static final String ID = "id";
public static final String IDENTITY = "identity";
public static final String IGNORED = "ignored-by-unaffected-host-controller";
public static final String IGNORED_RESOURCES = "ignored-resources";
Expand Down Expand Up @@ -275,6 +276,7 @@ public class ModelDescriptionConstants {
public static final String LEVEL = "level";
public static final String LDAP = "ldap";
public static final String LDAP_CONNECTION = "ldap-connection";
public static final String LIST_SNAPSHOTS_OPERATION = "list-snapshots";
public static final String LOCAL = "local";
public static final String LOCAL_DESTINATION_OUTBOUND_SOCKET_BINDING = "local-destination-outbound-socket-binding";
public static final String LOCAL_HOST_NAME = "local-host-name";
Expand Down Expand Up @@ -359,10 +361,10 @@ public class ModelDescriptionConstants {
public static final String PASSWORD = "password";
public static final String PATH = "path";
public static final String PATHS = "paths";
public static final String PATTERN = "pattern";
public static final String PERIODIC_ROTATING_FILE_HANDLER = "periodic-rotating-file-handler";
public static final String PERMISSION_COMBINATION_POLICY = "permission-combination-policy";
public static final String PERSIST_NAME = "persist-name";
public static final String PATTERN = "pattern";
public static final String PERSISTENT = "persistent";
public static final String PLAIN_TEXT = "plain-text";
public static final String PLATFORM_MBEAN = "platform-mbean";
Expand Down Expand Up @@ -549,6 +551,7 @@ public class ModelDescriptionConstants {
*/
public static final String SYNC_REMOVED_FOR_READD = "sync-dropped-for-readd";
public static final String TAIL_COMMENT_ALLOWED = "tail-comment-allowed";
public static final String TAKE_SNAPSHOT_OPERATION = "take-snapshot";
public static final String TARGET_PATH = "target-path";
public static final String TCP = "tcp";
public static final String TIMEOUT = "timeout";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2018, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.test.integration.domain.management;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.integration.domain.management.util.DomainLifecycleUtil;
import org.jboss.as.test.integration.domain.management.util.DomainTestSupport;
import org.jboss.as.test.integration.management.api.ReadConfigAsFeaturesTestBase;
import org.jboss.dmr.ModelNode;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*;

/**
* Tests {@code read-config-as-features} operation in domain mode.
*
* @author <a href="mailto:[email protected]">Richard Janík</a>
*/
public class ReadConfigAsFeaturesDomainTestCase extends ReadConfigAsFeaturesTestBase {

private static DomainTestSupport testSupport;
private static DomainLifecycleUtil domainMasterLifecycleUtil;

private String defaultDomainConfig;
private String defaultHostConfig;
private ModelNode defaultDomainConfigAsFeatures;
private ModelNode defaultHostConfigAsFeatures;

@BeforeClass
public static void setupDomain() {
testSupport = DomainTestSupport.createAndStartSupport(DomainTestSupport.Configuration.create(ReadConfigAsFeaturesDomainTestCase.class.getSimpleName(),
"domain-configs/domain-standard.xml", "host-configs/host-master.xml", "host-configs/host-slave.xml"));
domainMasterLifecycleUtil = testSupport.getDomainMasterLifecycleUtil();
}

@AfterClass
public static void tearDownDomain() {
testSupport.stop();
testSupport = null;
domainMasterLifecycleUtil = null;
}

@Test
public void domainSystemPropertyTest() {
ModelNode redefineProperty = Util.getWriteAttributeOperation(PathAddress.pathAddress(SYSTEM_PROPERTY, "jboss.domain.test.property.one"), VALUE, "SIX");
ModelNode addProperty = Util.createAddOperation(PathAddress.pathAddress(SYSTEM_PROPERTY, "customProp"));
addProperty.get(BOOT_TIME).set(false);
addProperty.get(VALUE).set("customPropVal");

ModelNode expectedDomainConfigAsFeatures = defaultDomainConfigAsFeatures.clone();

// modify the existing property
ModelNode propertyId = new ModelNode();
propertyId.get(SYSTEM_PROPERTY).set("jboss.domain.test.property.one");
ModelNode existingProperty = getListElement(expectedDomainConfigAsFeatures, "domain.system-property", propertyId);
existingProperty.get(PARAMS).get(VALUE).set("SIX");

// add the new property
ModelNode newPropertyId = new ModelNode();
ModelNode newPropertyParams = new ModelNode();
ModelNode newProperty = new ModelNode();
newPropertyId.get(SYSTEM_PROPERTY).set("customProp");
newPropertyParams.get(BOOT_TIME).set(false);
newPropertyParams.get(VALUE).set("customPropVal");
newProperty.get(SPEC).set("domain.system-property");
newProperty.get(ID).set(newPropertyId);
newProperty.get(PARAMS).set(newPropertyParams);
// add the new property
expectedDomainConfigAsFeatures.add(newProperty);

doTest(Arrays.asList(redefineProperty, addProperty), expectedDomainConfigAsFeatures, PathAddress.EMPTY_ADDRESS);
}

@Test
public void domainProfileTest() {
ModelNode redefineProfileAttribute = Util.getWriteAttributeOperation(
PathAddress.pathAddress(PROFILE, DEFAULT).append(SUBSYSTEM, "io").append("buffer-pool", "default"),
"buffer-size", 500);
ModelNode removeSubsystemFromProfile = Util.createRemoveOperation(PathAddress.pathAddress(PROFILE, DEFAULT).append(SUBSYSTEM, "request-controller"));

ModelNode expectedDomainConfigAsFeatures = defaultDomainConfigAsFeatures.clone();

// remove the request controller subsystem
ModelNode defaultProfileId = new ModelNode();
defaultProfileId.get(PROFILE).set(DEFAULT);
ModelNode defaultProfile = getListElement(expectedDomainConfigAsFeatures, PROFILE, defaultProfileId);
int requestControllerSubsystemIndex = getFeatureNodeChildIndex(defaultProfile, "profile.subsystem.request-controller");
defaultProfile.get(CHILDREN).remove(requestControllerSubsystemIndex);

// rewrite the buffer-pool attribute
ModelNode ioSubsystem = getFeatureNodeChild(defaultProfile, "profile.subsystem.io");
ModelNode bufferPool = getFeatureNodeChild(ioSubsystem, "profile.subsystem.io.buffer-pool");
ModelNode bufferPoolParams = new ModelNode();
bufferPoolParams.get("buffer-size").set(500);
bufferPool.get(PARAMS).set(bufferPoolParams);

doTest(Arrays.asList(redefineProfileAttribute, removeSubsystemFromProfile), expectedDomainConfigAsFeatures, PathAddress.EMPTY_ADDRESS);
}

@Test
public void hostInterfaceTest() {
ModelNode redefineInterface = Util.getWriteAttributeOperation(PathAddress.pathAddress(HOST, MASTER).append(INTERFACE, "management"), INET_ADDRESS, "10.10.10.10");

ModelNode expectedHostConfigAsFeatures = defaultHostConfigAsFeatures.clone();

ModelNode managementInterfaceId = new ModelNode();
managementInterfaceId.get(INTERFACE).set("management");
ModelNode managementInterface = getFeatureNodeChild(expectedHostConfigAsFeatures.get(0), "host.interface", managementInterfaceId);
ModelNode managementInterfaceParams = new ModelNode();
managementInterfaceParams.get(INET_ADDRESS).set("10.10.10.10");
managementInterface.get(PARAMS).set(managementInterfaceParams);

doTest(Collections.singletonList(redefineInterface), expectedHostConfigAsFeatures, PathAddress.pathAddress(HOST, MASTER));
}

@Test
public void hostSubsystemTest() {
ModelNode redefineJmxAttribute = Util.getWriteAttributeOperation(
PathAddress.pathAddress(HOST, MASTER).append(SUBSYSTEM, "jmx").append("expose-model", "resolved"),
"domain-name", "customDomainName");

ModelNode expectedHostConfigAsFeatures = defaultHostConfigAsFeatures.clone();

ModelNode jmxSubsystem = getFeatureNodeChild(expectedHostConfigAsFeatures.get(0), "host.subsystem.jmx");
ModelNode exposeModelResolved = getFeatureNodeChild(jmxSubsystem, "host.subsystem.jmx.expose-model.resolved");
ModelNode exposeModelResolvedParams = new ModelNode();
exposeModelResolvedParams.get("domain-name").set("customDomainName");
exposeModelResolved.get(PARAMS).set(exposeModelResolvedParams);

doTest(Collections.singletonList(redefineJmxAttribute), expectedHostConfigAsFeatures, PathAddress.pathAddress(HOST, MASTER));
}

private void doTest(List<ModelNode> operations, ModelNode expectedConfigAsFeatures, PathAddress domainOrHostPath) {
for (ModelNode operation : operations) {
domainMasterLifecycleUtil.executeForResult(operation);
}
if (!equalsWithoutListOrder(expectedConfigAsFeatures, getConfigAsFeatures(domainOrHostPath))) {
System.out.println("Actual:\n" + getConfigAsFeatures(domainOrHostPath).toJSONString(false) + "\nExpected:\n" + expectedConfigAsFeatures.toJSONString(false));
Assert.fail("There are differences between the expected and the actual model, see the test output for details");
}
}

@Override
protected void saveDefaultConfig() {
if (defaultDomainConfig == null || defaultHostConfig == null) {
ModelNode takeSnapshotOnDomain = Util.createEmptyOperation(TAKE_SNAPSHOT_OPERATION, PathAddress.EMPTY_ADDRESS);
ModelNode takeSnapshotOnHost = Util.createEmptyOperation(TAKE_SNAPSHOT_OPERATION, PathAddress.pathAddress(HOST, MASTER));
domainMasterLifecycleUtil.executeForResult(takeSnapshotOnDomain);
domainMasterLifecycleUtil.executeForResult(takeSnapshotOnHost);
ModelNode listDomainSnapshots = Util.createEmptyOperation(LIST_SNAPSHOTS_OPERATION, PathAddress.EMPTY_ADDRESS);
ModelNode listHostSnapshots = Util.createEmptyOperation(LIST_SNAPSHOTS_OPERATION, PathAddress.pathAddress(HOST, MASTER));
ModelNode domainSnapshots = domainMasterLifecycleUtil.executeForResult(listDomainSnapshots);
ModelNode hostSnapshots = domainMasterLifecycleUtil.executeForResult(listHostSnapshots);

defaultDomainConfig = domainSnapshots.get("names").get(0).asString();
defaultHostConfig = hostSnapshots.get("names").get(0).asString();
}
}

@Override
protected void saveDefaultResult() {
if (defaultDomainConfigAsFeatures == null || defaultHostConfigAsFeatures == null) {
defaultDomainConfigAsFeatures = getConfigAsFeatures(PathAddress.EMPTY_ADDRESS);
defaultHostConfigAsFeatures = getConfigAsFeatures(PathAddress.pathAddress(HOST, MASTER));
}
}

@Override
protected void restoreDefaultConfig() throws TimeoutException, InterruptedException {
ModelNode reloadWithSnapshots = Util.createEmptyOperation(RELOAD, PathAddress.pathAddress(HOST, MASTER));
reloadWithSnapshots.get(DOMAIN_CONFIG).set(defaultDomainConfig);
reloadWithSnapshots.get(HOST_CONFIG).set(defaultHostConfig);
domainMasterLifecycleUtil.executeForResult(reloadWithSnapshots);
domainMasterLifecycleUtil.awaitHostController(System.currentTimeMillis());
}

private ModelNode getConfigAsFeatures(PathAddress pathAddress) {
return domainMasterLifecycleUtil.executeForResult(
Util.createEmptyOperation(READ_CONFIG_AS_FEATURES_OPERATION, pathAddress));
}
}
Loading

0 comments on commit 9d37ca7

Please sign in to comment.