/
DatasourcesSubsystemTestCase.java
287 lines (247 loc) · 13.3 KB
/
DatasourcesSubsystemTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.connector.subsystems.datasources;
import java.io.IOException;
import java.util.List;
import org.jboss.as.connector.logging.ConnectorLogger;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.model.test.FailedOperationTransformationConfig;
import org.jboss.as.model.test.FailedOperationTransformationConfig.AttributesPathAddressConfig;
import org.jboss.as.model.test.ModelTestControllerVersion;
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.as.model.test.SingleClassFilter;
import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
import org.jboss.as.subsystem.test.AdditionalInitialization;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.as.subsystem.test.KernelServicesBuilder;
import org.jboss.as.subsystem.test.LegacyKernelServicesInitializer;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
/**
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
* @author <a href="stefano.maestri@redhat.com>Stefano Maestri</a>
*/
public class DatasourcesSubsystemTestCase extends AbstractSubsystemBaseTest {
public DatasourcesSubsystemTestCase() {
super(DataSourcesExtension.SUBSYSTEM_NAME, new DataSourcesExtension());
}
@Override
protected String getSubsystemXml() throws IOException {
//test configuration put in standalone.xml
return readResource("datasources-minimal.xml");
}
@Override
protected String getSubsystemXsdPath() throws Exception {
return "schema/wildfly-datasources_5_0.xsd";
}
@Override
protected String[] getSubsystemTemplatePaths() throws IOException {
return new String[]{
"/subsystem-templates/datasources.xml"
};
}
@Test
@Override
public void testSchemaOfSubsystemTemplates() throws Exception {
super.testSchemaOfSubsystemTemplates();
}
@Test
public void testFullConfig() throws Exception {
standardSubsystemTest("datasources-full.xml");
}
@Test
public void testExpressionConfig() throws Exception {
standardSubsystemTest("datasources-full-expression.xml", "datasources-full.xml");
}
protected AdditionalInitialization createAdditionalInitialization() {
return AdditionalInitialization.MANAGEMENT;
}
@Test
public void testTransformerEAP62() throws Exception {
testTransformer("datasources-full.xml", ModelTestControllerVersion.EAP_6_2_0, ModelVersion.create(1, 2, 0));
}
@Test
public void testTransformerExpressionEAP62() throws Exception {
testTransformer("datasources-full-expression111.xml", ModelTestControllerVersion.EAP_6_2_0, ModelVersion.create(1, 2, 0));
}
@Test
public void testTransformerEAP63() throws Exception {
testTransformer("datasources-full.xml", ModelTestControllerVersion.EAP_6_3_0, ModelVersion.create(1, 3, 0));
}
@Test
public void testTransformerExpressionEAP63() throws Exception {
testTransformer("datasources-full-expression111.xml", ModelTestControllerVersion.EAP_6_3_0, ModelVersion.create(1, 3, 0));
}
@Test
public void testTransformerEAP64() throws Exception {
testTransformer("datasources-full.xml", ModelTestControllerVersion.EAP_6_4_0, ModelVersion.create(1, 3, 0));
}
@Test
public void testTransformerExpressionEAP64() throws Exception {
testTransformer("datasources-full-expression111.xml", ModelTestControllerVersion.EAP_6_4_0, ModelVersion.create(1, 3, 0));
}
@Test
public void testTransformerElytronEnabledEAP64() throws Exception {
testTransformerElytronEnabled("datasources-elytron-enabled_5_0.xml", ModelTestControllerVersion.EAP_6_4_0, ModelVersion.create(1, 3, 0));
}
@Test
public void testTransformerEAP7() throws Exception {
testTransformerEAP7FullConfiguration("datasources-full.xml");
}
@Test
public void testRejectionsEAP7() throws Exception {
testTransformerEAP7Rejection("datasources-no-connection-url.xml");
}
@Test
public void testTransformerWF8() throws Exception {
testTransformer("datasources-full.xml", ModelTestControllerVersion.WILDFLY_8_0_0_FINAL, ModelVersion.create(2, 0, 0));
}
@Test
public void testTransformerWF82() throws Exception {
testTransformer("datasources-full.xml", ModelTestControllerVersion.WILDFLY_8_2_0_FINAL, ModelVersion.create(3, 0, 0));
}
private KernelServices initialKernelServices(KernelServicesBuilder builder, ModelTestControllerVersion controllerVersion, final ModelVersion modelVersion) throws Exception {
LegacyKernelServicesInitializer initializer = builder.createLegacyKernelServicesBuilder(null, controllerVersion, modelVersion);
String mavenGroupId = controllerVersion.getMavenGroupId();
String artifactId = "wildfly-connector";
if (controllerVersion.isEap() && controllerVersion.getMavenGavVersion().equals(controllerVersion.getCoreVersion())) { // EAP 6
artifactId = "jboss-as-connector";
}
initializer.addMavenResourceURL(mavenGroupId + ":" + artifactId + ":" + controllerVersion.getMavenGavVersion());
initializer.addMavenResourceURL("org.jboss.ironjacamar:ironjacamar-spec-api:1.0.28.Final")
.addMavenResourceURL("org.jboss.ironjacamar:ironjacamar-common-api:1.0.28.Final")
.setExtensionClassName("org.jboss.as.connector.subsystems.datasources.DataSourcesExtension")
.excludeFromParent(SingleClassFilter.createFilter(ConnectorLogger.class));
KernelServices mainServices = builder.build();
Assert.assertTrue(mainServices.isSuccessfulBoot());
KernelServices legacyServices = mainServices.getLegacyServices(modelVersion);
Assert.assertTrue(legacyServices.isSuccessfulBoot());
Assert.assertNotNull(legacyServices);
return mainServices;
}
/**
* Tests transformation of model from latest version into one passed into modelVersion parameter.
*
* @throws Exception
*/
private void testTransformer(String subsystemXml, ModelTestControllerVersion controllerVersion, final ModelVersion modelVersion) throws Exception {
//Use the non-runtime version of the extension which will happen on the HC
KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT);
KernelServices mainServices = initialKernelServices(builder, controllerVersion, modelVersion);
List<ModelNode> ops = builder.parseXmlResource(subsystemXml);
PathAddress subsystemAddress = PathAddress.pathAddress(DataSourcesSubsystemRootDefinition.PATH_SUBSYSTEM);
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, ops, new FailedOperationTransformationConfig()
.addFailedAttribute(subsystemAddress.append(DataSourceDefinition.PATH_DATASOURCE), new FailedOperationTransformationConfig.NewAttributesConfig(Constants.TRACKING))
.addFailedAttribute(subsystemAddress.append(XaDataSourceDefinition.PATH_XA_DATASOURCE), new FailedOperationTransformationConfig.NewAttributesConfig(Constants.TRACKING))
);
}
/**
* Tests transformation of model from latest version into one passed into modelVersion parameter.
*
* @throws Exception
*/
private void testTransformerElytronEnabled(String subsystemXml, ModelTestControllerVersion controllerVersion, final ModelVersion modelVersion) throws Exception {
//Use the non-runtime version of the extension which will happen on the HC
KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT);
KernelServices mainServices = initialKernelServices(builder, controllerVersion, modelVersion);
List<ModelNode> ops = builder.parseXmlResource(subsystemXml);
PathAddress subsystemAddress = PathAddress.pathAddress(DataSourcesSubsystemRootDefinition.PATH_SUBSYSTEM);
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, modelVersion, ops, new FailedOperationTransformationConfig()
.addFailedAttribute(subsystemAddress.append(DataSourceDefinition.PATH_DATASOURCE),
new FailedOperationTransformationConfig.NewAttributesConfig(Constants.TRACKING, Constants.ELYTRON_ENABLED, Constants.AUTHENTICATION_CONTEXT))
.addFailedAttribute(subsystemAddress.append(XaDataSourceDefinition.PATH_XA_DATASOURCE),
new FailedOperationTransformationConfig.NewAttributesConfig(Constants.TRACKING, Constants.ELYTRON_ENABLED, Constants.AUTHENTICATION_CONTEXT,
Constants.RECOVERY_ELYTRON_ENABLED, Constants.RECOVERY_AUTHENTICATION_CONTEXT) {
@Override
protected boolean isAttributeWritable(String attributeName) {
return false;
}
@Override
protected boolean checkValue(String attrName, ModelNode attribute, boolean isWriteAttribute) {
if (attribute.isDefined()) {
return true;
} else {
return false;
}
}
@Override
protected ModelNode correctValue(ModelNode toResolve, boolean isWriteAttribute) {
return new ModelNode();
}
})
);
}
/**
* Tests transformation of model from latest version which works well in EAP 7.0.0 without setting up FailedOperationTransformationConfig.
*
* @throws Exception
*/
private void testTransformerEAP7FullConfiguration(String subsystemXml) throws Exception {
ModelTestControllerVersion eap7ControllerVersion = ModelTestControllerVersion.EAP_7_0_0;
ModelVersion eap7ModelVersion = ModelVersion.create(4, 0, 0);
KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT);
KernelServices mainServices = initialKernelServices(builder, eap7ControllerVersion, eap7ModelVersion);
List<ModelNode> ops = builder.parseXmlResource(subsystemXml);
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, eap7ModelVersion, ops, FailedOperationTransformationConfig.NO_FAILURES);
}
/**
* Tests transformation of model from latest version which needs to be rejected in EAP 7.0.0
*
* @throws Exception
*/
private void testTransformerEAP7Rejection(String subsystemXml) throws Exception {
//Use the non-runtime version of the extension which will happen on the HC
ModelTestControllerVersion eap7ControllerVersion = ModelTestControllerVersion.EAP_7_0_0;
ModelVersion eap7ModelVersion = ModelVersion.create(4, 0, 0);
KernelServicesBuilder builder = createKernelServicesBuilder(AdditionalInitialization.MANAGEMENT);
KernelServices mainServices = initialKernelServices(builder, eap7ControllerVersion, eap7ModelVersion);
List<ModelNode> ops = builder.parseXmlResource(subsystemXml);
PathAddress subsystemAddress = PathAddress.pathAddress(DataSourcesSubsystemRootDefinition.PATH_SUBSYSTEM);
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, eap7ModelVersion, ops, new FailedOperationTransformationConfig()
.addFailedAttribute(subsystemAddress.append(DataSourceDefinition.PATH_DATASOURCE),
new RejectUndefinedAttribute(Constants.CONNECTION_URL.getName()))
);
}
private static class RejectUndefinedAttribute extends AttributesPathAddressConfig<RejectUndefinedAttribute> {
private RejectUndefinedAttribute(final String... attributes) {
super(attributes);
}
@Override
protected boolean isAttributeWritable(final String attributeName) {
return true;
}
@Override
protected boolean checkValue(final String attrName, final ModelNode attribute, final boolean isWriteAttribute) {
return !attribute.isDefined();
}
@Override
protected ModelNode correctValue(final ModelNode toResolve, final boolean isWriteAttribute) {
return null;
}
@Override
public boolean canCorrectMore(ModelNode operation) {
return false;
}
}
}