}
}
public void testExecuteOperations() throws Exception {
String subsystemXml = getSubsystemXml();
KernelServices services = super.installInController(subsystemXml);
// status check - our service should be available and have 2 plugin definitions
AgentService service = (AgentService) services.getContainer().getService(AgentService.SERVICE_NAME).getValue();
Assert.assertEquals(service.getPlugins().size(), 2);
PathAddress agentSubsystemPath = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM,
AgentSubsystemExtension.SUBSYSTEM_NAME));
// get the startup model from subsystem xml
ModelNode model = services.readWholeModel();
// current list of plugins from the attribute
ModelNode pluginsNode = model.get(SUBSYSTEM, AgentSubsystemExtension.SUBSYSTEM_NAME).get(
AgentSubsystemExtension.PLUGINS_ELEMENT);
// Add another plugin
pluginsNode.add("foo", true);
ModelNode addOp = new ModelNode();
addOp.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
addOp.get(OP_ADDR).set(agentSubsystemPath.toModelNode());
addOp.get(NAME).set(AgentSubsystemExtension.PLUGINS_ELEMENT);
addOp.get(VALUE).set(pluginsNode);
ModelNode result = services.executeOperation(addOp);
Assert.assertEquals(result.get(OUTCOME).asString(), SUCCESS);
// now test that things are as they should be
model = services.readWholeModel();
Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(AgentSubsystemExtension.SUBSYSTEM_NAME));
Assert.assertTrue(model.get(SUBSYSTEM, AgentSubsystemExtension.SUBSYSTEM_NAME).hasDefined(
AgentSubsystemExtension.AGENT_ENABLED));
Assert.assertTrue(model
.get(SUBSYSTEM, AgentSubsystemExtension.SUBSYSTEM_NAME, AgentSubsystemExtension.AGENT_ENABLED).resolve()
.asBoolean());
Assert.assertTrue(model.get(SUBSYSTEM, AgentSubsystemExtension.SUBSYSTEM_NAME).hasDefined(
AgentSubsystemExtension.PLUGINS_ELEMENT));
List<Property> plugins = model.get(SUBSYSTEM, AgentSubsystemExtension.SUBSYSTEM_NAME)
.get(AgentSubsystemExtension.PLUGINS_ELEMENT).asPropertyList();
Assert.assertEquals(plugins.size(), 3); // there were 2, but we added "foo" above
Assert.assertEquals(plugins.get(0).getName(), "platform"); // platform plugin is first in the xml
Assert.assertEquals(plugins.get(0).getValue().asBoolean(), true);
Assert.assertEquals(plugins.get(1).getName(), "blah"); // blah plugin is first in the xml
Assert.assertEquals(plugins.get(1).getValue().asBoolean(), false);
Assert.assertEquals(plugins.get(2).getName(), "foo"); // foo plugin we added above
Assert.assertEquals(plugins.get(2).getValue().asBoolean(), true);
// we enabled a new plugin - now should have 3 now
Assert.assertEquals(service.getPlugins().size(), 3);
Assert.assertTrue(service.getPlugins().get("platform"));
Assert.assertFalse(service.getPlugins().get("blah"));
Assert.assertTrue(service.getPlugins().get("foo"));
// Use read-attribute instead of reading the whole model to get an attribute value
ModelNode readOp = new ModelNode();
readOp.get(OP).set(READ_ATTRIBUTE_OPERATION);
readOp.get(OP_ADDR).set(agentSubsystemPath.toModelNode().resolve());
readOp.get(NAME).set(AgentSubsystemExtension.AGENT_ENABLED);
result = services.executeOperation(readOp);
Assert.assertTrue(checkResultAndGetContents(result).resolve().asBoolean());
readOp.get(NAME).set(AgentSubsystemExtension.PLUGINS_ELEMENT);
result = services.executeOperation(readOp);
ModelNode content = checkResultAndGetContents(result);
plugins = content.asPropertyList();
Assert.assertEquals(plugins.size(), 3); // there were 2, but we added "foo" above
Assert.assertEquals(plugins.get(0).getName(), "platform"); // platform plugin is first in the xml
Assert.assertEquals(plugins.get(0).getValue().asBoolean(), true);