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