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.modcluster;
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.Random;
23  import org.jboss.hal.testsuite.container.WildFlyContainer;
24  import org.jboss.hal.testsuite.fragment.FormFragment;
25  import org.jboss.hal.testsuite.fragment.TableFragment;
26  import org.jboss.hal.testsuite.page.configuration.ModclusterPage;
27  import org.jboss.hal.testsuite.test.Manatoko;
28  import org.junit.jupiter.api.BeforeAll;
29  import org.junit.jupiter.api.BeforeEach;
30  import org.junit.jupiter.api.Test;
31  import org.testcontainers.junit.jupiter.Container;
32  import org.testcontainers.junit.jupiter.Testcontainers;
33  import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
34  import org.wildfly.extras.creaper.core.online.operations.Batch;
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.DEFAULT;
39  import static org.jboss.hal.dmr.ModelDescriptionConstants.LISTENER;
40  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
41  import static org.jboss.hal.dmr.ModelDescriptionConstants.TYPE;
42  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.HA;
43  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.CAPACITY;
44  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.LOAD_METRIC_CREATE;
45  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.LOAD_METRIC_DELETE;
46  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.LOAD_METRIC_UPDATE;
47  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.PROXY_UPDATE;
48  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.WEIGHT;
49  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.loadMetricAddress;
50  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.loadProviderDynamicAddress;
51  import static org.jboss.hal.testsuite.fixtures.ModclusterFixtures.proxyAddress;
52  
53  @Manatoko
54  @Testcontainers
55  class LoadMetricTest {
56  
57      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(HA);
58  
59      @BeforeAll
60      static void setupModel() throws Exception {
61          OnlineManagementClient client = wildFly.managementClient();
62          Operations operations = new Operations(client);
63          Batch proxyAdd = new Batch();
64          proxyAdd.add(proxyAddress(PROXY_UPDATE), Values.of(LISTENER, DEFAULT));
65          proxyAdd.add(loadProviderDynamicAddress(PROXY_UPDATE));
66          operations.batch(proxyAdd).assertSuccess();
67          operations.add(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_DELETE), Values.of(TYPE, "heap")).assertSuccess();
68          operations.add(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_UPDATE), Values.of(TYPE, "heap")).assertSuccess();
69      }
70  
71      @Inject Console console;
72      @Inject CrudOperations crud;
73      @Page ModclusterPage page;
74      TableFragment table;
75      FormFragment form;
76  
77      @BeforeEach
78      void setUp() {
79          page.navigate(NAME, PROXY_UPDATE);
80          console.verticalNavigation().selectPrimary("load-metrics-item");
81          table = page.getLoadMetricTable();
82          form = page.getLoadMetricForm();
83          table.bind(form);
84      }
85  
86      @Test
87      void create() throws Exception {
88          crud.create(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_CREATE), table, f -> {
89              f.text(NAME, LOAD_METRIC_CREATE);
90              f.select(TYPE, "cpu");
91          },
92                  ver -> ver.verifyAttribute(TYPE, "cpu"));
93      }
94  
95      @Test
96      void reset() throws Exception {
97          table.select(LOAD_METRIC_UPDATE);
98          crud.reset(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_UPDATE), form);
99      }
100 
101     @Test
102     void update() throws Exception {
103         table.select(LOAD_METRIC_UPDATE);
104         crud.update(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_UPDATE), form, WEIGHT, Random.number());
105     }
106 
107     @Test
108     void updateCapacity() throws Exception {
109         // update an attribute of type DOUBLE
110         table.select(LOAD_METRIC_UPDATE);
111         crud.update(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_UPDATE), form, CAPACITY, Random.numberDouble());
112     }
113 
114     @Test
115     void delete() throws Exception {
116         crud.delete(loadMetricAddress(PROXY_UPDATE, LOAD_METRIC_DELETE), table, LOAD_METRIC_DELETE);
117     }
118 }