zzzk1 commented on code in PR #3823:
URL: 
https://github.com/apache/incubator-streampark/pull/3823#discussion_r1662374608


##########
streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/TokenManagementTest.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.JavascriptExecutor;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.remote.RemoteWebDriver;
+import org.openqa.selenium.support.ui.WebDriverWait;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+import java.time.Duration;
+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);
+
+        new WebDriverWait(browser, Duration.ofSeconds(10));
+        String clipboardContent = (String) ((JavascriptExecutor) 
browser).executeScript("return navigator.clipboard.readText();");

Review Comment:
   @SbloodyS i am try a lot and found: `selenium` and `streampark` services 
running in docker, as remote service. I cannot visit the clipboard through 
**Toolkit** api under local env, another option is to use JS script to read the 
clipboard in  browser, the value of the board, but it failed for some reasons: 
maybe the page was not in focus or it was denied by the security policy.



##########
streampark-e2e/streampark-e2e-case/src/test/java/org/apache/streampark/e2e/cases/TokenManagementTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.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 testCreateDuplicateToken() {
+        final TokenManagementPage tokenManagementPage = new 
TokenManagementPage(browser);
+        refreshPage();
+        tokenManagementPage.createToken(existUserName, newTokenDescription);
+
+        Awaitility.await()
+            .untilAsserted(
+                () ->
+                    assertThat(tokenManagementPage.errorMessageSearchLayout())
+                        .as("Please select a user").isNotNull());
+    }
+
+  @Test
+  @Order(30)
+  void testDeleteToken() {
+    final TokenManagementPage teamManagementPage = new 
TokenManagementPage(browser);
+    refreshPage();
+    teamManagementPage.deleteToken(existUserName);
+
+    Awaitility.await()
+        .untilAsserted(
+            () -> {
+              browser.navigate().refresh();
+              assertThat(teamManagementPage.tokenList())
+                  .noneMatch(it -> it.getText().contains(existUserName));
+            });
+  }
+
+  /**
+  * Users can only create one token. Once the user creates a token, it will 
not be found in the search layout.
+  * So type username which has been used in search layout will fail with 
frontend check. This method only used
+  * to help testCreateDuplicateToken testing frontend verify for and 
testDeleteToken skip frontend verify.
+  */
+  private void refreshPage() {
+      browser.navigate().refresh();
+  }
+}

Review Comment:
   This method here is just to allow test cases to proceed.



##########
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();

Review Comment:
   We can remove `browser.navigate().refresh();` after fixing issue 
https://github.com/apache/incubator-streampark/issues/3865



##########
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();

Review Comment:
   > This still unaddressed.
   
   This place is necessary. Each user should only be able to create one token. 
At this time, the refresh will filter out the username that have already 
created tokens from the drop-down box.



-- 
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]

Reply via email to