gemmellr commented on code in PR #6242:
URL: https://github.com/apache/artemis/pull/6242#discussion_r2917764078
##########
tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/console/TabsTest.java:
##########
@@ -16,103 +16,76 @@
*/
package org.apache.activemq.artemis.tests.smoke.console;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import
org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
import org.apache.activemq.artemis.tests.smoke.console.pages.LoginPage;
+import org.apache.activemq.artemis.tests.smoke.console.pages.StatusPage;
+import org.junit.Assert;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
+import java.util.Collections;
+import java.util.Set;
+
//Parameters set in super class
@ExtendWith(ParameterizedTestExtension.class)
public class TabsTest extends ArtemisTest {
- public TabsTest(String browser, String serverName) {
- super(browser, serverName);
- }
-
- @TestTemplate
- public void testConnectionsTab() {
- testTab("connections", "Connections");
- }
-
- @TestTemplate
- public void testSessionsTab() {
- testTab("sessions", "Sessions");
- }
-
- @TestTemplate
- public void testConsumersTab() {
- testTab("consumers", "Consumers");
- }
-
- @TestTemplate
- public void testProducersTab() {
- testTab("producers", "Producers");
- }
-
- @TestTemplate
- public void testAddressesTab() {
- testTab("addresses", "Addresses");
- }
+ private final String TAB_CONNECTIONS = "Connections";
- @TestTemplate
- public void testQueuesTab() {
- testTab("queues", "Queues");
- }
+ private final String TAB_SESSIONS = "Sessions";
- private void testTab(String userpass, String tab) {
- loadLandingPage();
- new LoginPage(driver).loginValidUser(userpass, userpass,
DEFAULT_TIMEOUT);
- driver.findElement(By.xpath("//button/span[contains(text(),'" + tab +
"')]"));
- }
+ private final String TAB_CONSUMERS = "Consumers";
- @TestTemplate
- public void testConnectionsTabNegative() {
- // use credentials for a valid user who cannot see the tab
- testTabNegative("queues", "Connections");
- }
+ private final String TAB_PRODUCERS = "Producers";
- @TestTemplate
- public void testSessionsTabNegative() {
- // use credentials for a valid user who cannot see the tab
- testTabNegative("connections", "Sessions");
- }
+ private final String TAB_ADDRESSES = "Addresses";
- @TestTemplate
- public void testConsumersTabNegative() {
- // use credentials for a valid user who cannot see the tab
- testTabNegative("connections", "Consumers");
- }
+ private final String TAB_QUEUES = "Queues";
- @TestTemplate
- public void testProducersTabNegative() {
- // use credentials for a valid user who cannot see the tab
- testTabNegative("connections", "roducers");
- }
+ private final String[] TABS = new String[]{TAB_CONNECTIONS, TAB_SESSIONS,
TAB_CONSUMERS, TAB_PRODUCERS, TAB_ADDRESSES, TAB_QUEUES};
- @TestTemplate
- public void testAddressesTabNegative() {
- // use credentials for a valid user who cannot see the tab
- testTabNegative("connections", "Addresses");
+ public TabsTest(String browser, String serverName) {
+ super(browser, serverName);
}
@TestTemplate
- public void testQueuesTabNegative() {
- // use credentials for a valid user who cannot see the tab
- testTabNegative("connections", "Queues");
+ public void testVisibleTabs() {
+ testTabs(SERVER_ADMIN_USERNAME, false, Set.of(TABS));
+ testTabs("connections", true, Collections.singleton(TAB_CONNECTIONS));
+ testTabs("sessions", true, Collections.singleton(TAB_SESSIONS));
+ testTabs("consumers", true, Collections.singleton(TAB_CONSUMERS));
+ testTabs("producers", true, Collections.singleton(TAB_PRODUCERS));
+ testTabs("addresses", true, Collections.singleton(TAB_ADDRESSES));
+ testTabs("queues", true, Collections.singleton(TAB_QUEUES));
}
- private void testTabNegative(String userpass, String tab) {
+ private void testTabs(String userpass, boolean isAlertExpected, Set<String>
visibleTabs) {
loadLandingPage();
- new LoginPage(driver).loginValidUser(userpass, userpass,
DEFAULT_TIMEOUT);
- try {
- driver.findElement(By.xpath("//a[contains(text(),'" + tab + "')]"));
- fail("User " + userpass + " should not have been able to see the " +
tab + " tab.");
- } catch (NoSuchElementException e) {
- // expected
+
+ StatusPage statusPage = new LoginPage(driver).loginValidUser(userpass,
userpass, DEFAULT_TIMEOUT);
+
+ assertEquals(isAlertExpected, statusPage.countAlerts() > 0);
+ statusPage.closeAlerts();
+
+ for (String tab : TABS) {
+ By tabLocator = By.xpath("//button/span[contains(text(),'" + tab +
"')]");
+ if (visibleTabs.contains(tab)) {
+ driver.findElement(tabLocator);
+ } else {
+ try {
+ driver.findElement(tabLocator);
+ fail("User " + userpass + " should not have been able to see
the " + tab + " tab.");
+ } catch (Exception e) {
+ Assert.assertEquals(NoSuchElementException.class, e.getClass());
Review Comment:
Should be using the Assertions class method, which is already static
imported (there also will be an unused import for the Assert class when fixing)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]