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.NAME;
38  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
39  import static org.jboss.hal.testsuite.fixtures.IOFixtures.BP_CREATE;
40  import static org.jboss.hal.testsuite.fixtures.IOFixtures.BP_DELETE;
41  import static org.jboss.hal.testsuite.fixtures.IOFixtures.BP_READ;
42  import static org.jboss.hal.testsuite.fixtures.IOFixtures.BP_UPDATE;
43  import static org.jboss.hal.testsuite.fixtures.IOFixtures.BUFFERS_PER_SLICE;
44  import static org.jboss.hal.testsuite.fixtures.IOFixtures.BUFFER_SIZE;
45  import static org.jboss.hal.testsuite.fixtures.IOFixtures.DIRECT_BUFFERS;
46  import static org.jboss.hal.testsuite.fixtures.IOFixtures.bufferPoolAddress;
47  import static org.junit.jupiter.api.Assertions.assertEquals;
48  
49  @Manatoko
50  @Testcontainers
51  class BufferPoolTest {
52  
53      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
54  
55      @BeforeAll
56      static void setupModel() throws Exception {
57          OnlineManagementClient client = wildFly.managementClient();
58          Operations operations = new Operations(client);
59          operations.add(bufferPoolAddress(BP_READ), Values.empty().and(BUFFER_SIZE, 11).and(BUFFERS_PER_SLICE, 22));
60          operations.add(bufferPoolAddress(BP_UPDATE), Values.empty());
61          operations.add(bufferPoolAddress(BP_DELETE), Values.empty());
62      }
63  
64      @Inject Console console;
65      @Inject CrudOperations crud;
66      @Page IOPage page;
67      TableFragment table;
68      FormFragment form;
69  
70      @BeforeEach
71      void prepare() {
72          page.navigate();
73          console.verticalNavigation().selectPrimary("io-buffer-pool-item");
74  
75          form = page.getBufferPoolForm();
76          table = page.getBufferPoolTable();
77          table.bind(form);
78      }
79  
80      @Test
81      void create() throws Exception {
82          crud.create(bufferPoolAddress(BP_CREATE), table,
83                  form -> {
84                      form.text(NAME, BP_CREATE);
85                      form.number(BUFFER_SIZE, 12);
86                      form.number(BUFFERS_PER_SLICE, 23);
87                      form.flip(DIRECT_BUFFERS, true);
88                  });
89      }
90  
91      @Test
92      void read() {
93          table.select(BP_READ);
94          assertEquals(11, form.intValue(BUFFER_SIZE));
95      }
96  
97      @Test
98      void update() throws Exception {
99          table.select(BP_UPDATE);
100         crud.update(bufferPoolAddress(BP_UPDATE), form, BUFFER_SIZE, Random.number());
101     }
102 
103     @Test
104     void updateInvalidBufferSize() {
105         table.select(BP_UPDATE);
106         crud.updateWithError(form, BUFFER_SIZE, 0);
107     }
108 
109     @Test
110     void updateInvalidBuffersPerSlice() {
111         table.select(BP_UPDATE);
112         crud.updateWithError(form, BUFFERS_PER_SLICE, 0);
113     }
114 
115     @Test
116     void delete() throws Exception {
117         crud.delete(bufferPoolAddress(BP_DELETE), table, BP_DELETE);
118     }
119 }