1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.hal.testsuite.test.configuration.web;
17
18 import org.jboss.arquillian.core.api.annotation.Inject;
19 import org.jboss.arquillian.graphene.findby.ByJQuery;
20 import org.jboss.arquillian.graphene.page.Page;
21 import org.jboss.hal.testsuite.CrudOperations;
22 import org.jboss.hal.testsuite.Random;
23 import org.jboss.hal.testsuite.container.WildFlyContainer;
24 import org.jboss.hal.testsuite.fixtures.WebFixtures;
25 import org.jboss.hal.testsuite.page.configuration.UndertowPage;
26 import org.jboss.hal.testsuite.test.Manatoko;
27 import org.junit.jupiter.api.BeforeAll;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.testcontainers.junit.jupiter.Container;
31 import org.testcontainers.junit.jupiter.Testcontainers;
32 import org.wildfly.extras.creaper.core.online.operations.Address;
33 import org.wildfly.extras.creaper.core.online.operations.Operations;
34 import org.wildfly.extras.creaper.core.online.operations.Values;
35
36 import static org.jboss.hal.dmr.ModelDescriptionConstants.DEFAULT_HOST;
37 import static org.jboss.hal.dmr.ModelDescriptionConstants.DEFAULT_SECURITY_DOMAIN;
38 import static org.jboss.hal.dmr.ModelDescriptionConstants.DEFAULT_WEB_MODULE;
39 import static org.jboss.hal.dmr.ModelDescriptionConstants.INSTANCE_ID;
40 import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
41 import static org.jboss.hal.dmr.ModelDescriptionConstants.RESOLVE_EXPRESSIONS;
42 import static org.jboss.hal.dmr.ModelDescriptionConstants.STATISTICS_ENABLED;
43 import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
44 import static org.jboss.hal.testsuite.fixtures.WebFixtures.DEFAULT_SERVER;
45 import static org.jboss.hal.testsuite.fixtures.WebFixtures.DEFAULT_SERVER_CREATE;
46 import static org.jboss.hal.testsuite.fixtures.WebFixtures.DEFAULT_SERVLET_CONTAINER;
47 import static org.jboss.hal.testsuite.fixtures.WebFixtures.DEFAULT_SERVLET_CONTAINER_CREATE;
48 import static org.jboss.hal.testsuite.fixtures.WebFixtures.DEFAULT_VIRTUAL_HOST;
49 import static org.jboss.hal.testsuite.fixtures.WebFixtures.DEFAULT_VIRTUAL_HOST_CREATE;
50 import static org.jboss.hal.testsuite.fixtures.WebFixtures.UNDERTOW_ADDRESS;
51 import static org.jboss.hal.testsuite.fixtures.WebFixtures.servletContainerAddress;
52 import static org.jboss.hal.testsuite.fixtures.WebFixtures.virtualHostAddress;
53
54 @Manatoko
55 @Testcontainers
56 class GlobalSettingsTest {
57
58 @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
59 static Operations operations;
60
61 @BeforeAll
62 static void setupModel() throws Exception {
63 operations = new Operations(wildFly.managementClient());
64 Address serverAddress = WebFixtures.serverAddress(DEFAULT_SERVER_CREATE);
65 operations.add(serverAddress);
66 operations.add(servletContainerAddress(DEFAULT_SERVLET_CONTAINER_CREATE));
67 operations.add(virtualHostAddress(DEFAULT_SERVER_CREATE, DEFAULT_VIRTUAL_HOST_CREATE),
68 Values.of(DEFAULT_WEB_MODULE, "module_" + Random.name(7) + ".war"));
69 operations.writeAttribute(serverAddress, DEFAULT_HOST, DEFAULT_VIRTUAL_HOST_CREATE);
70 }
71
72 @Inject CrudOperations crudOperations;
73 @Page UndertowPage page;
74
75 @BeforeEach
76 void prepare() {
77 page.navigate();
78 }
79
80 @Test
81 public void updateDefaultSecurityDomain() throws Exception {
82 crudOperations.update(UNDERTOW_ADDRESS, page.getConfigurationForm(), DEFAULT_SECURITY_DOMAIN);
83 }
84
85 @Test
86 public void updateDefaultServer() throws Exception {
87 crudOperations.update(UNDERTOW_ADDRESS, page.getConfigurationForm(), DEFAULT_SERVER, DEFAULT_SERVER_CREATE);
88 }
89
90 @Test
91 public void updateDefaultServletContainer() throws Exception {
92 crudOperations.update(UNDERTOW_ADDRESS, page.getConfigurationForm(), DEFAULT_SERVLET_CONTAINER,
93 DEFAULT_SERVLET_CONTAINER_CREATE);
94 }
95
96 @Test
97 public void updateDefaultVirtualHost() throws Exception {
98 crudOperations.update(UNDERTOW_ADDRESS, page.getConfigurationForm(),
99 consumer -> {
100 consumer.text(DEFAULT_SERVER, DEFAULT_SERVER_CREATE);
101 consumer.text(DEFAULT_VIRTUAL_HOST, DEFAULT_VIRTUAL_HOST_CREATE);
102 }, resourceVerifier -> resourceVerifier.verifyAttribute(DEFAULT_VIRTUAL_HOST,
103 DEFAULT_VIRTUAL_HOST_CREATE));
104 }
105
106 @Test
107 public void updateInstanceId() throws Exception {
108 crudOperations.update(UNDERTOW_ADDRESS, page.getConfigurationForm(), INSTANCE_ID);
109 }
110
111 @Test
112 public void toggleStatisticsEnabled() throws Exception {
113 boolean statisticsEnabled = operations.invoke("read-attribute", UNDERTOW_ADDRESS,
114 Values.of(NAME, STATISTICS_ENABLED).and(RESOLVE_EXPRESSIONS, true)).booleanValue();
115 crudOperations.update(UNDERTOW_ADDRESS, page.getConfigurationForm(),
116 form -> {
117 form.getRoot().findElement(ByJQuery.selector("button[title=\"Switch to normal mode\"]")).click();
118 form.flip(STATISTICS_ENABLED, !statisticsEnabled);
119 }, resourceVerifier -> resourceVerifier.verifyAttribute(STATISTICS_ENABLED, !statisticsEnabled));
120 }
121 }