View Javadoc
1   /*
2    *  Copyright 2022 Red Hat
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.jboss.hal.testsuite.test.configuration.distributableweb;
17  
18  import org.jboss.arquillian.core.api.annotation.Inject;
19  import org.jboss.arquillian.graphene.page.Page;
20  import org.jboss.hal.testsuite.Console;
21  import org.jboss.hal.testsuite.CrudOperations;
22  import org.jboss.hal.testsuite.container.WildFlyContainer;
23  import org.jboss.hal.testsuite.fragment.FormFragment;
24  import org.jboss.hal.testsuite.fragment.SelectFragment;
25  import org.jboss.hal.testsuite.fragment.TableFragment;
26  import org.jboss.hal.testsuite.model.ResourceVerifier;
27  import org.jboss.hal.testsuite.page.configuration.DistributableWebPage;
28  import org.jboss.hal.testsuite.test.Manatoko;
29  import org.junit.jupiter.api.BeforeAll;
30  import org.junit.jupiter.api.BeforeEach;
31  import org.junit.jupiter.api.Test;
32  import org.testcontainers.junit.jupiter.Container;
33  import org.testcontainers.junit.jupiter.Testcontainers;
34  import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
35  import org.wildfly.extras.creaper.core.online.operations.Operations;
36  import org.wildfly.extras.creaper.core.online.operations.Values;
37  
38  import static org.jboss.hal.dmr.ModelDescriptionConstants.AFFINITY;
39  import static org.jboss.hal.dmr.ModelDescriptionConstants.CACHE_CONTAINER;
40  import static org.jboss.hal.dmr.ModelDescriptionConstants.INFINISPAN;
41  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
42  import static org.jboss.hal.dmr.ModelDescriptionConstants.RANKED;
43  import static org.jboss.hal.dmr.ModelDescriptionConstants.ROUTING;
44  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.FULL;
45  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.ATTRIBUTE;
46  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.GRANULARITY;
47  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.INFINISPAN_SESSION_AFFINITY;
48  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.INFINISPAN_SESSION_CREATE;
49  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.INFINISPAN_SESSION_DELETE;
50  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.INFINISPAN_SESSION_UPDATE;
51  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.SESSION;
52  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.SUBSYSTEM_ADDRESS;
53  import static org.jboss.hal.testsuite.fixtures.DistributableWebFixtures.infinispanSessionAddress;
54  import static org.jboss.hal.testsuite.fixtures.InfinispanFixtures.CC_CREATE;
55  import static org.jboss.hal.testsuite.test.configuration.distributableweb.DistributableWebOperations.addCacheContainer;
56  import static org.junit.jupiter.api.Assertions.fail;
57  
58  @Manatoko
59  @Testcontainers
60  class InfinispanSessionTest {
61  
62      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(FULL);
63      private static OnlineManagementClient client;
64  
65      @BeforeAll
66      static void setupModel() throws Exception {
67          client = wildFly.managementClient();
68          Operations operations = new Operations(client);
69          addCacheContainer(client, operations, CC_CREATE);
70          Values values = Values.of(CACHE_CONTAINER, CC_CREATE).and(GRANULARITY, SESSION);
71          operations.add(SUBSYSTEM_ADDRESS.and(ROUTING, INFINISPAN), Values.of(CACHE_CONTAINER, CC_CREATE)).assertSuccess();
72          operations.add(infinispanSessionAddress(INFINISPAN_SESSION_UPDATE), values).assertSuccess();
73          operations.add(infinispanSessionAddress(INFINISPAN_SESSION_AFFINITY), values).assertSuccess();
74          operations.add(infinispanSessionAddress(INFINISPAN_SESSION_DELETE), values).assertSuccess();
75      }
76  
77      @Page DistributableWebPage page;
78      @Inject CrudOperations crud;
79      @Inject Console console;
80      TableFragment table;
81      FormFragment form;
82  
83      @BeforeEach
84      void setUp() {
85          page.navigate();
86          console.verticalNavigation().selectPrimary("dw-infinispan-session-management-item");
87          table = page.getInfinispanSessionManagementTable();
88          form = page.getInfinispanSessionManagementForm();
89          table.bind(form);
90      }
91  
92      @Test
93      void create() throws Exception {
94          crud.create(infinispanSessionAddress(INFINISPAN_SESSION_CREATE), table, f -> {
95              f.text(NAME, INFINISPAN_SESSION_CREATE);
96              f.text(CACHE_CONTAINER, CC_CREATE);
97          });
98      }
99  
100     @Test
101     void update() throws Exception {
102         table.select(INFINISPAN_SESSION_UPDATE);
103         crud.update(infinispanSessionAddress(INFINISPAN_SESSION_UPDATE), form,
104                 f -> f.select(GRANULARITY, ATTRIBUTE),
105                 verifier -> verifier.verifyAttribute(GRANULARITY, ATTRIBUTE));
106     }
107 
108     @Test
109     void switchAffinity() throws Exception {
110         table.select(INFINISPAN_SESSION_AFFINITY);
111         page.getInfinispanSessionManagementTabs().select("dw-infinispan-session-management-affinity-tab");
112         SelectFragment select = page.getSwitchAffinity();
113         if (select != null) {
114             select.select(RANKED);
115             console.verifySuccess();
116             new ResourceVerifier(infinispanSessionAddress(INFINISPAN_SESSION_AFFINITY).and(AFFINITY, RANKED), client)
117                     .verifyExists();
118         } else {
119             fail("Select control to switch affinity not found!");
120         }
121 
122     }
123 
124     @Test
125     void reset() throws Exception {
126         table.select(INFINISPAN_SESSION_UPDATE);
127         crud.reset(infinispanSessionAddress(INFINISPAN_SESSION_UPDATE), form);
128     }
129 
130     @Test
131     void delete() throws Exception {
132         table.select(INFINISPAN_SESSION_DELETE);
133         crud.delete(infinispanSessionAddress(INFINISPAN_SESSION_DELETE), table, INFINISPAN_SESSION_DELETE);
134     }
135 }