AdjustOperationForDomain { ModelNode adjust(ModelNode operation) { if (!options.isDomain) { return operation; } if (Constants.COMPOSITE.equals(operation.get(Constants.OP).asString())) { ModelNode steps = operation.get(Constants.STEPS); if (steps.getType() != ModelType.LIST) { throw new IllegalArgumentException("Composite operation steps is not a list: " + steps.asString()); } for (ModelNode step : steps.asList()) { adjust(step); } return operation; } ModelNode address = operation.get(Constants.OP_ADDR); if (address.getType() != ModelType.LIST) { throw new IllegalArgumentException("Operation address is not a list: " + address.asString()); } Property prependToAddress = null; List<ModelNode> addressElements = address.asList(); for (ModelNode addressElement : addressElements) { if (addressElement.getType() != ModelType.PROPERTY) { throw new IllegalArgumentException("Operation address element is not a property: " + addressElement.asString()); } Property property = addressElement.asProperty(); if (Constants.PROFILE.equals(property.getName()) || Constants.HOST.equals(property.getName())) { return operation; } if (Constants.SUBSYSTEM.equals(property.getName())) { checkProfile(operation.asString()); prependToAddress = new Property(Constants.PROFILE, new ModelNode(options.defaultProfile)); break; } if (Constants.CORE_SERVICE.equals(property.getName()) && options.defaultHost != null) { prependToAddress = new Property(Constants.HOST, new ModelNode(options.defaultHost)); break; } } if (prependToAddress != null) { address.setEmptyList(); address.add(prependToAddress); for (ModelNode addressElement : addressElements) { address.add(addressElement); } } return operation; } AdjustOperationForDomain(OnlineOptions options);   }
@Test public void modelNodeOperation_standalone() { OnlineOptions options = OnlineOptions.standalone().localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); ModelNode op = new ModelNode(); op.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); ModelNode adjustedOp = new ModelNode(); adjustedOp.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.SUBSYSTEM, "web"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.SUBSYSTEM, "web"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.CORE_SERVICE, "management"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.CORE_SERVICE, "management"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.INTERFACE, "public"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.INTERFACE, "public"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.SOCKET_BINDING_GROUP, "standard-sockets"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.SOCKET_BINDING_GROUP, "standard-sockets"); assertEquals(adjustedOp, adjust.adjust(op)); }
@Test public void modelNodeOperation_domain() { OnlineOptions options = OnlineOptions.domain().forHost("master").forProfile("default").build() .localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); ModelNode op = new ModelNode(); op.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); ModelNode adjustedOp = new ModelNode(); adjustedOp.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.SUBSYSTEM, "web"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.PROFILE, "default") .add(Constants.SUBSYSTEM, "web"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.CORE_SERVICE, "management"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.HOST, "master") .add(Constants.CORE_SERVICE, "management"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.INTERFACE, "public"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.INTERFACE, "public"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.SOCKET_BINDING_GROUP, "standard-sockets"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.SOCKET_BINDING_GROUP, "standard-sockets"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.PROFILE, "default").add(Constants.SUBSYSTEM, "web"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.PROFILE, "default").add(Constants.SUBSYSTEM, "web"); assertEquals(adjustedOp, adjust.adjust(op)); op.get(Constants.OP_ADDR).setEmptyList().add(Constants.HOST, "master") .add(Constants.CORE_SERVICE, "management"); adjustedOp.get(Constants.OP_ADDR).setEmptyList().add(Constants.HOST, "master") .add(Constants.CORE_SERVICE, "management"); assertEquals(adjustedOp, adjust.adjust(op)); }
@Test public void batch_modelNodeOperation_domain() { OnlineOptions options = OnlineOptions.domain().forHost("master").forProfile("default").build() .localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); ModelNode op = new ModelNode(); op.get(Constants.OP).set(Constants.COMPOSITE); op.get(Constants.OP_ADDR).setEmptyList(); op.get(Constants.STEPS).setEmptyList(); ModelNode adjustedOp = new ModelNode(); adjustedOp.get(Constants.OP).set(Constants.COMPOSITE); adjustedOp.get(Constants.OP_ADDR).setEmptyList(); adjustedOp.get(Constants.STEPS).setEmptyList(); ModelNode step = new ModelNode(); ModelNode adjustedStep = new ModelNode(); step.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); step.get(Constants.OP_ADDR).setEmptyList().add(Constants.SUBSYSTEM, "web"); adjustedStep.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); adjustedStep.get(Constants.OP_ADDR).setEmptyList().add(Constants.PROFILE, "default") .add(Constants.SUBSYSTEM, "web"); op.get(Constants.STEPS).add(step); adjustedOp.get(Constants.STEPS).add(adjustedStep); step = new ModelNode(); adjustedStep = new ModelNode(); step.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); step.get(Constants.OP_ADDR).setEmptyList().add(Constants.CORE_SERVICE, "management"); adjustedStep.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); adjustedStep.get(Constants.OP_ADDR).setEmptyList().add(Constants.HOST, "master") .add(Constants.CORE_SERVICE, "management"); op.get(Constants.STEPS).add(step); adjustedOp.get(Constants.STEPS).add(adjustedStep); step = new ModelNode(); adjustedStep = new ModelNode(); step.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); step.get(Constants.OP_ADDR).setEmptyList().add(Constants.INTERFACE, "public"); adjustedStep.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); adjustedStep.get(Constants.OP_ADDR).setEmptyList().add(Constants.INTERFACE, "public"); op.get(Constants.STEPS).add(step); adjustedOp.get(Constants.STEPS).add(adjustedStep); step = new ModelNode(); adjustedStep = new ModelNode(); step.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); step.get(Constants.OP_ADDR).setEmptyList().add(Constants.SOCKET_BINDING_GROUP, "standard-sockets"); adjustedStep.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); adjustedStep.get(Constants.OP_ADDR).setEmptyList().add(Constants.SOCKET_BINDING_GROUP, "standard-sockets"); op.get(Constants.STEPS).add(step); adjustedOp.get(Constants.STEPS).add(adjustedStep); step = new ModelNode(); adjustedStep = new ModelNode(); step.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); step.get(Constants.OP_ADDR).setEmptyList().add(Constants.PROFILE, "default").add(Constants.SUBSYSTEM, "web"); adjustedStep.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); adjustedStep.get(Constants.OP_ADDR).setEmptyList().add(Constants.PROFILE, "default") .add(Constants.SUBSYSTEM, "web"); op.get(Constants.STEPS).add(step); adjustedOp.get(Constants.STEPS).add(adjustedStep); step = new ModelNode(); adjustedStep = new ModelNode(); step.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); step.get(Constants.OP_ADDR).setEmptyList().add(Constants.HOST, "master") .add(Constants.CORE_SERVICE, "management"); adjustedStep.get(Constants.OP).set(Constants.READ_RESOURCE_OPERATION); adjustedStep.get(Constants.OP_ADDR).setEmptyList().add(Constants.HOST, "master") .add(Constants.CORE_SERVICE, "management"); op.get(Constants.STEPS).add(step); adjustedOp.get(Constants.STEPS).add(adjustedStep); assertEquals(adjustedOp, adjust.adjust(op)); }
@Test public void stringOperation_standalone() { OnlineOptions options = OnlineOptions.standalone().localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); assertEquals("/subsystem=web:read-resource", adjust.adjust("/subsystem=web:read-resource")); assertEquals("/core-service=management:read-resource", adjust.adjust("/core-service=management:read-resource")); assertEquals("/interface=public:read-resource", adjust.adjust("/interface=public:read-resource")); assertEquals("/socket-binding-group=standard-sockets:read-resource", adjust.adjust("/socket-binding-group=standard-sockets:read-resource")); }
@Test public void stringOperation_domain() { OnlineOptions options = OnlineOptions.domain().forHost("master").forProfile("default").build() .localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); assertEquals("/profile=default/subsystem=web:read-resource", adjust.adjust("/subsystem=web:read-resource")); assertEquals("/host=master/core-service=management:read-resource", adjust.adjust("/core-service=management:read-resource")); assertEquals("/interface=public:read-resource", adjust.adjust("/interface=public:read-resource")); assertEquals("/socket-binding-group=standard-sockets:read-resource", adjust.adjust("/socket-binding-group=standard-sockets:read-resource")); assertEquals("/profile=default/subsystem=web:read-resource", adjust.adjust("/profile=default/subsystem=web:read-resource")); assertEquals("/host=master/core-service=management:read-resource", adjust.adjust("/host=master/core-service=management:read-resource")); }
@Test(expected = IllegalArgumentException.class) public void unknownProfile() { OnlineOptions options = OnlineOptions.domain().build().localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); adjust.adjust("/subsystem=web:read-resource"); }
@Test public void unknownHost() { OnlineOptions options = OnlineOptions.domain().build().localDefault().build(); AdjustOperationForDomain adjust = new AdjustOperationForDomain(options); assertEquals("/core-service=management:read-resource", adjust.adjust("/core-service=management:read-resource")); }