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.remoting;
17  
18  import org.jboss.arquillian.core.api.annotation.Inject;
19  import org.jboss.arquillian.graphene.page.Page;
20  import org.jboss.dmr.ModelNode;
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.command.AddLocalSocketBinding;
25  import org.jboss.hal.testsuite.container.WildFlyContainer;
26  import org.jboss.hal.testsuite.fixtures.RemotingFixtures;
27  import org.jboss.hal.testsuite.fragment.FormFragment;
28  import org.jboss.hal.testsuite.fragment.TableFragment;
29  import org.jboss.hal.testsuite.model.ResourceVerifier;
30  import org.jboss.hal.testsuite.page.configuration.RemotingPage;
31  import org.jboss.hal.testsuite.test.Manatoko;
32  import org.junit.jupiter.api.BeforeAll;
33  import org.junit.jupiter.api.BeforeEach;
34  import org.junit.jupiter.api.Test;
35  import org.testcontainers.junit.jupiter.Container;
36  import org.testcontainers.junit.jupiter.Testcontainers;
37  import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
38  import org.wildfly.extras.creaper.core.online.operations.Operations;
39  import org.wildfly.extras.creaper.core.online.operations.Values;
40  
41  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
42  import static org.jboss.hal.dmr.ModelDescriptionConstants.OUTBOUND_SOCKET_BINDING_REF;
43  import static org.jboss.hal.dmr.ModelDescriptionConstants.PROPERTY;
44  import static org.jboss.hal.dmr.ModelDescriptionConstants.VALUE;
45  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
46  import static org.jboss.hal.testsuite.fixtures.RemotingFixtures.BACKLOG;
47  import static org.jboss.hal.testsuite.fixtures.RemotingFixtures.LOCAL_OUTBOUND_CREATE;
48  import static org.jboss.hal.testsuite.fixtures.RemotingFixtures.LOCAL_OUTBOUND_DELETE;
49  import static org.jboss.hal.testsuite.fixtures.RemotingFixtures.LOCAL_OUTBOUND_READ;
50  import static org.jboss.hal.testsuite.fixtures.RemotingFixtures.LOCAL_OUTBOUND_UPDATE;
51  import static org.jboss.hal.testsuite.fixtures.SocketBindingFixtures.OUTBOUND_LOCAL_READ;
52  import static org.junit.jupiter.api.Assertions.assertEquals;
53  
54  @Manatoko
55  @Testcontainers
56  class OutboundLocalTest {
57  
58      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
59      private static OnlineManagementClient client;
60  
61      @BeforeAll
62      static void setupModel() throws Exception {
63          client = wildFly.managementClient();
64          Operations operations = new Operations(client);
65          client.apply(new AddLocalSocketBinding(OUTBOUND_LOCAL_READ));
66  
67          operations.add(RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_READ),
68                  Values.of(OUTBOUND_SOCKET_BINDING_REF, OUTBOUND_LOCAL_READ));
69          operations.add(RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_UPDATE),
70                  Values.of(OUTBOUND_SOCKET_BINDING_REF, OUTBOUND_LOCAL_READ));
71          operations.add(RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_DELETE),
72                  Values.of(OUTBOUND_SOCKET_BINDING_REF, OUTBOUND_LOCAL_READ));
73      }
74  
75      @Inject Console console;
76      @Inject CrudOperations crud;
77      @Page RemotingPage page;
78      TableFragment table;
79      FormFragment form;
80  
81      @BeforeEach
82      void prepare() {
83          page.navigate();
84          console.verticalNavigation().selectSecondary("remoting-outbound-connection-item",
85                  "remoting-local-outbound-sub-item");
86          table = page.getLocalOutboundTable();
87          form = page.getLocalOutboundForm();
88          table.bind(form);
89      }
90  
91      @Test
92      void create() throws Exception {
93          crud.create(RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_CREATE), table, form -> {
94              form.text(NAME, LOCAL_OUTBOUND_CREATE);
95              form.text(OUTBOUND_SOCKET_BINDING_REF, OUTBOUND_LOCAL_READ);
96          });
97      }
98  
99      @Test
100     void read() {
101         table.select(LOCAL_OUTBOUND_READ);
102         form.showSensitive(OUTBOUND_SOCKET_BINDING_REF);
103         assertEquals(OUTBOUND_LOCAL_READ, form.value(OUTBOUND_SOCKET_BINDING_REF));
104     }
105 
106     @Test
107     void update() throws Exception {
108         ModelNode properties = Random.properties(BACKLOG, "12");
109 
110         table.select(LOCAL_OUTBOUND_UPDATE);
111         crud.update(RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_UPDATE), form,
112                 f -> f.properties(PROPERTY).add(properties),
113                 resourceVerifier -> {
114                     // properties are nested resources!
115                     ResourceVerifier propertyVerifier = new ResourceVerifier(
116                             RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_UPDATE).and(PROPERTY, BACKLOG),
117                             client);
118                     propertyVerifier.verifyAttribute(VALUE, "12");
119                 });
120     }
121 
122     @Test
123     void delete() throws Exception {
124         crud.delete(RemotingFixtures.outboundLocalAddress(LOCAL_OUTBOUND_DELETE), table, LOCAL_OUTBOUND_DELETE);
125     }
126 }