|
16 | 16 | */ |
17 | 17 | package org.apache.activemq.artemis.tests.smoke.console; |
18 | 18 |
|
| 19 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
19 | 20 | import static org.junit.jupiter.api.Assertions.fail; |
20 | 21 |
|
21 | 22 | import org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension; |
22 | 23 | import org.apache.activemq.artemis.tests.smoke.console.pages.LoginPage; |
| 24 | +import org.apache.activemq.artemis.tests.smoke.console.pages.StatusPage; |
23 | 25 | import org.junit.jupiter.api.TestTemplate; |
24 | 26 | import org.junit.jupiter.api.extension.ExtendWith; |
25 | 27 | import org.openqa.selenium.By; |
26 | 28 | import org.openqa.selenium.NoSuchElementException; |
27 | 29 |
|
| 30 | +import java.util.Collections; |
| 31 | +import java.util.Set; |
| 32 | + |
28 | 33 | //Parameters set in super class |
29 | 34 | @ExtendWith(ParameterizedTestExtension.class) |
30 | 35 | public class TabsTest extends ArtemisTest { |
31 | 36 |
|
32 | | - public TabsTest(String browser, String serverName) { |
33 | | - super(browser, serverName); |
34 | | - } |
35 | | - |
36 | | - @TestTemplate |
37 | | - public void testConnectionsTab() { |
38 | | - testTab("connections", "Connections"); |
39 | | - } |
40 | | - |
41 | | - @TestTemplate |
42 | | - public void testSessionsTab() { |
43 | | - testTab("sessions", "Sessions"); |
44 | | - } |
45 | | - |
46 | | - @TestTemplate |
47 | | - public void testConsumersTab() { |
48 | | - testTab("consumers", "Consumers"); |
49 | | - } |
50 | | - |
51 | | - @TestTemplate |
52 | | - public void testProducersTab() { |
53 | | - testTab("producers", "Producers"); |
54 | | - } |
55 | | - |
56 | | - @TestTemplate |
57 | | - public void testAddressesTab() { |
58 | | - testTab("addresses", "Addresses"); |
59 | | - } |
| 37 | + private final String TAB_CONNECTIONS = "Connections"; |
60 | 38 |
|
61 | | - @TestTemplate |
62 | | - public void testQueuesTab() { |
63 | | - testTab("queues", "Queues"); |
64 | | - } |
| 39 | + private final String TAB_SESSIONS = "Sessions"; |
65 | 40 |
|
66 | | - private void testTab(String userpass, String tab) { |
67 | | - loadLandingPage(); |
68 | | - new LoginPage(driver).loginValidUser(userpass, userpass, DEFAULT_TIMEOUT); |
69 | | - driver.findElement(By.xpath("//button/span[contains(text(),'" + tab + "')]")); |
70 | | - } |
| 41 | + private final String TAB_CONSUMERS = "Consumers"; |
71 | 42 |
|
72 | | - @TestTemplate |
73 | | - public void testConnectionsTabNegative() { |
74 | | - // use credentials for a valid user who cannot see the tab |
75 | | - testTabNegative("queues", "Connections"); |
76 | | - } |
| 43 | + private final String TAB_PRODUCERS = "Producers"; |
77 | 44 |
|
78 | | - @TestTemplate |
79 | | - public void testSessionsTabNegative() { |
80 | | - // use credentials for a valid user who cannot see the tab |
81 | | - testTabNegative("connections", "Sessions"); |
82 | | - } |
| 45 | + private final String TAB_ADDRESSES = "Addresses"; |
83 | 46 |
|
84 | | - @TestTemplate |
85 | | - public void testConsumersTabNegative() { |
86 | | - // use credentials for a valid user who cannot see the tab |
87 | | - testTabNegative("connections", "Consumers"); |
88 | | - } |
| 47 | + private final String TAB_QUEUES = "Queues"; |
89 | 48 |
|
90 | | - @TestTemplate |
91 | | - public void testProducersTabNegative() { |
92 | | - // use credentials for a valid user who cannot see the tab |
93 | | - testTabNegative("connections", "roducers"); |
94 | | - } |
| 49 | + private final String[] TABS = new String[]{TAB_CONNECTIONS, TAB_SESSIONS, TAB_CONSUMERS, TAB_PRODUCERS, TAB_ADDRESSES, TAB_QUEUES}; |
95 | 50 |
|
96 | | - @TestTemplate |
97 | | - public void testAddressesTabNegative() { |
98 | | - // use credentials for a valid user who cannot see the tab |
99 | | - testTabNegative("connections", "Addresses"); |
| 51 | + public TabsTest(String browser, String serverName) { |
| 52 | + super(browser, serverName); |
100 | 53 | } |
101 | 54 |
|
102 | 55 | @TestTemplate |
103 | | - public void testQueuesTabNegative() { |
104 | | - // use credentials for a valid user who cannot see the tab |
105 | | - testTabNegative("connections", "Queues"); |
| 56 | + public void testVisibleTabs() { |
| 57 | + testTabs(SERVER_ADMIN_USERNAME, false, Set.of(TABS)); |
| 58 | + testTabs("connections", true, Collections.singleton(TAB_CONNECTIONS)); |
| 59 | + testTabs("sessions", true, Collections.singleton(TAB_SESSIONS)); |
| 60 | + testTabs("consumers", true, Collections.singleton(TAB_CONSUMERS)); |
| 61 | + testTabs("producers", true, Collections.singleton(TAB_PRODUCERS)); |
| 62 | + testTabs("addresses", true, Collections.singleton(TAB_ADDRESSES)); |
| 63 | + testTabs("queues", true, Collections.singleton(TAB_QUEUES)); |
106 | 64 | } |
107 | 65 |
|
108 | | - private void testTabNegative(String userpass, String tab) { |
| 66 | + private void testTabs(String userpass, boolean isAlertExpected, Set<String> visibleTabs) { |
109 | 67 | loadLandingPage(); |
110 | | - new LoginPage(driver).loginValidUser(userpass, userpass, DEFAULT_TIMEOUT); |
111 | | - try { |
112 | | - driver.findElement(By.xpath("//a[contains(text(),'" + tab + "')]")); |
113 | | - fail("User " + userpass + " should not have been able to see the " + tab + " tab."); |
114 | | - } catch (NoSuchElementException e) { |
115 | | - // expected |
| 68 | + |
| 69 | + StatusPage statusPage = new LoginPage(driver).loginValidUser(userpass, userpass, DEFAULT_TIMEOUT); |
| 70 | + |
| 71 | + assertEquals(isAlertExpected, statusPage.countAlerts() > 0); |
| 72 | + statusPage.closeAlerts(); |
| 73 | + |
| 74 | + for (String tab : TABS) { |
| 75 | + By tabLocator = By.xpath("//button/span[contains(text(),'" + tab + "')]"); |
| 76 | + if (visibleTabs.contains(tab)) { |
| 77 | + driver.findElement(tabLocator); |
| 78 | + } else { |
| 79 | + try { |
| 80 | + driver.findElement(tabLocator); |
| 81 | + fail("User " + userpass + " should not have been able to see the " + tab + " tab."); |
| 82 | + } catch (Exception e) { |
| 83 | + assertEquals(NoSuchElementException.class, e.getClass()); |
| 84 | + } |
| 85 | + } |
116 | 86 | } |
| 87 | + |
| 88 | + statusPage.logout(DEFAULT_TIMEOUT); |
117 | 89 | } |
118 | 90 | } |
0 commit comments