1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.jboss.extension;
17
18 import static de.smartics.properties.jboss.extension.AbstractSubsystemFileBasedParsingTestCase.fetchXml;
19 import static de.smartics.properties.jboss.extension.resources.SubsystemDefinition.SUBSYSTEM_NAME;
20 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
21 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIBE;
22 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
23 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
24 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
25
26 import java.io.IOException;
27 import java.util.List;
28
29 import junit.framework.Assert;
30
31 import org.jboss.as.controller.PathAddress;
32 import org.jboss.as.controller.PathElement;
33 import org.jboss.as.subsystem.test.AbstractSubsystemTest;
34 import org.jboss.as.subsystem.test.KernelServices;
35 import org.jboss.dmr.ModelNode;
36 import org.junit.Ignore;
37 import org.junit.Test;
38
39
40
41
42
43
44
45
46
47
48
49 @Ignore
50 public class SubsystemParsingTestCase extends AbstractSubsystemTest
51 {
52
53 public SubsystemParsingTestCase()
54 {
55 super(SUBSYSTEM_NAME, new SubsystemExtension());
56 }
57
58
59
60
61 @Test
62 public void testParseSubsystem() throws Exception
63 {
64
65 final String subsystemXml = createXml();
66 final List<ModelNode> operations = super.parse(subsystemXml);
67
68
69 Assert.assertEquals(2, operations.size());
70
71
72 final ModelNode addSubsystem = operations.get(0);
73 Assert.assertEquals(ADD, addSubsystem.get(OP).asString());
74 final PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR));
75 Assert.assertEquals(1, addr.size());
76 final PathElement element = addr.getElement(0);
77 Assert.assertEquals(SUBSYSTEM, element.getKey());
78 Assert.assertEquals(SUBSYSTEM_NAME, element.getValue());
79 }
80
81 private String createXml() throws IOException
82 {
83 final String xml = fetchXml("cache-only.xml");
84 return xml;
85 }
86
87
88
89
90 @Test
91 public void testInstallIntoController() throws Exception
92 {
93
94 final String subsystemXml = createXml();
95 final KernelServices services = super.installInController(subsystemXml);
96
97
98 final ModelNode model = services.readWholeModel();
99 Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(SUBSYSTEM_NAME));
100 }
101
102
103
104
105
106
107 @Test
108 public void testParseAndMarshalModel() throws Exception
109 {
110
111 final String subsystemXml = createXml();
112 final KernelServices servicesA = super.installInController(subsystemXml);
113
114 final ModelNode modelA = servicesA.readWholeModel();
115 final String marshalled = servicesA.getPersistedSubsystemXml();
116
117
118
119 final KernelServices servicesB = super.installInController(marshalled);
120 final ModelNode modelB = servicesB.readWholeModel();
121
122
123 super.compare(modelA, modelB);
124 }
125
126
127
128
129
130
131 @Test
132 public void testDescribeHandler() throws Exception
133 {
134
135 final String subsystemXml = createXml();
136 final KernelServices servicesA = super.installInController(subsystemXml);
137
138 final ModelNode modelA = servicesA.readWholeModel();
139 final ModelNode describeOp = new ModelNode();
140 describeOp.get(OP).set(DESCRIBE);
141 describeOp.get(OP_ADDR).set(
142 PathAddress.pathAddress(
143 PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME)).toModelNode());
144 final List<ModelNode> operations =
145 super.checkResultAndGetContents(servicesA.executeOperation(describeOp))
146 .asList();
147
148
149
150 final KernelServices servicesB = super.installInController(operations);
151 final ModelNode modelB = servicesB.readWholeModel();
152
153
154 super.compare(modelA, modelB);
155 }
156
157
158
159
160 @Test
161 public void testSubsystemRemoval() throws Exception
162 {
163
164 final String subsystemXml = createXml();
165 final KernelServices services = super.installInController(subsystemXml);
166
167 super.assertRemoveSubsystemResources(services);
168
169
170 }
171 }