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.web;
17  
18  import org.jboss.arquillian.core.api.annotation.Inject;
19  import org.jboss.arquillian.graphene.page.Page;
20  import org.jboss.hal.resources.Ids;
21  import org.jboss.hal.testsuite.Console;
22  import org.jboss.hal.testsuite.CrudOperations;
23  import org.jboss.hal.testsuite.Random;
24  import org.jboss.hal.testsuite.container.WildFlyContainer;
25  import org.jboss.hal.testsuite.fragment.FormFragment;
26  import org.jboss.hal.testsuite.fragment.TableFragment;
27  import org.jboss.hal.testsuite.page.configuration.FilterPage;
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.operations.Operations;
35  import org.wildfly.extras.creaper.core.online.operations.Values;
36  
37  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
38  import static org.jboss.hal.dmr.ModelDescriptionConstants.QUEUE_SIZE;
39  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
40  import static org.jboss.hal.testsuite.fixtures.WebFixtures.FILTER_CREATE;
41  import static org.jboss.hal.testsuite.fixtures.WebFixtures.FILTER_DELETE;
42  import static org.jboss.hal.testsuite.fixtures.WebFixtures.FILTER_UPDATE;
43  import static org.jboss.hal.testsuite.fixtures.WebFixtures.MAX_CONCURRENT_REQUESTS;
44  import static org.jboss.hal.testsuite.fixtures.WebFixtures.requestLimitAddress;
45  
46  @Manatoko
47  @Testcontainers
48  public class RequestLimitTest {
49  
50      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
51  
52      @BeforeAll
53      static void setupModel() throws Exception {
54          Operations operations = new Operations(wildFly.managementClient());
55          operations.add(requestLimitAddress(FILTER_UPDATE), Values.of(MAX_CONCURRENT_REQUESTS, Random.number()));
56          operations.add(requestLimitAddress(FILTER_DELETE), Values.of(MAX_CONCURRENT_REQUESTS, Random.number()));
57      }
58  
59      @Inject Console console;
60      @Page FilterPage page;
61      @Inject CrudOperations crud;
62      TableFragment table;
63      FormFragment form;
64  
65      @BeforeEach
66      void prepare() {
67          page.navigate();
68          console.verticalNavigation().selectPrimary(Ids.build("undertow-request-limit", "item"));
69          table = page.getRequestLimitTable();
70          form = page.getRequestLimitForm();
71          table.bind(form);
72      }
73  
74      @Test
75      void create() throws Exception {
76          crud.create(requestLimitAddress(FILTER_CREATE), table, form -> {
77              form.text(NAME, FILTER_CREATE);
78              form.number(MAX_CONCURRENT_REQUESTS, Random.number());
79          });
80      }
81  
82      @Test
83      void update() throws Exception {
84          int requests = Random.number();
85          int queue = Random.number();
86  
87          table.select(FILTER_UPDATE);
88          crud.update(requestLimitAddress(FILTER_UPDATE), form, f -> {
89              f.number(MAX_CONCURRENT_REQUESTS, requests);
90              f.number(QUEUE_SIZE, queue);
91          }, resourceVerifier -> {
92              resourceVerifier.verifyAttribute(MAX_CONCURRENT_REQUESTS, requests);
93              resourceVerifier.verifyAttribute(QUEUE_SIZE, queue);
94          });
95      }
96  
97      @Test
98      void delete() throws Exception {
99          crud.delete(requestLimitAddress(FILTER_DELETE), table, FILTER_DELETE);
100     }
101 }