Skip to content

Commit

Permalink
WFCORE-692 read-children-names(include-aliases=true) can return phant…
Browse files Browse the repository at this point in the history
…om results if another resource exists with the same key as tje target address of a resource alias.
  • Loading branch information
pferraro committed May 14, 2015
1 parent 207dbb8 commit 87048ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ static Map<String, Set<String>> getChildAddresses(final OperationContext context
PathAddress target = aliasEntry.convertToTargetAddress(addr.append(element));
PathAddress targetParent = target.subAddress(0, target.size() - 1);
Resource parentResource = context.readResourceFromRoot(targetParent, false);
if (parentResource != null && parentResource.hasChildren(target.getLastElement().getKey())) {
if (parentResource != null && parentResource.hasChild(target.getLastElement())) {
set.add(element.getValue());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class AliasResourceTestCase extends AbstractControllerTestBase {
private static final String CORE = "core";
private static final String ALIASED = "aliased";
static final String MODEL = "model";
static final String OTHER = "other";
private static final String CHILD = "child";
private static final String KID_MODEL = "kid";
private static final String KID_ALIASED = "kid-aliased";
Expand Down Expand Up @@ -244,6 +245,7 @@ public void readChildrenTypes() throws Exception {
public void testReadChildresNamesNoModel() throws Exception {
ModelNode op = createOperation(READ_CHILDREN_NAMES_OPERATION);
op.get(CHILD_TYPE).set(CORE);
op.get(INCLUDE_ALIASES).set(true);
ModelNode result = executeForResult(op);
List<ModelNode> list = result.asList();
Assert.assertEquals(0, list.size());
Expand All @@ -252,6 +254,20 @@ public void testReadChildresNamesNoModel() throws Exception {
result = executeForResult(op);
list = result.asList();
Assert.assertEquals(0, list.size());

addCore(CORE, OTHER);
// Validate WFCORE-692
// This should result in 1 child of type "core", but 0 children of type "alias", since "core" =>"other" has no aliases
op.get(CHILD_TYPE).set(CORE);
result = executeForResult(op);
list = result.asList();
Assert.assertEquals(1, list.size());
Assert.assertTrue(list.contains(new ModelNode(OTHER)));

op.get(CHILD_TYPE).set(ALIASED);
result = executeForResult(op);
list = result.asList();
Assert.assertEquals(0, list.size());
}

@Test
Expand Down Expand Up @@ -435,7 +451,11 @@ private void checkInvokeOp(String main, String other) throws Exception {
}

private void addCore(String main) throws Exception {
ModelNode op = createOperation(ADD, main, MODEL);
this.addCore(main, MODEL);
}

private void addCore(String key, String value) throws Exception {
ModelNode op = createOperation(ADD, key, value);
op.get("rw").set("R/W");
op.get("ro").set("R/O");
executeForResult(op);
Expand Down Expand Up @@ -639,7 +659,6 @@ private void checkAttribute(ModelNode attr, String description, String accessTyp
}

@Override
@SuppressWarnings("deprecation")
protected void initModel(ManagementModel managementModel) {
ManagementResourceRegistration registration = managementModel.getRootResourceRegistration();
GlobalOperationHandlers.registerGlobalOperations(registration, processType);
Expand All @@ -648,29 +667,13 @@ protected void initModel(ManagementModel managementModel) {

GlobalNotifications.registerGlobalNotifications(registration, processType);

ManagementResourceRegistration coreResourceRegistration = registration.registerSubModel(new CoreResourceDefinition());
registration.registerAlias(getAliasedModelElement(),
new TestAliasEntry(coreResourceRegistration));
ManagementResourceRegistration coreResourceRegistration = registration.registerSubModel(new CoreResourceDefinition(MODEL));
registration.registerAlias(PathElement.pathElement(ALIASED, MODEL), new TestAliasEntry(coreResourceRegistration));

ManagementResourceRegistration childReg = coreResourceRegistration.registerSubModel(new ChildResourceDefinition());
coreResourceRegistration.registerAlias(getAliasedChildModelElement(),
new TestAliasEntry(childReg));
}

private PathElement getCoreModelElement() {
return PathElement.pathElement(CORE, MODEL);
}

private PathElement getAliasedModelElement() {
return PathElement.pathElement(ALIASED, MODEL);
}

private PathElement getChildModelElement() {
return PathElement.pathElement(CHILD, KID_MODEL);
}
coreResourceRegistration.registerAlias(PathElement.pathElement(CHILD, KID_ALIASED), new TestAliasEntry(childReg));

private PathElement getAliasedChildModelElement() {
return PathElement.pathElement(CHILD, KID_ALIASED);
registration.registerSubModel(new CoreResourceDefinition(OTHER));
}

private static SimpleAttributeDefinition READ_WRITE = new SimpleAttributeDefinition("rw", ModelType.STRING, true);
Expand All @@ -685,8 +688,8 @@ private PathElement getAliasedChildModelElement() {

private class CoreResourceDefinition extends SimpleResourceDefinition {

public CoreResourceDefinition() {
super(getCoreModelElement(), createResourceDescriptionResolver(), new CoreAddHandler(), new CoreRemoveHandler());
public CoreResourceDefinition(String value) {
super(PathElement.pathElement(CORE, value), createResourceDescriptionResolver(), new CoreAddHandler(), new CoreRemoveHandler());
}

@Override
Expand All @@ -708,7 +711,7 @@ public void registerOperations(ManagementResourceRegistration resourceRegistrati

private class ChildResourceDefinition extends SimpleResourceDefinition {
public ChildResourceDefinition() {
super(getChildModelElement(), createResourceDescriptionResolver(), new ChildAddHandler(), new ChildRemoveHandler());
super(PathElement.pathElement(CHILD, KID_MODEL), createResourceDescriptionResolver(), new ChildAddHandler(), new ChildRemoveHandler());
}

@Override
Expand Down

0 comments on commit 87048ba

Please sign in to comment.