Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] WFCORE-692 read-children-names(include-aliases=true) can return phantom results #729

Merged
merged 1 commit into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,16 @@ static Map<String, Set<String>> getChildAddresses(final OperationContext context
}
}
} else {
//PathAddress target = aliasEntry.getTargetAddress();
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())) {
set.add(element.getValue());
if (parentResource != null) {
PathElement targetElement = target.getLastElement();
if (targetElement.isWildcard()) {
set.addAll(parentResource.getChildrenNames(targetElement.getKey()));
} else if (parentResource.hasChild(targetElement)) {
set.add(element.getValue());
}
}
}
if (!element.isWildcard()) {
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