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.TARGET;
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.REDIRECT;
44  import static org.jboss.hal.testsuite.fixtures.WebFixtures.rewriteAddress;
45  
46  @Manatoko
47  @Testcontainers
48  public class RewriteTest {
49  
50      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
51      static Operations operations;
52  
53      @BeforeAll
54      static void setupModel() throws Exception {
55          operations = new Operations(wildFly.managementClient());
56          operations.add(rewriteAddress(FILTER_UPDATE), Values.of(TARGET, Random.name()));
57          operations.add(rewriteAddress(FILTER_DELETE), Values.of(TARGET, Random.name()));
58      }
59  
60      @Inject Console console;
61      @Page FilterPage page;
62      @Inject CrudOperations crud;
63      TableFragment table;
64      FormFragment form;
65  
66      @BeforeEach
67      void prepare() {
68          page.navigate();
69          console.verticalNavigation().selectPrimary(Ids.build("undertow-rewrite", "item"));
70          table = page.getRewriteTable();
71          form = page.getRewriteForm();
72          table.bind(form);
73      }
74  
75      @Test
76      void create() throws Exception {
77          crud.create(rewriteAddress(FILTER_CREATE), table, form -> {
78              form.text(NAME, FILTER_CREATE);
79              form.text(TARGET, Random.name());
80          });
81      }
82  
83      @Test
84      void update() throws Exception {
85          String target = Random.name();
86          boolean redirect = operations.readAttribute(rewriteAddress(FILTER_UPDATE), REDIRECT).booleanValue();
87  
88          table.select(FILTER_UPDATE);
89          crud.update(rewriteAddress(FILTER_UPDATE), form,
90                  f -> {
91                      f.text(TARGET, target);
92                      f.flip(REDIRECT, !redirect);
93                  },
94                  resourceVerifier -> {
95                      resourceVerifier.verifyAttribute(TARGET, target);
96                      resourceVerifier.verifyAttribute(REDIRECT, !redirect);
97                  });
98      }
99  
100     @Test
101     void delete() throws Exception {
102         crud.delete(rewriteAddress(FILTER_DELETE), table, FILTER_DELETE);
103     }
104 }