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 org.jboss.arquillian.core.api.annotation.Inject;
19 import org.jboss.hal.meta.token.NameTokens;
20 import org.jboss.hal.resources.Ids;
21 import org.jboss.hal.resources.Names;
22 import org.jboss.hal.testsuite.Console;
23 import org.jboss.hal.testsuite.Random;
24 import org.jboss.hal.testsuite.container.WildFlyContainer;
25 import org.jboss.hal.testsuite.fragment.finder.ColumnFragment;
26 import org.jboss.hal.testsuite.model.Library;
27 import org.jboss.hal.testsuite.model.ResourceVerifier;
28 import org.jboss.hal.testsuite.page.Places;
29 import org.jboss.hal.testsuite.test.Manatoko;
30 import org.junit.jupiter.api.BeforeAll;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.testcontainers.junit.jupiter.Container;
34 import org.testcontainers.junit.jupiter.Testcontainers;
35 import org.wildfly.extras.creaper.commands.datasources.AddDataSource;
36 import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
37
38 import com.gwtplatform.mvp.shared.proxy.PlaceRequest;
39
40 import static org.jboss.hal.dmr.ModelDescriptionConstants.DATASOURCES;
41 import static org.jboss.hal.dmr.ModelDescriptionConstants.ENABLED;
42 import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
43 import static org.jboss.hal.resources.UIConstants.MEDIUM_TIMEOUT;
44 import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
45 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.DATA_SOURCE_DELETE;
46 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.DATA_SOURCE_DISABLE;
47 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.DATA_SOURCE_ENABLE;
48 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.DATA_SOURCE_READ;
49 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.DATA_SOURCE_TEST;
50 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.dataSourceAddress;
51 import static org.jboss.hal.testsuite.fixtures.DataSourceFixtures.h2ConnectionUrl;
52 import static org.jboss.hal.testsuite.fragment.finder.FinderFragment.configurationSubsystemPath;
53 import static org.junit.jupiter.api.Assertions.assertFalse;
54 import static org.junit.jupiter.api.Assertions.assertTrue;
55
56 @Manatoko
57 @Testcontainers
58 class DataSourceFinderTest {
59
60 @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
61 static final String H2_DRIVER_NAME = "h2";
62 static OnlineManagementClient client;
63
64 @BeforeAll
65 static void setupModel() throws Exception {
66 client = wildFly.managementClient();
67 client.apply(new AddDataSource.Builder<>(DATA_SOURCE_DELETE)
68 .driverName(H2_DRIVER_NAME)
69 .jndiName(Random.jndiName(DATA_SOURCE_DELETE))
70 .connectionUrl(h2ConnectionUrl(DATA_SOURCE_DELETE))
71 .build());
72 client.apply(new AddDataSource.Builder<>(DATA_SOURCE_DISABLE)
73 .driverName(H2_DRIVER_NAME)
74 .jndiName(Random.jndiName(DATA_SOURCE_DISABLE))
75 .connectionUrl(h2ConnectionUrl(DATA_SOURCE_DISABLE))
76 .enableAfterCreate()
77 .build());
78 client.apply(new AddDataSource.Builder<>(DATA_SOURCE_ENABLE)
79 .driverName(H2_DRIVER_NAME)
80 .jndiName(Random.jndiName(DATA_SOURCE_ENABLE))
81 .connectionUrl(h2ConnectionUrl(DATA_SOURCE_ENABLE))
82 .build());
83 client.apply(new AddDataSource.Builder<>(DATA_SOURCE_READ)
84 .driverName(H2_DRIVER_NAME)
85 .jndiName(Random.jndiName(DATA_SOURCE_READ))
86 .connectionUrl(h2ConnectionUrl(DATA_SOURCE_READ))
87 .build());
88 client.apply(new AddDataSource.Builder<>(DATA_SOURCE_TEST)
89 .driverName(H2_DRIVER_NAME)
90 .jndiName(Random.jndiName(DATA_SOURCE_TEST))
91 .connectionUrl(h2ConnectionUrl(DATA_SOURCE_TEST))
92 .enableAfterCreate()
93 .build());
94 }
95
96 @Inject Console console;
97 ColumnFragment column;
98
99 @BeforeEach
100 void prepare() {
101 column = console.finder(NameTokens.CONFIGURATION, configurationSubsystemPath(DATASOURCES)
102 .append(Ids.DATA_SOURCE_DRIVER, Ids.asId(Names.DATASOURCES)))
103 .column(Ids.DATA_SOURCE_CONFIGURATION);
104 }
105
106 @Test
107 void read() {
108 assertTrue(column.containsItem(Ids.dataSourceConfiguration(DATA_SOURCE_READ, false)));
109 }
110
111 @Test
112 void select() {
113 column.selectItem(Ids.dataSourceConfiguration(DATA_SOURCE_READ, false));
114 PlaceRequest placeRequest = Places.finderPlace(NameTokens.CONFIGURATION,
115 configurationSubsystemPath(DATASOURCES)
116 .append(Ids.DATA_SOURCE_DRIVER, Ids.asId(Names.DATASOURCES))
117 .append(Ids.DATA_SOURCE_CONFIGURATION, Ids.dataSourceConfiguration(DATA_SOURCE_READ, false)));
118 console.verify(placeRequest);
119 }
120
121 @Test
122 void view() {
123 column.selectItem(Ids.dataSourceConfiguration(DATA_SOURCE_READ, false))
124 .view();
125
126 PlaceRequest placeRequest = new PlaceRequest.Builder().nameToken(NameTokens.DATA_SOURCE_CONFIGURATION)
127 .with(NAME, DATA_SOURCE_READ)
128 .build();
129 console.verify(placeRequest);
130 }
131
132 @Test
133 void disable() throws Exception {
134 column.selectItem(Ids.dataSourceConfiguration(DATA_SOURCE_DISABLE, false))
135 .dropdown()
136 .click("Disable");
137
138 console.verifySuccess();
139 new ResourceVerifier(dataSourceAddress(DATA_SOURCE_DISABLE), client)
140 .verifyAttribute(ENABLED, false);
141 }
142
143 @Test
144 void enable() throws Exception {
145 column.selectItem(Ids.dataSourceConfiguration(DATA_SOURCE_ENABLE, false))
146 .dropdown()
147 .click("Enable");
148
149 console.verifySuccess();
150 new ResourceVerifier(dataSourceAddress(DATA_SOURCE_ENABLE), client)
151 .verifyAttribute(ENABLED, true);
152 }
153
154 @Test
155 void testConnection() {
156 column.selectItem(Ids.dataSourceConfiguration(DATA_SOURCE_TEST, false))
157 .dropdown()
158 .click("Test Connection");
159 console.verifySuccess();
160 }
161
162 @Test
163 void delete() throws Exception {
164 column.selectItem(Ids.dataSourceConfiguration(DATA_SOURCE_DELETE, false))
165 .dropdown()
166 .click("Remove");
167 console.confirmationDialog().confirm();
168
169 console.verifySuccess();
170 Library.letsSleep(MEDIUM_TIMEOUT);
171 assertFalse(column.containsItem(Ids.dataSourceConfiguration(DATA_SOURCE_DELETE, false)));
172 new ResourceVerifier(dataSourceAddress(DATA_SOURCE_DELETE), client)
173 .verifyDoesNotExist();
174 }
175 }