1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.hal.testsuite.test.configuration.resourceadapter;
17
18 import java.util.List;
19
20 import org.jboss.arquillian.core.api.annotation.Inject;
21 import org.jboss.arquillian.graphene.page.Page;
22 import org.jboss.dmr.ModelNode;
23 import org.jboss.hal.testsuite.Console;
24 import org.jboss.hal.testsuite.CrudOperations;
25 import org.jboss.hal.testsuite.Random;
26 import org.jboss.hal.testsuite.container.WildFlyContainer;
27 import org.jboss.hal.testsuite.model.ResourceVerifier;
28 import org.jboss.hal.testsuite.page.configuration.ResourceAdapterPage;
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.core.online.OnlineManagementClient;
36 import org.wildfly.extras.creaper.core.online.operations.Operations;
37 import org.wildfly.extras.creaper.core.online.operations.Values;
38
39 import static org.jboss.hal.dmr.ModelDescriptionConstants.ARCHIVE;
40 import static org.jboss.hal.dmr.ModelDescriptionConstants.CONFIG_PROPERTIES;
41 import static org.jboss.hal.dmr.ModelDescriptionConstants.FROM;
42 import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
43 import static org.jboss.hal.dmr.ModelDescriptionConstants.STATISTICS_ENABLED;
44 import static org.jboss.hal.dmr.ModelDescriptionConstants.TO;
45 import static org.jboss.hal.dmr.ModelDescriptionConstants.TRANSACTION_SUPPORT;
46 import static org.jboss.hal.dmr.ModelDescriptionConstants.VALUE;
47 import static org.jboss.hal.dmr.ModelDescriptionConstants.WM_SECURITY_MAPPING_GROUPS;
48 import static org.jboss.hal.dmr.ModelDescriptionConstants.WM_SECURITY_MAPPING_USERS;
49 import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
50 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.BEANVALIDATIONGROUPS;
51 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.BOOTSTRAP_CONTEXT;
52 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.LOCAL_TRANSACTION;
53 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.RESOURCE_ADAPTER_UPDATE;
54 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.WM_SECURITY;
55 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.WM_SECURITY_DEFAULT_GROUPS;
56 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.WM_SECURITY_DEFAULT_PRINCIPAL;
57 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.WM_SECURITY_MAPPING_REQUIRED;
58 import static org.jboss.hal.testsuite.fixtures.ResourceAdapterFixtures.resourceAdapterAddress;
59
60 @Manatoko
61 @Testcontainers
62 class ResourceAdapterConfigurationTest {
63
64 @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
65 private static OnlineManagementClient client;
66
67 @BeforeAll
68 static void setupModel() throws Exception {
69 client = wildFly.managementClient();
70 Operations operations = new Operations(client);
71 operations.add(resourceAdapterAddress(RESOURCE_ADAPTER_UPDATE), Values.of(ARCHIVE, Random.name()));
72 }
73
74 @Inject Console console;
75 @Inject CrudOperations crud;
76 @Page ResourceAdapterPage page;
77
78 @BeforeEach
79 void setUp() {
80 page.navigate(NAME, RESOURCE_ADAPTER_UPDATE);
81 console.verticalNavigation().selectPrimary("resource-adapter-configuration-item");
82 }
83
84 @Test
85 void updateAttributes() throws Exception {
86 page.getConfigurationTabs().select("resource-adapter-configuration-attributes-tab");
87
88 List<String> groups = Random.list();
89 String bootstrapContext = Random.name();
90 ModelNode configProperties = Random.properties("foo", "bar");
91
92 crud.update(resourceAdapterAddress(RESOURCE_ADAPTER_UPDATE), page.getAttributesForm(),
93 form -> {
94 form.list(BEANVALIDATIONGROUPS).add(groups);
95 form.text(BOOTSTRAP_CONTEXT, bootstrapContext);
96 form.flip(STATISTICS_ENABLED, true);
97 form.select(TRANSACTION_SUPPORT, "LocalTransaction");
98 form.properties(CONFIG_PROPERTIES).add(configProperties);
99 },
100 resourceVerifier -> {
101 for (String group : groups) {
102 resourceVerifier.verifyListAttributeContainsValue(BEANVALIDATIONGROUPS, group);
103 }
104 resourceVerifier.verifyAttribute(BOOTSTRAP_CONTEXT, bootstrapContext);
105 resourceVerifier.verifyAttribute(STATISTICS_ENABLED, true);
106 resourceVerifier.verifyAttribute(TRANSACTION_SUPPORT, LOCAL_TRANSACTION);
107
108 ResourceVerifier propertyVerifier = new ResourceVerifier(
109 resourceAdapterAddress(RESOURCE_ADAPTER_UPDATE).and(CONFIG_PROPERTIES, "foo"), client);
110 propertyVerifier.verifyAttribute(VALUE, "bar");
111 });
112 }
113
114 @Test
115 void updateWmSecurity() throws Exception {
116 page.getConfigurationTabs().select("resource-adapter-configuration-wm-security-tab");
117
118 List<String> defaultGroups = Random.list();
119 String defaultPrincipal = Random.name();
120
121 crud.update(resourceAdapterAddress(RESOURCE_ADAPTER_UPDATE), page.getWmSecurityForm(),
122 form -> {
123 form.flip(WM_SECURITY, true);
124 form.list(WM_SECURITY_DEFAULT_GROUPS).add(defaultGroups);
125 form.text(WM_SECURITY_DEFAULT_PRINCIPAL, defaultPrincipal);
126 form.flip(WM_SECURITY_MAPPING_REQUIRED, true);
127 form.properties(WM_SECURITY_MAPPING_GROUPS).add(Random.properties("group", "admin"));
128 form.properties(WM_SECURITY_MAPPING_USERS).add(Random.properties("user", "john"));
129 },
130 resourceVerifier -> {
131 resourceVerifier.verifyAttribute(WM_SECURITY, true);
132 for (String group : defaultGroups) {
133 resourceVerifier.verifyListAttributeContainsValue(WM_SECURITY_DEFAULT_GROUPS, group);
134 }
135 resourceVerifier.verifyAttribute(WM_SECURITY_DEFAULT_PRINCIPAL, defaultPrincipal);
136 resourceVerifier.verifyAttribute(WM_SECURITY_MAPPING_REQUIRED, true);
137 resourceVerifier.verifyAttribute(WM_SECURITY_MAPPING_GROUPS, mappings("group", "admin"));
138 resourceVerifier.verifyAttribute(WM_SECURITY_MAPPING_USERS, mappings("user", "john"));
139 });
140 }
141
142 private ModelNode mappings(String from, String to) {
143 ModelNode mapping = new ModelNode();
144 mapping.get(FROM).set(from);
145 mapping.get(TO).set(to);
146 ModelNode mappings = new ModelNode();
147 mappings.add(mapping);
148 return mappings;
149 }
150 }