Skip to content

Commit

Permalink
Merge pull request #3716 from pferraro/test
Browse files Browse the repository at this point in the history
WFCORE-4388 Subsystem test framework alters order of child resources…
  • Loading branch information
jmesnil committed Apr 1, 2019
2 parents a239a80 + e9c42f7 commit 5952efc
Showing 1 changed file with 9 additions and 32 deletions.
Expand Up @@ -32,7 +32,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jboss.as.controller.ModelVersion;
Expand All @@ -44,7 +43,6 @@
import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration;
import org.jboss.as.controller.registry.LegacyResourceDefinition;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.junit.Assert;
Expand Down Expand Up @@ -120,39 +118,18 @@ private static Resource modelToResource(final PathAddress startAddress, final Im
}
res.writeModel(value);

Set<PathElement> childAddresses = reg.getChildAddresses(PathAddress.EMPTY_ADDRESS);

// When we have overrides those should be used for the checking. The set of child addresses however,
// may have the wildcard children before more specific ones. So we move the specific ones first
List<PathElement> sortedChildAddresses = ModelTestUtils.moveWildcardChildrenToEnd(childAddresses);
Set<PathElement> handledChildren = new HashSet<>();
for (PathElement path : sortedChildAddresses) {

ImmutableManagementResourceRegistration sub = reg.getSubModel(PathAddress.pathAddress(path));
if (path.isWildcard()) {
ModelNode subModel = model.get(path.getKey());
if (subModel.isDefined()) {
for (Property p : subModel.asPropertyList()) {
if (p.getValue().isDefined()) {
final PathElement element = PathElement.pathElement(path.getKey(), p.getName());
if (!handledChildren.contains(element)) {
res.registerChild(
element,
modelToResource(startAddress,sub, p.getValue(), includeUndefined, fullPath.append(path)));
}
}
}
}
} else {
ModelNode subModel = model.get(path.getKeyValuePair());
if (subModel.isDefined()) {
res.registerChild(path, modelToResource(startAddress,sub, subModel, includeUndefined, fullPath.append(path)));
for (String childType : reg.getChildNames(PathAddress.EMPTY_ADDRESS)) {
if (model.hasDefined(childType)) {
for (Property property : model.get(childType).asPropertyList()) {
PathElement childPath = PathElement.pathElement(childType, property.getName());
ImmutableManagementResourceRegistration subRegistration = reg.getSubModel(PathAddress.pathAddress(childPath));
Resource child = modelToResource(startAddress, subRegistration, property.getValue(), includeUndefined, fullPath.append(childPath));
res.registerChild(childPath, child);
}
}

handledChildren.add(path);
allFields.remove(path.getKey());
allFields.remove(childType);
}

if (!allFields.isEmpty()){
throw ControllerLogger.ROOT_LOGGER.modelFieldsNotKnown(allFields, startAddress.append(fullPath));
}
Expand Down

0 comments on commit 5952efc

Please sign in to comment.