Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

put tests back

  • Loading branch information...
commit 59d26b06fd3556c944a5e2a52ffd196ccb07d6b4 1 parent 0361b92
Tomaz Cerar authored March 19, 2012 kabir committed March 20, 2012
26  ...as-subsystem-archetype/src/test/java/com/mycompany/subsystem/extension/SubsystemBaseParsingTestCase.java
... ...
@@ -0,0 +1,26 @@
  1
+package com.mycompany.subsystem.extension;
  2
+
  3
+import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
  4
+
  5
+import java.io.IOException;
  6
+
  7
+/**
  8
+ * This is the barebone test example that tests subsystem
  9
+ * It does same things that {@link SubsystemParsingTestCase} does but most of internals are already done in AbstractSubsystemBaseTest
  10
+ * If you need more control over what happens in tests look at  {@link SubsystemParsingTestCase}
  11
+ * @author <a href="mailto:tomaz.cerar@redhat.com">Tomaz Cerar</a>
  12
+ */
  13
+public class SubsystemBaseParsingTestCase extends AbstractSubsystemBaseTest {
  14
+
  15
+    public SubsystemBaseParsingTestCase() {
  16
+        super(SubsystemExtension.SUBSYSTEM_NAME, new SubsystemExtension());
  17
+    }
  18
+
  19
+
  20
+    @Override
  21
+    protected String getSubsystemXml() throws IOException {
  22
+        return "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
  23
+                "</subsystem>";
  24
+    }
  25
+
  26
+}
131  jboss-as-subsystem-archetype/src/test/java/com/mycompany/subsystem/extension/SubsystemParsingTestCase.java
... ...
@@ -1,25 +1,142 @@
1 1
 package com.mycompany.subsystem.extension;
2 2
 
3 3
 
4  
-import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
  4
+import junit.framework.Assert;
  5
+import org.jboss.as.controller.PathAddress;
  6
+import org.jboss.as.controller.PathElement;
  7
+import org.jboss.as.subsystem.test.AbstractSubsystemTest;
  8
+import org.jboss.as.subsystem.test.KernelServices;
  9
+import org.jboss.dmr.ModelNode;
  10
+import org.junit.Test;
5 11
 
6  
-import java.io.IOException;
  12
+import java.util.List;
  13
+
  14
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
  15
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
  16
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  17
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  18
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
7 19
 
8 20
 
9 21
 /**
  22
+ * Tests all management expects for subsystem, parsing, marshaling, model definition and other
  23
+ * Here is an example that allows you a fine grained controler over what is tested and how. So it can give you ideas what can be done and tested.
  24
+ * If you have no need for advanced testing of subsystem you look at {@link SubsystemBaseParsingTestCase} that testes same stuff but most of the code
  25
+ * is hidden inside of test harness
  26
+ *
10 27
  * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
11 28
  */
12  
-public class SubsystemParsingTestCase extends AbstractSubsystemBaseTest {
  29
+public class SubsystemParsingTestCase extends AbstractSubsystemTest {
13 30
 
14 31
     public SubsystemParsingTestCase() {
15 32
         super(SubsystemExtension.SUBSYSTEM_NAME, new SubsystemExtension());
16 33
     }
17 34
 
18  
-    @Override
19  
-    protected String getSubsystemXml() throws IOException {
20  
-        return "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
21  
-                "</subsystem>";
  35
+    /**
  36
+     * Tests that the xml is parsed into the correct operations
  37
+     */
  38
+    @Test
  39
+    public void testParseSubsystem() throws Exception {
  40
+        //Parse the subsystem xml into operations
  41
+        String subsystemXml =
  42
+                "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
  43
+                        "</subsystem>";
  44
+        List<ModelNode> operations = super.parse(subsystemXml);
  45
+
  46
+        ///Check that we have the expected number of operations
  47
+        Assert.assertEquals(1, operations.size());
  48
+
  49
+        //Check that each operation has the correct content
  50
+        ModelNode addSubsystem = operations.get(0);
  51
+        Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
  52
+        PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
  53
+        Assert.assertEquals(1, addr.size());
  54
+        PathElement element = addr.getElement(0);
  55
+        Assert.assertEquals(SUBSYSTEM, element.getKey());
  56
+        Assert.assertEquals(SubsystemExtension.SUBSYSTEM_NAME, element.getValue());
  57
+    }
  58
+
  59
+    /**
  60
+     * Test that the model created from the xml looks as expected
  61
+     */
  62
+    @Test
  63
+    public void testInstallIntoController() throws Exception {
  64
+        //Parse the subsystem xml and install into the controller
  65
+        String subsystemXml =
  66
+                "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
  67
+                        "</subsystem>";
  68
+        KernelServices services = super.installInController(subsystemXml);
  69
+
  70
+        //Read the whole model and make sure it looks as expected
  71
+        ModelNode model = services.readWholeModel();
  72
+        Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SubsystemExtension.SUBSYSTEM_NAME));
  73
+    }
  74
+
  75
+    /**
  76
+     * Starts a controller with a given subsystem xml and then checks that a second
  77
+     * controller started with the xml marshalled from the first one results in the same model
  78
+     */
  79
+    @Test
  80
+    public void testParseAndMarshalModel() throws Exception {
  81
+        //Parse the subsystem xml and install into the first controller
  82
+        String subsystemXml =
  83
+                "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
  84
+                        "</subsystem>";
  85
+        KernelServices servicesA = super.installInController(subsystemXml);
  86
+        //Get the model and the persisted xml from the first controller
  87
+        ModelNode modelA = servicesA.readWholeModel();
  88
+        String marshalled = servicesA.getPersistedSubsystemXml();
  89
+
  90
+        //Install the persisted xml from the first controller into a second controller
  91
+        KernelServices servicesB = super.installInController(marshalled);
  92
+        ModelNode modelB = servicesB.readWholeModel();
  93
+
  94
+        //Make sure the models from the two controllers are identical
  95
+        super.compare(modelA, modelB);
  96
+    }
  97
+
  98
+    /**
  99
+     * Starts a controller with the given subsystem xml and then checks that a second
  100
+     * controller started with the operations from its describe action results in the same model
  101
+     */
  102
+    @Test
  103
+    public void testDescribeHandler() throws Exception {
  104
+        //Parse the subsystem xml and install into the first controller
  105
+        String subsystemXml =
  106
+                "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
  107
+                        "</subsystem>";
  108
+        KernelServices servicesA = super.installInController(subsystemXml);
  109
+        //Get the model and the describe operations from the first controller
  110
+        ModelNode modelA = servicesA.readWholeModel();
  111
+        ModelNode describeOp = new ModelNode();
  112
+        describeOp.get(OP).set(DESCRIBE);
  113
+        describeOp.get(OP_ADDR).set(
  114
+                PathAddress.pathAddress(
  115
+                        PathElement.pathElement(SUBSYSTEM, SubsystemExtension.SUBSYSTEM_NAME)).toModelNode());
  116
+        List<ModelNode> operations = super.checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();
  117
+
  118
+
  119
+        //Install the describe options from the first controller into a second controller
  120
+        KernelServices servicesB = super.installInController(operations);
  121
+        ModelNode modelB = servicesB.readWholeModel();
  122
+
  123
+        //Make sure the models from the two controllers are identical
  124
+        super.compare(modelA, modelB);
22 125
     }
23 126
 
  127
+    /**
  128
+     * Tests that the subsystem can be removed
  129
+     */
  130
+    @Test
  131
+    public void testSubsystemRemoval() throws Exception {
  132
+        //Parse the subsystem xml and install into the first controller
  133
+        String subsystemXml =
  134
+                "<subsystem xmlns=\"" + SubsystemExtension.NAMESPACE + "\">" +
  135
+                        "</subsystem>";
  136
+        KernelServices services = super.installInController(subsystemXml);
  137
+        //Checks that the subsystem was removed from the model
  138
+        super.assertRemoveSubsystemResources(services);
24 139
 
  140
+        //TODO Chek that any services that were installed were removed here
  141
+    }
25 142
 }
54  jboss-as-subsystem-example/src/main/java/com/acme/corp/tracker/extension/TrackerTickHandler.java
@@ -2,9 +2,7 @@
2 2
 
3 3
 import org.jboss.as.controller.AbstractWriteAttributeHandler;
4 4
 import org.jboss.as.controller.OperationContext;
5  
-import org.jboss.as.controller.OperationContext.Stage;
6 5
 import org.jboss.as.controller.OperationFailedException;
7  
-import org.jboss.as.controller.OperationStepHandler;
8 6
 import org.jboss.as.controller.PathAddress;
9 7
 import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
10 8
 import org.jboss.dmr.ModelNode;
@@ -17,49 +15,51 @@
17 15
     public static final TrackerTickHandler INSTANCE = new TrackerTickHandler();
18 16
 
19 17
     private TrackerTickHandler() {
  18
+        super(TypeDefinition.TICK);
20 19
     }
21 20
 
  21
+
22 22
     /**
23 23
      * Hook to allow subclasses to make runtime changes to effect the attribute value change.
24 24
      *
25  
-     * @param context the context of the operation
26  
-     * @param operation the operation
27  
-     * @param attributeName the name of the attribute being modified
28  
-     * @param resolvedValue the new value for the attribute, after {@link ModelNode#resolve()} has been called on it
29  
-     * @param currentValue the existing value for the attribute
  25
+     * @param context        the context of the operation
  26
+     * @param operation      the operation
  27
+     * @param attributeName  the name of the attribute being modified
  28
+     * @param resolvedValue  the new value for the attribute, after {@link ModelNode#resolve()} has been called on it
  29
+     * @param currentValue   the existing value for the attribute
30 30
      * @param handbackHolder holder for an arbitrary object to pass to
31  
-     *             {@link #revertUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, Object)} if
32  
-     *             the operation needs to be rolled back
33  
-     *
  31
+     *                       {@link #revertUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, Object)} if
  32
+     *                       the operation needs to be rolled back
34 33
      * @return {@code true} if the server requires restart to effect the attribute
35 34
      *         value change; {@code false} if not
36 35
      */
37 36
 
38  
-    protected  boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
39  
-                                                        ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException{
40  
-        if (attributeName.equals(TrackerExtension.TICK)){
  37
+    protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
  38
+                                           ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handbackHolder) throws OperationFailedException {
  39
+        if (attributeName.equals(TrackerExtension.TICK)) {
41 40
             final String suffix = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
42 41
             TrackerService service = (TrackerService) context.getServiceRegistry(true).getRequiredService(TrackerService.createServiceName(suffix)).getValue();
43  
-            service.setTick(currentValue.asLong());
  42
+            service.setTick(resolvedValue.asLong());
44 43
             context.completeStep();
45 44
         }
46 45
 
47 46
         return false;
48 47
     }
49  
-/**
50  
-    * Hook to allow subclasses to revert runtime changes made in
51  
-    * {@link #applyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)}.
52  
-    *
53  
-    * @param context the context of the operation
54  
-    * @param operation the operation
55  
-    * @param attributeName the name of the attribute being modified
56  
-    * @param valueToRestore the previous value for the attribute, before this operation was executed
57  
-    * @param valueToRevert the new value for the attribute that should be reverted
58  
-    * @param handback an object, if any, passed in to the {@code handbackHolder} by the {@code applyUpdateToRuntime}
59  
-    *                 implementation
60  
-    */
  48
+
  49
+    /**
  50
+     * Hook to allow subclasses to revert runtime changes made in
  51
+     * {@link #applyUpdateToRuntime(OperationContext, ModelNode, String, ModelNode, ModelNode, HandbackHolder)}.
  52
+     *
  53
+     * @param context        the context of the operation
  54
+     * @param operation      the operation
  55
+     * @param attributeName  the name of the attribute being modified
  56
+     * @param valueToRestore the previous value for the attribute, before this operation was executed
  57
+     * @param valueToRevert  the new value for the attribute that should be reverted
  58
+     * @param handback       an object, if any, passed in to the {@code handbackHolder} by the {@code applyUpdateToRuntime}
  59
+     *                       implementation
  60
+     */
61 61
     protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName,
62  
-                                                      ModelNode valueToRestore, ModelNode valueToRevert, Void handback) {
  62
+                                         ModelNode valueToRestore, ModelNode valueToRevert, Void handback) {
63 63
         // no-op
64 64
     }
65 65
 }
22  jboss-as-subsystem-example/src/test/java/com/acme/corp/tracker/extension/SubsystemBaseParsingTestCase.java
... ...
@@ -0,0 +1,22 @@
  1
+package com.acme.corp.tracker.extension;
  2
+
  3
+
  4
+import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
  5
+
  6
+import java.io.IOException;
  7
+
  8
+
  9
+/**
  10
+ * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
  11
+ */
  12
+public class SubsystemBaseParsingTestCase extends AbstractSubsystemBaseTest {
  13
+
  14
+    public SubsystemBaseParsingTestCase() {
  15
+        super(TrackerExtension.SUBSYSTEM_NAME, new TrackerExtension());
  16
+    }
  17
+
  18
+    @Override
  19
+    protected String getSubsystemXml() throws IOException {
  20
+        return readResource("subsystem.xml");
  21
+    }
  22
+}
228  jboss-as-subsystem-example/src/test/java/com/acme/corp/tracker/extension/SubsystemParsingTestCase.java
... ...
@@ -1,22 +1,238 @@
1 1
 package com.acme.corp.tracker.extension;
2 2
 
3 3
 
4  
-import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
  4
+import junit.framework.Assert;
  5
+import org.jboss.as.controller.PathAddress;
  6
+import org.jboss.as.controller.PathElement;
  7
+import org.jboss.as.subsystem.test.AbstractSubsystemTest;
  8
+import org.jboss.as.subsystem.test.KernelServices;
  9
+import org.jboss.dmr.ModelNode;
  10
+import org.junit.Test;
5 11
 
6  
-import java.io.IOException;
  12
+import java.util.List;
  13
+
  14
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
  15
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
  16
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
  17
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  18
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  19
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
  20
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
  21
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
  22
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
  23
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE;
  24
+import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.WRITE_ATTRIBUTE_OPERATION;
7 25
 
8 26
 
9 27
 /**
10 28
  * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
11 29
  */
12  
-public class SubsystemParsingTestCase extends AbstractSubsystemBaseTest {
  30
+public class SubsystemParsingTestCase extends AbstractSubsystemTest {
13 31
 
14 32
     public SubsystemParsingTestCase() {
15 33
         super(TrackerExtension.SUBSYSTEM_NAME, new TrackerExtension());
16 34
     }
17 35
 
18  
-    @Override
19  
-    protected String getSubsystemXml() throws IOException {
20  
-        return readResource("subsystem.xml");
  36
+    /**
  37
+     * Tests that the xml is parsed into the correct operations
  38
+     */
  39
+    @Test
  40
+    public void testParseSubsystem() throws Exception {
  41
+        //Parse the subsystem xml into operations
  42
+        String subsystemXml =
  43
+                "<subsystem xmlns=\"" + TrackerExtension.NAMESPACE + "\">" +
  44
+                        "   <deployment-types>" +
  45
+                        "       <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
  46
+                        "   </deployment-types>" +
  47
+                        "</subsystem>";
  48
+        List<ModelNode> operations = super.parse(subsystemXml);
  49
+
  50
+        ///Check that we have the expected number of operations
  51
+        Assert.assertEquals(2, operations.size());
  52
+
  53
+        //Check that each operation has the correct content
  54
+        //The add subsystem operation will happen first
  55
+        ModelNode addSubsystem = operations.get(0);
  56
+        Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
  57
+        PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
  58
+        Assert.assertEquals(1, addr.size());
  59
+        PathElement element = addr.getElement(0);
  60
+        Assert.assertEquals(SUBSYSTEM, element.getKey());
  61
+        Assert.assertEquals(TrackerExtension.SUBSYSTEM_NAME, element.getValue());
  62
+
  63
+        //Then we will get the add type operation
  64
+        ModelNode addType = operations.get(1);
  65
+        Assert.assertEquals(ADD, addType.get(OP).asString());
  66
+        Assert.assertEquals(12345, addType.get("tick").asLong());
  67
+        addr = PathAddress.pathAddress(addType.get(OP_ADDR));
  68
+        Assert.assertEquals(2, addr.size());
  69
+        element = addr.getElement(0);
  70
+        Assert.assertEquals(SUBSYSTEM, element.getKey());
  71
+        Assert.assertEquals(TrackerExtension.SUBSYSTEM_NAME, element.getValue());
  72
+        element = addr.getElement(1);
  73
+        Assert.assertEquals("type", element.getKey());
  74
+        Assert.assertEquals("tst", element.getValue());
  75
+    }
  76
+
  77
+    /**
  78
+     * Test that the model created from the xml looks as expected
  79
+     */
  80
+    @Test
  81
+    public void testInstallIntoController() throws Exception {
  82
+        //Parse the subsystem xml and install into the controller
  83
+        String subsystemXml =
  84
+                "<subsystem xmlns=\"" + TrackerExtension.NAMESPACE + "\">" +
  85
+                        "   <deployment-types>" +
  86
+                        "       <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
  87
+                        "   </deployment-types>" +
  88
+                        "</subsystem>";
  89
+        KernelServices services = super.installInController(subsystemXml);
  90
+
  91
+        //Read the whole model and make sure it looks as expected
  92
+        ModelNode model = services.readWholeModel();
  93
+        //Useful for debugging :-)
  94
+        //System.out.println(model);
  95
+        Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(TrackerExtension.SUBSYSTEM_NAME));
  96
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME).hasDefined("type"));
  97
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type").hasDefined("tst"));
  98
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type", "tst").hasDefined("tick"));
  99
+        Assert.assertEquals(12345, model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type", "tst", "tick").asLong());
  100
+    }
  101
+
  102
+    /**
  103
+     * Starts a controller with a given subsystem xml and then checks that a second
  104
+     * controller started with the xml marshalled from the first one results in the same model
  105
+     */
  106
+    @Test
  107
+    public void testParseAndMarshalModel() throws Exception {
  108
+        //Parse the subsystem xml and install into the first controller
  109
+        String subsystemXml =
  110
+                "<subsystem xmlns=\"" + TrackerExtension.NAMESPACE + "\">" +
  111
+                        "   <deployment-types>" +
  112
+                        "       <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
  113
+                        "   </deployment-types>" +
  114
+                        "</subsystem>";
  115
+        KernelServices servicesA = super.installInController(subsystemXml);
  116
+        //Get the model and the persisted xml from the first controller
  117
+        ModelNode modelA = servicesA.readWholeModel();
  118
+        String marshalled = servicesA.getPersistedSubsystemXml();
  119
+
  120
+        //Install the persisted xml from the first controller into a second controller
  121
+        KernelServices servicesB = super.installInController(marshalled);
  122
+        ModelNode modelB = servicesB.readWholeModel();
  123
+
  124
+        //Make sure the models from the two controllers are identical
  125
+        super.compare(modelA, modelB);
  126
+    }
  127
+
  128
+    /**
  129
+     * Starts a controller with the given subsystem xml and then checks that a second
  130
+     * controller started with the operations from its describe action results in the same model
  131
+     */
  132
+    @Test
  133
+    public void testDescribeHandler() throws Exception {
  134
+        //Parse the subsystem xml and install into the first controller
  135
+        String subsystemXml =
  136
+                "<subsystem xmlns=\"" + TrackerExtension.NAMESPACE + "\">" +
  137
+                        "</subsystem>";
  138
+        KernelServices servicesA = super.installInController(subsystemXml);
  139
+        //Get the model and the describe operations from the first controller
  140
+        ModelNode modelA = servicesA.readWholeModel();
  141
+        ModelNode describeOp = new ModelNode();
  142
+        describeOp.get(OP).set(DESCRIBE);
  143
+        describeOp.get(OP_ADDR).set(
  144
+                PathAddress.pathAddress(
  145
+                        PathElement.pathElement(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME)).toModelNode());
  146
+        List<ModelNode> operations = super.checkResultAndGetContents(servicesA.executeOperation(describeOp)).asList();
  147
+
  148
+        //Install the describe options from the first controller into a second controller
  149
+        KernelServices servicesB = super.installInController(operations);
  150
+        ModelNode modelB = servicesB.readWholeModel();
  151
+
  152
+        //Make sure the models from the two controllers are identical
  153
+        super.compare(modelA, modelB);
  154
+
  155
+    }
  156
+
  157
+    /**
  158
+     * Tests that the subsystem can be removed
  159
+     */
  160
+    @Test
  161
+    public void testSubsystemRemoval() throws Exception {
  162
+        //Parse the subsystem xml and install into the first controller
  163
+        String subsystemXml =
  164
+                "<subsystem xmlns=\"" + TrackerExtension.NAMESPACE + "\">" +
  165
+                        "   <deployment-types>" +
  166
+                        "       <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
  167
+                        "   </deployment-types>" +
  168
+                        "</subsystem>";
  169
+        KernelServices services = super.installInController(subsystemXml);
  170
+
  171
+        //Sanity check to test the service for 'tst' was there
  172
+        services.getContainer().getRequiredService(TrackerService.createServiceName("tst"));
  173
+
  174
+        //Checks that the subsystem was removed from the model
  175
+        super.assertRemoveSubsystemResources(services);
  176
+
  177
+        //Check that any services that were installed were removed here
  178
+        try {
  179
+            services.getContainer().getRequiredService(TrackerService.createServiceName("tst"));
  180
+            Assert.fail("Should have removed services");
  181
+        } catch (Exception expected) {
  182
+        }
  183
+    }
  184
+
  185
+    @Test
  186
+    public void testExecuteOperations() throws Exception {
  187
+        String subsystemXml =
  188
+                "<subsystem xmlns=\"" + TrackerExtension.NAMESPACE + "\">" +
  189
+                        "   <deployment-types>" +
  190
+                        "       <deployment-type suffix=\"tst\" tick=\"12345\"/>" +
  191
+                        "   </deployment-types>" +
  192
+                        "</subsystem>";
  193
+        KernelServices services = super.installInController(subsystemXml);
  194
+
  195
+        //Add another type
  196
+        PathAddress fooTypeAddr = PathAddress.pathAddress(
  197
+                PathElement.pathElement(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME),
  198
+                PathElement.pathElement("type", "foo"));
  199
+        ModelNode addOp = new ModelNode();
  200
+        addOp.get(OP).set(ADD);
  201
+        addOp.get(OP_ADDR).set(fooTypeAddr.toModelNode());
  202
+        addOp.get("tick").set(1000);
  203
+        ModelNode result = services.executeOperation(addOp);
  204
+        Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
  205
+
  206
+
  207
+        ModelNode model = services.readWholeModel();
  208
+        Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(TrackerExtension.SUBSYSTEM_NAME));
  209
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME).hasDefined("type"));
  210
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type").hasDefined("tst"));
  211
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type", "tst").hasDefined("tick"));
  212
+        Assert.assertEquals(12345, model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type", "tst", "tick").asLong());
  213
+
  214
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type").hasDefined("foo"));
  215
+        Assert.assertTrue(model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type", "foo").hasDefined("tick"));
  216
+        Assert.assertEquals(1000, model.get(SUBSYSTEM, TrackerExtension.SUBSYSTEM_NAME, "type", "foo", "tick").asLong());
  217
+
  218
+        //Call write-attribute
  219
+        ModelNode writeOp = new ModelNode();
  220
+        writeOp.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
  221
+        writeOp.get(OP_ADDR).set(fooTypeAddr.toModelNode());
  222
+        writeOp.get(NAME).set("tick");
  223
+        writeOp.get(VALUE).set(3456);
  224
+        result = services.executeOperation(writeOp);
  225
+        Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
  226
+
  227
+        //Check that write attribute took effect, this time by calling read-attribute instead of reading the whole model
  228
+        ModelNode readOp = new ModelNode();
  229
+        readOp.get(OP).set(READ_ATTRIBUTE_OPERATION);
  230
+        readOp.get(OP_ADDR).set(fooTypeAddr.toModelNode());
  231
+        readOp.get(NAME).set("tick");
  232
+        result = services.executeOperation(readOp);
  233
+        Assert.assertEquals(3456, checkResultAndGetContents(result).asLong());
  234
+
  235
+        TrackerService service = (TrackerService) services.getContainer().getService(TrackerService.createServiceName("foo")).getValue();
  236
+        Assert.assertEquals(3456, service.getTick());
21 237
     }
22 238
 }

0 notes on commit 59d26b0

Please sign in to comment.
Something went wrong with that request. Please try again.