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.io;
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.IOPage;
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.Operations;
35  import org.wildfly.extras.creaper.core.online.operations.Values;
36  
37  import static org.jboss.hal.dmr.ModelDescriptionConstants.IO_THREADS;
38  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
39  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
40  import static org.jboss.hal.testsuite.fixtures.IOFixtures.WORKER_CREATE;
41  import static org.jboss.hal.testsuite.fixtures.IOFixtures.WORKER_DELETE;
42  import static org.jboss.hal.testsuite.fixtures.IOFixtures.WORKER_READ;
43  import static org.jboss.hal.testsuite.fixtures.IOFixtures.WORKER_UPDATE;
44  import static org.jboss.hal.testsuite.fixtures.IOFixtures.workerAddress;
45  import static org.junit.jupiter.api.Assertions.assertEquals;
46  
47  @Manatoko
48  @Testcontainers
49  class WorkerTest {
50  
51      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
52  
53      @BeforeAll
54      static void setupModel() throws Exception {
55          OnlineManagementClient client = wildFly.managementClient();
56          Operations operations = new Operations(client);
57          operations.add(workerAddress(WORKER_READ), Values.empty().and(IO_THREADS, 11));
58          operations.add(workerAddress(WORKER_UPDATE), Values.empty().and(IO_THREADS, 123));
59          operations.add(workerAddress(WORKER_DELETE), Values.empty().and(IO_THREADS, 321));
60      }
61  
62      @Inject Console console;
63      @Inject CrudOperations crud;
64      @Page IOPage page;
65      TableFragment table;
66      FormFragment form;
67  
68      @BeforeEach
69      void prepare() {
70          page.navigate();
71          console.verticalNavigation().selectPrimary("io-worker-item");
72  
73          form = page.getWorkerForm();
74          table = page.getWorkerTable();
75          table.bind(form);
76      }
77  
78      @Test
79      void create() throws Exception {
80          crud.create(workerAddress(WORKER_CREATE), table,
81                  form -> {
82                      form.text(NAME, WORKER_CREATE);
83                      form.number(IO_THREADS, 12);
84                      form.number("stack-size", 1024);
85                      form.number("task-keepalive", 2233);
86                      form.number("task-max-threads", 12345);
87                  });
88      }
89  
90      @Test
91      void read() {
92          table.select(WORKER_READ);
93          assertEquals(11, form.intValue(IO_THREADS));
94      }
95  
96      @Test
97      void update() throws Exception {
98          table.select(WORKER_UPDATE);
99          crud.update(workerAddress(WORKER_UPDATE), form, IO_THREADS, Random.number());
100     }
101 
102     @Test
103     void updateInvalidMaxThreads() {
104         table.select(WORKER_UPDATE);
105         crud.updateWithError(form, IO_THREADS, -1);
106     }
107 
108     @Test
109     void delete() throws Exception {
110         crud.delete(workerAddress(WORKER_DELETE), table, WORKER_DELETE);
111     }
112 }