This is an automated email from the ASF dual-hosted git repository.
benjobs pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git
The following commit(s) were added to refs/heads/dev by this push:
new 8a2f39f31 [ISSUE-3812][Feature] Introduce token management e2e test
(#3823)
8a2f39f31 is described below
commit 8a2f39f31985a76108750b51fd419bec7eaa7e6a
Author: Zhengke Zhou <[email protected]>
AuthorDate: Tue Jul 16 11:10:21 2024 +0800
[ISSUE-3812][Feature] Introduce token management e2e test (#3823)
* Introduce token management e2e test
Co-authored-by: benjobs <[email protected]>
---
.github/workflows/e2e.yml | 2 +
.../streampark/e2e/cases/TokenManagementTest.java | 121 +++++++++++++++++++
.../streampark/e2e/pages/system/SystemPage.java | 6 +
.../e2e/pages/system/TokenManagementPage.java | 131 +++++++++++++++++++++
4 files changed, 260 insertions(+)
diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml
index 755e7e275..5374fc941 100644
--- a/.github/workflows/e2e.yml
+++ b/.github/workflows/e2e.yml
@@ -110,6 +110,8 @@ jobs:
strategy:
matrix:
case:
+ - name: TokenManagementTest
+ class: org.apache.streampark.e2e.cases.TokenManagementTest
- name: UploadManagementTest
class: org.apache.streampark.e2e.cases.UploadManagementTest
- name: ProjectsManagementTest
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/TokenManagementTest.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/TokenManagementTest.java
new file mode 100644
index 000000000..f677fd032
--- /dev/null
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/TokenManagementTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.e2e.cases;
+
+import org.apache.streampark.e2e.core.StreamPark;
+import org.apache.streampark.e2e.pages.LoginPage;
+import org.apache.streampark.e2e.pages.system.SystemPage;
+import org.apache.streampark.e2e.pages.system.TokenManagementPage;
+
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@StreamPark(composeFiles = "docker/basic/docker-compose.yaml")
+public class TokenManagementTest {
+
+ private static RemoteWebDriver browser;
+
+ private static final String userName = "admin";
+
+ private static final String password = "streampark";
+
+ private static final String teamName = "default";
+
+ private static final String existUserName = "admin";
+
+ private static final String newTokenDescription =
"test_new_token_description";
+
+ @BeforeAll
+ public static void setup() {
+ new LoginPage(browser)
+ .login(userName, password, teamName)
+ .goToNav(SystemPage.class)
+ .goToTab(TokenManagementPage.class);
+ }
+
+ @Test
+ @Order(10)
+ void testCreateToken() {
+ final TokenManagementPage tokenManagementPage = new
TokenManagementPage(browser);
+ tokenManagementPage.createToken(existUserName, newTokenDescription);
+
+ Awaitility.await()
+ .untilAsserted(
+ () -> assertThat(tokenManagementPage.tokenList())
+ .as("Token list should contain newly-created token")
+ .extracting(WebElement::getText)
+ .anyMatch(it -> it.contains(existUserName)));
+ }
+
+ @Test
+ @Order(20)
+ void testCopyToken() {
+ final TokenManagementPage tokenManagementPage = new
TokenManagementPage(browser);
+ tokenManagementPage.copyToken(existUserName);
+
+ // put clipboard value into createTokenForm.description
+ tokenManagementPage.buttonCreateToken().click();
+
tokenManagementPage.createTokenForm().inputDescription().sendKeys(Keys.CONTROL,
"v");
+ String token =
tokenManagementPage.createTokenForm().inputDescription().getAttribute("value");
+ tokenManagementPage.createTokenForm().buttonCancel().click();
+
+ Awaitility.await()
+ .untilAsserted(
+ () -> assertThat(tokenManagementPage.tokenList())
+ .as("Clipboard should contain existing token.")
+ .extracting(WebElement::getText)
+ .anyMatch(it -> it.contains(token)));
+ }
+
+ @Test
+ @Order(30)
+ void testCreateDuplicateToken() {
+ final TokenManagementPage tokenManagementPage = new
TokenManagementPage(browser);
+ browser.navigate().refresh();
+ tokenManagementPage.createToken(existUserName, newTokenDescription);
+
+ Awaitility.await()
+ .untilAsserted(
+ () ->
assertThat(tokenManagementPage.errorMessageSearchLayout())
+ .as("Please select a user").isNotNull());
+
+ tokenManagementPage.createTokenForm().buttonCancel().click();
+ }
+
+ @Test
+ @Order(40)
+ void testDeleteToken() {
+ final TokenManagementPage teamManagementPage = new
TokenManagementPage(browser);
+ teamManagementPage.deleteToken(existUserName);
+
+ Awaitility.await()
+ .untilAsserted(
+ () -> {
+ browser.navigate().refresh();
+ assertThat(teamManagementPage.tokenList())
+ .noneMatch(it -> it.getText().contains(existUserName));
+ });
+ }
+}
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/SystemPage.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/SystemPage.java
index 779455b0e..14e7035e2 100644
---
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/SystemPage.java
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/SystemPage.java
@@ -72,6 +72,12 @@ public final class SystemPage extends NavBarPage implements
NavBarItem {
menuRoleManagement.click();
return tab.cast(new RoleManagementPage(driver));
}
+ if (tab == TokenManagementPage.class) {
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(menuTokenManagement));
+ menuTokenManagement.click();
+ return tab.cast(new TokenManagementPage(driver));
+ }
if (tab == MemberManagementPage.class) {
new WebDriverWait(driver, Duration.ofSeconds(10))
diff --git
a/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/TokenManagementPage.java
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/TokenManagementPage.java
new file mode 100644
index 000000000..987e01ad4
--- /dev/null
+++
b/streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/pages/system/TokenManagementPage.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.streampark.e2e.pages.system;
+
+import org.apache.streampark.e2e.pages.common.NavBarPage;
+
+import lombok.Getter;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.support.FindBy;
+import org.openqa.selenium.support.PageFactory;
+import org.openqa.selenium.support.ui.ExpectedConditions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import java.time.Duration;
+import java.util.List;
+
+@Getter
+public class TokenManagementPage extends NavBarPage implements SystemPage.Tab {
+
+ @FindBy(xpath = "//span[contains(., 'Token
List')]/..//button[contains(@class, 'ant-btn-primary')]/span[contains(text(),
'Add New')]")
+ private WebElement buttonCreateToken;
+
+ @FindBy(xpath = "//tbody[contains(@class, 'ant-table-tbody')]")
+ private List<WebElement> tokenList;
+
+ @FindBy(xpath = "//button[contains(@class, 'ant-btn')]/span[contains(.,
'OK')]")
+ private WebElement deleteConfirmButton;
+
+ @FindBy(className = "ant-form-item-explain-error")
+ private WebElement errorMessageSearchLayout;
+
+ private final CreateTokenForm createTokenForm = new CreateTokenForm();
+
+ public TokenManagementPage(RemoteWebDriver driver) {
+ super(driver);
+ }
+
+ public TokenManagementPage createToken(String existUserName, String
description) {
+ waitForPageLoading();
+
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+ .until(ExpectedConditions.elementToBeClickable(buttonCreateToken));
+ buttonCreateToken.click();
+
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(createTokenForm.inputUserName()));
+ createTokenForm.inputUserName().sendKeys(existUserName);
+ createTokenForm.inputUserName().sendKeys(Keys.RETURN);
+
+ createTokenForm.inputDescription().sendKeys(description);
+ createTokenForm.buttonSubmit().click();
+ return this;
+ }
+
+ public TokenManagementPage copyToken(String existUserName) {
+ waitForPageLoading();
+
+ tokenList().stream()
+ .filter(it -> it.getText().contains(existUserName))
+ .flatMap(
+ it ->
it.findElements(By.xpath("//button[contains(@tooltip,'Copy Token')]")).stream())
+ .filter(WebElement::isDisplayed)
+ .findFirst()
+ .orElseThrow(() -> new RuntimeException("No Copy button in token
list"))
+ .click();
+
+ return this;
+ }
+
+ public TokenManagementPage deleteToken(String existUserName) {
+ waitForPageLoading();
+
+ tokenList().stream()
+ .filter(it -> it.getText().contains(existUserName))
+ .flatMap(
+ it ->
it.findElements(By.xpath("//button[contains(@tooltip,'Delete
Token')]")).stream())
+ .filter(WebElement::isDisplayed)
+ .findFirst()
+ .orElseThrow(() -> new RuntimeException("No delete button in token
list"))
+ .click();
+
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+
.until(ExpectedConditions.elementToBeClickable(deleteConfirmButton));
+ deleteConfirmButton.click();
+
+ return this;
+ }
+
+ private void waitForPageLoading() {
+ new WebDriverWait(driver, Duration.ofSeconds(10))
+ .until(ExpectedConditions.urlContains("/system/token"));
+ }
+
+ @Getter
+ public class CreateTokenForm {
+
+ CreateTokenForm() {
+ PageFactory.initElements(driver, this);
+ }
+
+ @FindBy(id = "form_item_userId")
+ private WebElement inputUserName;
+
+ @FindBy(id = "form_item_description")
+ private WebElement inputDescription;
+
+ @FindBy(xpath = "//button[contains(@class,
'ant-btn')]//span[contains(., 'Submit')]")
+ private WebElement buttonSubmit;
+
+ @FindBy(xpath = "//button[contains(@class,
'ant-btn')]//span[contains(., 'Cancel')]")
+ private WebElement buttonCancel;
+ }
+}