1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.hal.testsuite.test.runtime.server;
17
18 import java.io.IOException;
19 import java.util.concurrent.Callable;
20
21 import org.jboss.arquillian.core.api.annotation.Inject;
22 import org.jboss.hal.meta.token.NameTokens;
23 import org.jboss.hal.testsuite.Console;
24 import org.jboss.hal.testsuite.container.WildFlyContainer;
25 import org.jboss.hal.testsuite.fragment.finder.FinderPath;
26 import org.jboss.hal.testsuite.preview.runtime.TopologyPreview;
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.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.testcontainers.junit.jupiter.Container;
34 import org.testcontainers.junit.jupiter.Testcontainers;
35 import org.wildfly.extras.creaper.core.online.ModelNodeResult;
36 import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
37 import org.wildfly.extras.creaper.core.online.operations.Address;
38 import org.wildfly.extras.creaper.core.online.operations.Operations;
39 import org.wildfly.extras.creaper.core.online.operations.admin.DomainAdministration;
40
41 import static java.util.concurrent.TimeUnit.SECONDS;
42 import static org.awaitility.Awaitility.await;
43 import static org.hamcrest.Matchers.equalTo;
44 import static org.jboss.hal.dmr.ModelDescriptionConstants.SERVER;
45 import static org.jboss.hal.dmr.ModelDescriptionConstants.SUSPEND_STATE;
46 import static org.jboss.hal.dmr.ModelDescriptionConstants.UNDEFINED;
47 import static org.jboss.hal.resources.Ids.DOMAIN_BROWSE_BY;
48 import static org.junit.jupiter.api.Assertions.assertEquals;
49
50 @Manatoko
51 @Testcontainers
52 class TopologyTest {
53
54 @Container static WildFlyContainer wildFly = WildFlyContainer.domain();
55 static OnlineManagementClient client;
56 static final Logger logger = LoggerFactory.getLogger(TopologyTest.class);
57
58 @BeforeAll
59 static void setupModel() throws IOException {
60 client = wildFly.managementClient();
61 DomainAdministration administration = new DomainAdministration(client);
62 administration.stopServer("server-one");
63 }
64
65 @Inject Console console;
66 TopologyPreview preview;
67
68 @BeforeEach
69 void prepare() {
70 preview = console.finder(NameTokens.RUNTIME,
71 new FinderPath().append(DOMAIN_BROWSE_BY, "topology")).preview(TopologyPreview.class);
72 }
73
74 @Test
75 void startServerOneSuspended() {
76 String server = "server-one";
77 preview.serverAction(server, "Start in suspended mode");
78 await().atMost(60, SECONDS).until(readServerState(server), equalTo("SUSPENDED"));
79
80 console.waitNoNotification();
81 preview.refresh();
82 preview.selectServer(server);
83 assertEquals("SUSPENDED", preview.getServerAttribute("Suspend State"));
84 }
85
86 private Callable<String> readServerState(String server) {
87 return () -> {
88 Address address = Address.host(client.options().defaultHost).and(SERVER, server);
89 Operations operations = new Operations(wildFly.managementClient());
90 try {
91 ModelNodeResult result = operations.readAttribute(address, SUSPEND_STATE);
92 if (result.isSuccess()) {
93 return result.stringValue();
94 } else {
95 return UNDEFINED;
96 }
97 } catch (IOException e) {
98 logger.warn("Unable to read suspend state for {}: {}", address, e.getMessage());
99 return UNDEFINED;
100 }
101 };
102 }
103 }