forked from wildfly/wildfly
/
DataSourceOperationsUnitTestCase.java
792 lines (570 loc) · 28.7 KB
/
DataSourceOperationsUnitTestCase.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/*
* JBoss, Home of Professional Open Source.
* Copyright 2011, Red Hat, Inc., 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.test.smoke.mgmt.datasource;
import java.util.List;
import java.util.Properties;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import junit.framework.Assert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.test.integration.management.jca.DsMgmtTestBase;
import org.jboss.as.test.smoke.modular.utils.PollingUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ALLOW_RESOURCE_SERVICE_RESTART;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.addExtensionProperties;
import static org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.checkModelParams;
import static org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.nonXaDsProperties;
import static org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.setOperationParams;
import static org.jboss.as.test.integration.management.jca.ComplexPropertiesParseUtils.xaDsProperties;
/**
* Datasource operation unit test.
*
* @author <a href="mailto:stefano.maestri@redhat.com">Stefano Maestri</a>
* @author <a href="mailto:jeff.zhang@jboss.org">Jeff Zhang</a>
* @author <a href="mailto:vrastsel@redhat.com">Vladimir Rastseluev</a>
*/
@RunWith(Arquillian.class)
@RunAsClient
public class DataSourceOperationsUnitTestCase extends DsMgmtTestBase {
@Deployment
public static Archive<?> fakeDeployment() {
return ShrinkWrap.create(JavaArchive.class);
}
@Test
public void testAddDsAndTestConnection() throws Exception {
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", "MyNewDs");
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set("MyNewDs");
operation.get("jndi-name").set("java:jboss/datasources/MyNewDs");
operation.get("driver-name").set("h2");
operation.get("pool-name").set("MyNewDs_Pool");
operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
testConnection("MyNewDs");
List<ModelNode> newList = marshalAndReparseDsResources("data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
Assert.assertNotNull(findNodeWithProperty(newList, "jndi-name", "java:jboss/datasources/MyNewDs"));
}
/**
* AS7-1202 test for enable datasource
*
* @throws Exception
*/
@Test
public void testAddDisabledDsEnableItAndTestConnection() throws Exception {
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", "MyNewDs");
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set("MyNewDs");
operation.get("jndi-name").set("java:jboss/datasources/MyNewDs");
operation.get("driver-name").set("h2");
operation.get("pool-name").set("MyNewDs_Pool");
operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
testConnection("MyNewDs");
List<ModelNode> newList = marshalAndReparseDsResources("data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
Assert.assertNotNull(findNodeWithProperty(newList, "jndi-name", "java:jboss/datasources/MyNewDs"));
}
@Test
public void testAddDsWithConnectionProperties() throws Exception {
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", "MyNewDs");
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set("MyNewDs");
operation.get("jndi-name").set("java:jboss/datasources/MyNewDs");
operation.get("driver-name").set("h2");
operation.get("pool-name").set("MyNewDs_Pool");
operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
final ModelNode connectionPropertyAddress = address.clone();
connectionPropertyAddress.add("connection-properties", "MyKey");
connectionPropertyAddress.protect();
final ModelNode connectionPropertyOperation = new ModelNode();
connectionPropertyOperation.get(OP).set("add");
connectionPropertyOperation.get(OP_ADDR).set(connectionPropertyAddress);
connectionPropertyOperation.get("value").set("MyValue");
executeOperation(connectionPropertyOperation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
List<ModelNode> newList = marshalAndReparseDsResources("data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
Assert.assertNotNull(findNodeWithProperty(newList, "jndi-name", "java:jboss/datasources/MyNewDs"));
}
@Test
public void testAddAndRemoveSameName() throws Exception {
final String dsName = "SameNameDs";
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", dsName);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(dsName);
operation.get("jndi-name").set("java:jboss/datasources/" + dsName);
operation.get("driver-name").set("h2");
operation.get("pool-name").set(dsName + "_Pool");
operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
// do twice, test for AS7-720
for (int i = 1; i <= 2; i++) {
executeOperation(operation);
remove(address);
}
}
/**
* AS7-1206 test for jndi binding isn't unbound during remove if jndi name
* and data-source name are different
*
* @throws Exception
*/
@Test
public void testAddAndRemoveNameAndJndiNameDifferent() throws Exception {
final String dsName = "DsName";
final String jndiDsName = "JndiDsName";
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", dsName);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(dsName);
operation.get("jndi-name").set("java:jboss/datasources/" + jndiDsName);
operation.get("driver-name").set("h2");
operation.get("pool-name").set(dsName + "_Pool");
operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
remove(address);
}
@Test
public void testAddAndRemoveXaDs() throws Exception {
final String dsName = "XaDsName";
final String jndiDsName = "XaJndiDsName";
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("xa-data-source", dsName);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(dsName);
operation.get("jndi-name").set("java:jboss/datasources/" + jndiDsName);
operation.get("driver-name").set("h2");
operation.get("pool-name").set(dsName + "_Pool");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
final ModelNode xaDatasourcePropertiesAddress = address.clone();
xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
xaDatasourcePropertiesAddress.protect();
final ModelNode xaDatasourcePropertyOperation = new ModelNode();
xaDatasourcePropertyOperation.get(OP).set("add");
xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");
executeOperation(xaDatasourcePropertyOperation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
testConnectionXA(dsName);
remove(address);
}
/**
* AS7-1200 test case for xa datasource persistence to xml
*
* @throws Exception
*/
@Test
public void testMarshallUnmarshallXaDs() throws Exception {
final String dsName = "XaDsName2";
final String jndiDsName = "XaJndiDsName2";
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("xa-data-source", dsName);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(dsName);
operation.get("jndi-name").set("java:jboss/datasources/" + jndiDsName);
operation.get("driver-name").set("h2");
operation.get("pool-name").set(dsName + "_Pool");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
final ModelNode xaDatasourcePropertiesAddress = address.clone();
xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
xaDatasourcePropertiesAddress.protect();
final ModelNode xaDatasourcePropertyOperation = new ModelNode();
xaDatasourcePropertyOperation.get(OP).set("add");
xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");
executeOperation(xaDatasourcePropertyOperation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
List<ModelNode> newList = marshalAndReparseDsResources("xa-data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
// remove from xml too
marshalAndReparseDsResources("xa-data-source");
Assert.assertNotNull(findNodeWithProperty(newList, "jndi-name", "java:jboss/datasources/" + jndiDsName));
}
/**
* AS7-1201 test for en/diable xa datasources
* <p/>
* DO NOT RE-ENABLE THIS TEST WITHOUT ACTUALLY FIXING THE PROBLEM
* <p/>
* It fails INTERMITTENTLY. This means that it is not enough to just run it once, decide it passes and submit it.
*
* @throws Exception
*/
@Test
public void disableAndReEnableXaDs() throws Exception {
final String dsName = "XaDsNameDisEn";
final String jndiDsName = "XaJndiDsNameDisEn";
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("xa-data-source", dsName);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(dsName);
operation.get("jndi-name").set("java:jboss/datasources/" + jndiDsName);
operation.get("driver-name").set("h2");
operation.get("pool-name").set(dsName + "_Pool");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
final ModelNode enableOperation = new ModelNode();
enableOperation.get(OP).set("enable");
enableOperation.get(OP_ADDR).set(address);
final ModelNode disableOperation = new ModelNode();
disableOperation.get(OPERATION_HEADERS).get(ALLOW_RESOURCE_SERVICE_RESTART).set(true);
disableOperation.get(OP).set("disable");
disableOperation.get(OP_ADDR).set(address);
executeOperation(operation);
final ModelNode xaDatasourcePropertiesAddress = address.clone();
xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
xaDatasourcePropertiesAddress.protect();
final ModelNode xaDatasourcePropertyOperation = new ModelNode();
xaDatasourcePropertyOperation.get(OP).set("add");
xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");
executeOperation(xaDatasourcePropertyOperation);
executeOperation(enableOperation);
testConnectionXA(dsName);
executeOperation(disableOperation);
executeOperation(enableOperation);
testConnectionXA(dsName);
remove(address);
}
@Test
public void testReadInstalledDrivers() throws Exception {
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("installed-drivers-list");
operation.get(OP_ADDR).set(address);
final ModelNode result = executeOperation(operation);
final ModelNode result2 = result.get(0);
Assert.assertNotNull("There are no installed JDBC drivers", result2);
Assert.assertTrue("Name of JDBC driver is udefined", result2.hasDefined("driver-name"));
if (!result2.hasDefined("deployment-name")) {//deployed drivers haven't these attributes
Assert.assertTrue("Module name of JDBC driver is udefined", result2.hasDefined("driver-module-name"));
Assert.assertTrue("Module slot of JDBC driver is udefined", result2.hasDefined("module-slot"));
}
}
/**
* AS7-1203 test for missing xa-datasource properties
*
* @throws Exception
*/
@Test
public void testAddXaDsWithProperties() throws Exception {
final String xaDs = "MyNewXaDs";
final String xaDsJndi = "java:jboss/xa-datasources/" + xaDs;
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("xa-data-source", xaDs);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(xaDs);
operation.get("jndi-name").set(xaDsJndi);
operation.get("driver-name").set("h2");
operation.get("xa-datasource-class").set("org.jboss.as.connector.subsystems.datasources.ModifiableXaDataSource");
operation.get("pool-name").set(xaDs + "_Pool");
operation.get("user-name").set("sa");
operation.get("password").set("sa");
executeOperation(operation);
final ModelNode xaDatasourcePropertiesAddress = address.clone();
xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
xaDatasourcePropertiesAddress.protect();
final ModelNode xaDatasourcePropertyOperation = new ModelNode();
xaDatasourcePropertyOperation.get(OP).set("add");
xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");
executeOperation(xaDatasourcePropertyOperation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
List<ModelNode> newList = marshalAndReparseDsResources("xa-data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
try {
ModifiableXaDataSource jxaDS = lookup(getModelControllerClient(), xaDsJndi, ModifiableXaDataSource.class);
Assert.fail("found datasource after it was unbounded");
} catch (Exception e) {
// must be thrown NameNotFound exception - datasource is unbounded
}
Assert.assertNotNull(findNodeWithProperty(newList, "jndi-name", xaDsJndi));
}
/**
* AS7-2720 tests for parsing particular datasource in standalone mode
*
* @throws Exception
*/
@Test
public void testAddComplexDs() throws Exception {
final String complexDs = "complexDs";
final String complexDsJndi = "java:jboss/datasources/" + complexDs;
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", complexDs);
address.protect();
Properties params = nonXaDsProperties(complexDsJndi);
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
setOperationParams(operation, params);
addExtensionProperties(operation);
executeOperation(operation);
final ModelNode datasourcePropertiesAddress = address.clone();
datasourcePropertiesAddress.add("connection-properties", "char.encoding");
datasourcePropertiesAddress.protect();
final ModelNode datasourcePropertyOperation = new ModelNode();
datasourcePropertyOperation.get(OP).set("add");
datasourcePropertyOperation.get(OP_ADDR).set(datasourcePropertiesAddress);
datasourcePropertyOperation.get("value").set("UTF-8");
executeOperation(datasourcePropertyOperation);
List<ModelNode> newList = marshalAndReparseDsResources("data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
ModelNode rightChild = findNodeWithProperty(newList, "jndi-name", complexDsJndi);
Assert.assertTrue("node:" + rightChild.asString() + ";\nparams" + params, checkModelParams(rightChild, params));
Assert.assertEquals(rightChild.asString(), "Property2", rightChild.get("valid-connection-checker-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property4", rightChild.get("exception-sorter-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property3", rightChild.get("stale-connection-checker-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property1", rightChild.get("reauth-plugin-properties", "name").asString());
Assert.assertNotNull("connection-properties not propagated ", findNodeWithProperty(newList, "value", "UTF-8"));
}
/**
* AS7-2720 tests for parsing particular XA-datasource in standalone mode
*
* @throws Exception
*/
@Test
public void testAddComplexXaDs() throws Exception {
final String complexXaDs = "complexXaDs";
final String complexXaDsJndi = "java:jboss/xa-datasources/" + complexXaDs;
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("xa-data-source", complexXaDs);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
Properties params = xaDsProperties(complexXaDsJndi);
setOperationParams(operation, params);
addExtensionProperties(operation);
operation.get("recovery-plugin-properties", "name").set("Property5");
operation.get("recovery-plugin-properties", "name1").set("Property6");
executeOperation(operation);
final ModelNode xaDatasourcePropertiesAddress = address.clone();
xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
xaDatasourcePropertiesAddress.protect();
final ModelNode xaDatasourcePropertyOperation = new ModelNode();
xaDatasourcePropertyOperation.get(OP).set("add");
xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");
executeOperation(xaDatasourcePropertyOperation);
List<ModelNode> newList = marshalAndReparseDsResources("xa-data-source");
remove(address);
Assert.assertNotNull("Reparsing failed:", newList);
ModelNode rightChild = findNodeWithProperty(newList, "jndi-name", complexXaDsJndi);
Assert.assertTrue("node:" + rightChild.asString() + ";\nparams" + params, checkModelParams(rightChild, params));
Assert.assertEquals(rightChild.asString(), "Property2", rightChild.get("valid-connection-checker-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property4", rightChild.get("exception-sorter-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property3", rightChild.get("stale-connection-checker-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property1", rightChild.get("reauth-plugin-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property5", rightChild.get("recovery-plugin-properties", "name").asString());
Assert.assertEquals(rightChild.asString(), "Property6", rightChild.get("recovery-plugin-properties", "name1").asString());
Assert.assertNotNull("xa-datasource-properties not propagated ", findNodeWithProperty(newList, "value", "jdbc:h2:mem:test"));
}
@Test
public void testXaDsWithSystemProperties() throws Exception {
final ModelNode propAddress = new ModelNode();
propAddress.add("system-property", "sql.parameter");
propAddress.protect();
final ModelNode propOperation = new ModelNode();
propOperation.get(OP).set("add");
propOperation.get(OP_ADDR).set(propAddress);
propOperation.get("value").set("sa");
executeOperation(propOperation);
final String dsName = "XaDsName2";
final String jndiDsName = "XaJndiDsName2";
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("xa-data-source", dsName);
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set(dsName);
operation.get("jndi-name").set("java:jboss/datasources/" + jndiDsName);
operation.get("driver-name").set("h2");
operation.get("pool-name").set(dsName + "_Pool");
operation.get("user-name").set("${sql.parameter}");
operation.get("password").set("${sql.parameter}");
executeOperation(operation);
final ModelNode xaDatasourcePropertiesAddress = address.clone();
xaDatasourcePropertiesAddress.add("xa-datasource-properties", "URL");
xaDatasourcePropertiesAddress.protect();
final ModelNode xaDatasourcePropertyOperation = new ModelNode();
xaDatasourcePropertyOperation.get(OP).set("add");
xaDatasourcePropertyOperation.get(OP_ADDR).set(xaDatasourcePropertiesAddress);
xaDatasourcePropertyOperation.get("value").set("jdbc:h2:mem:test");
executeOperation(xaDatasourcePropertyOperation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
testConnectionXA(dsName);
remove(address);
remove(propAddress);
}
/**
* test case for AS7-3316 issue - datasource with system properties
*
* @throws Exception
*/
@Test
public void testDsWithSystemProperties() throws Exception {
final ModelNode propAddress = new ModelNode();
propAddress.add("system-property", "sql.parameter");
propAddress.protect();
final ModelNode propOperation = new ModelNode();
propOperation.get(OP).set("add");
propOperation.get(OP_ADDR).set(propAddress);
propOperation.get("value").set("sa");
executeOperation(propOperation);
final ModelNode address = new ModelNode();
address.add("subsystem", "datasources");
address.add("data-source", "MyNewDs");
address.protect();
final ModelNode operation = new ModelNode();
operation.get(OP).set("add");
operation.get(OP_ADDR).set(address);
operation.get("name").set("MyNewDs");
operation.get("jndi-name").set("java:jboss/datasources/MyNewDs");
operation.get("driver-name").set("h2");
operation.get("pool-name").set("MyNewDs_Pool");
operation.get("connection-url").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
operation.get("user-name").set("${sql.parameter}");
operation.get("password").set("${sql.parameter}");
executeOperation(operation);
final ModelNode operation2 = new ModelNode();
operation2.get(OP).set("enable");
operation2.get(OP_ADDR).set(address);
executeOperation(operation2);
testConnection("MyNewDs");
remove(address);
remove(propAddress);
}
private static <T> T lookup(ModelControllerClient client, String name, Class<T> expected) throws Exception {
//TODO Don't do this FakeJndi stuff once we have remote JNDI working
MBeanServerConnection mbeanServer = JMXConnectorFactory.connect(new JMXServiceURL("service:jmx:remoting-jmx://127.0.0.1:9999")).getMBeanServerConnection();
ObjectName objectName = new ObjectName("jboss:name=test,type=fakejndi");
PollingUtils.retryWithTimeout(10000, new PollingUtils.WaitForMBeanTask(mbeanServer, objectName));
Object o = mbeanServer.invoke(objectName, "lookup", new Object[]{name}, new String[]{"java.lang.String"});
return expected.cast(o);
}
}