1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.hal.testsuite.configuration.datasource;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.jboss.arquillian.core.api.annotation.Inject;
22 import org.jboss.arquillian.graphene.page.Page;
23 import org.jboss.dmr.ModelNode;
24 import org.jboss.dmr.Property;
25 import org.jboss.hal.resources.Ids;
26 import org.jboss.hal.testsuite.Console;
27 import org.jboss.hal.testsuite.Random;
28 import org.jboss.hal.testsuite.container.WildFlyContainer;
29 import org.jboss.hal.testsuite.fragment.FormFragment;
30 import org.jboss.hal.testsuite.model.ResourceVerifier;
31 import org.jboss.hal.testsuite.page.configuration.DataSourcePage;
32 import org.jboss.hal.testsuite.test.Manatoko;
33 import org.junit.jupiter.api.BeforeAll;
34 import org.junit.jupiter.api.BeforeEach;
35 import org.junit.jupiter.api.Test;
36 import org.testcontainers.junit.jupiter.Container;
37 import org.testcontainers.junit.jupiter.Testcontainers;
38 import org.wildfly.extras.creaper.commands.datasources.AddXADataSource;
39 import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
40 import org.wildfly.extras.creaper.core.online.operations.Address;
41
42 import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
43 import static org.jboss.hal.dmr.ModelDescriptionConstants.VALUE;
44 import static org.jboss.hal.dmr.ModelDescriptionConstants.XA_DATASOURCE_PROPERTIES;
45 import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
46 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.URL_DELIMITER;
47 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.XA_DATA_SOURCE_UPDATE;
48 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.h2ConnectionUrl;
49 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.xaDataSourceAddress;
50
51 @Manatoko
52 @Testcontainers
53 class XADataSourceConfigurationTest {
54
55 @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
56 static OnlineManagementClient client;
57
58 @BeforeAll
59 static void setupModel() throws Exception {
60 client = wildFly.managementClient();
61 client.apply(new AddXADataSource.Builder<>(XA_DATA_SOURCE_UPDATE)
62 .driverName("h2")
63 .jndiName(Random.jndiName(XA_DATA_SOURCE_UPDATE))
64 .addXaDatasourceProperty("URL", h2ConnectionUrl(XA_DATA_SOURCE_UPDATE))
65 .build());
66 }
67
68 @Page DataSourcePage page;
69 @Inject Console console;
70 FormFragment form;
71
72 @BeforeEach
73 void prepare() {
74 Map<String, String> params = new HashMap<>();
75 params.put(NAME, XA_DATA_SOURCE_UPDATE);
76 params.put("xa", "true");
77 page.navigate(params);
78 }
79
80 @Test
81 void connectionAttributesProperties() throws Exception {
82 page.getXaTabs().select(Ids.build(Ids.XA_DATA_SOURCE, "connection", Ids.TAB));
83 form = page.getXaConnectionForm();
84
85 ModelNode properties = Random.properties();
86 String urlDelimiter = Random.name();
87
88
89
90 form.edit();
91 form.text(URL_DELIMITER, urlDelimiter);
92 form.properties(XA_DATASOURCE_PROPERTIES).removeTags();
93 form.properties(XA_DATASOURCE_PROPERTIES).add(properties);
94 form.save();
95
96 console.verifySuccess();
97 new ResourceVerifier(xaDataSourceAddress(XA_DATA_SOURCE_UPDATE), client)
98 .verifyAttribute(URL_DELIMITER, urlDelimiter);
99 for (Property key : properties.asPropertyList()) {
100 String value = key.getValue().asString();
101 Address address = xaDataSourceAddress(XA_DATA_SOURCE_UPDATE).and(XA_DATASOURCE_PROPERTIES, key.getName());
102 new ResourceVerifier(address, client).verifyAttribute(VALUE, value);
103 }
104 }
105
106 @Test
107 void connectionProperties() throws Exception {
108 page.getXaTabs().select(Ids.build(Ids.XA_DATA_SOURCE, "connection", Ids.TAB));
109 form = page.getXaConnectionForm();
110
111 ModelNode properties = Random.properties();
112
113 form.edit();
114 form.properties(XA_DATASOURCE_PROPERTIES).removeTags();
115 form.properties(XA_DATASOURCE_PROPERTIES).add(properties);
116 form.save();
117
118 console.verifySuccess();
119 for (Property key : properties.asPropertyList()) {
120 String value = key.getValue().asString();
121 Address address = xaDataSourceAddress(XA_DATA_SOURCE_UPDATE).and(XA_DATASOURCE_PROPERTIES, key.getName());
122 new ResourceVerifier(address, client).verifyAttribute(VALUE, value);
123 }
124 }
125
126 @Test
127 void connectionPropertiesSpecialCharacters() throws Exception {
128 page.getXaTabs().select(Ids.build(Ids.XA_DATA_SOURCE, "connection", Ids.TAB));
129 form = page.getXaConnectionForm();
130
131 ModelNode properties = new ModelNode();
132 properties.get("key1").set("jdbc:sybase:Tds:localhost:5000/mydatabase?JCONNECT_VERSION=6");
133 properties.get("key2").set("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MyDatabase");
134 properties.get("key3").set("jdbc:oracle:thin:@localhost:1521:orcalesid");
135 properties.get("key4").set("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
136 properties.get("key5")
137 .set("URL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=test)))");
138
139 form.edit();
140 form.properties(XA_DATASOURCE_PROPERTIES).removeTags();
141 form.properties(XA_DATASOURCE_PROPERTIES).add(properties);
142 form.save();
143
144 console.verifySuccess();
145 for (Property key : properties.asPropertyList()) {
146 String value = key.getValue().asString();
147 Address address = xaDataSourceAddress(XA_DATA_SOURCE_UPDATE)
148 .and(XA_DATASOURCE_PROPERTIES, key.getName());
149 new ResourceVerifier(address, client).verifyAttribute(VALUE, value);
150 }
151 }
152 }