From 323129febb575a2ad9054ee3493c6b922a39a1d8 Mon Sep 17 00:00:00 2001 From: Eric Gao Date: Tue, 27 Jun 2023 10:00:11 +0800 Subject: [PATCH] [Improvement][API-Test] Add api tests for project page (#14402) * add initial api tests for process definition controller * Update * Add test cases for project page * Remove unrelated stuff * Remove useless imports * Add project api test case to github workflow matrix --- .github/workflows/api-test.yml | 2 + dolphinscheduler-api-test/README.md | 2 +- .../api/test/cases/ProjectAPITest.java | 211 ++++++++++++++++++ .../test}/cases/TenantAPITest.java | 0 .../test}/cases/WorkerGroupAPITest.java | 0 .../test}/entity/HttpResponse.java | 0 .../test}/entity/HttpResponseBody.java | 0 .../test}/entity/LoginResponseData.java | 0 .../entity/TenantListPagingResponseData.java | 0 .../TenantListPagingResponseTotalList.java | 0 .../test}/pages/LoginPage.java | 0 .../api/test/pages/project/ProjectPage.java | 180 +++++++++++++++ .../test}/pages/security/TenantPage.java | 0 .../test}/pages/security/WorkerGroupPage.java | 0 .../test}/utils/JSONUtils.java | 0 .../test}/utils/RequestClient.java | 38 +++- 16 files changed, 426 insertions(+), 7 deletions(-) create mode 100644 dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/ProjectAPITest.java rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/cases/TenantAPITest.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/cases/WorkerGroupAPITest.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/entity/HttpResponse.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/entity/HttpResponseBody.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/entity/LoginResponseData.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/entity/TenantListPagingResponseData.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/entity/TenantListPagingResponseTotalList.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/pages/LoginPage.java (100%) create mode 100644 dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/project/ProjectPage.java rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/pages/security/TenantPage.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/pages/security/WorkerGroupPage.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/utils/JSONUtils.java (100%) rename dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/{api.test => api/test}/utils/RequestClient.java (81%) diff --git a/.github/workflows/api-test.yml b/.github/workflows/api-test.yml index 75b4dd4449..14a5bcec1d 100644 --- a/.github/workflows/api-test.yml +++ b/.github/workflows/api-test.yml @@ -92,6 +92,8 @@ jobs: class: org.apache.dolphinscheduler.api.test.cases.TenantAPITest - name: WorkerGroup class: org.apache.dolphinscheduler.api.test.cases.WorkerGroupAPITest + - name: Project + class: org.apache.dolphinscheduler.api.test.cases.ProjectAPITest env: RECORDING_PATH: /tmp/recording-${{ matrix.case.name }} steps: diff --git a/dolphinscheduler-api-test/README.md b/dolphinscheduler-api-test/README.md index c5eec50c89..9e48bc6430 100644 --- a/dolphinscheduler-api-test/README.md +++ b/dolphinscheduler-api-test/README.md @@ -9,7 +9,7 @@ Every page of DolphinScheduler's api is abstracted into a class for better maint ### Example The login page's api is abstracted -as [`LoginPage`](dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/LoginPage.java) +as [`LoginPage`](dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/LoginPage.java) , with the following fields, ```java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/ProjectAPITest.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/ProjectAPITest.java new file mode 100644 index 0000000000..bb6e1455aa --- /dev/null +++ b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/ProjectAPITest.java @@ -0,0 +1,211 @@ +/* + * Licensed to 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. Apache Software Foundation (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.dolphinscheduler.api.test.cases; + +import org.apache.dolphinscheduler.api.test.core.DolphinScheduler; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.entity.LoginResponseData; +import org.apache.dolphinscheduler.api.test.pages.LoginPage; +import org.apache.dolphinscheduler.api.test.pages.project.ProjectPage; +import org.apache.dolphinscheduler.api.test.utils.JSONUtils; +import org.apache.dolphinscheduler.common.enums.UserType; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.User; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; + +import lombok.extern.slf4j.Slf4j; + +import java.util.LinkedHashMap; +import java.util.List; + +@DolphinScheduler(composeFiles = "docker/basic/docker-compose.yaml") +@Slf4j +// TODO: Add more detailed permission control related cases after userPage test cases completed +public class ProjectAPITest { + + private static final String username = "admin"; + + private static final String password = "dolphinscheduler123"; + + private static String sessionId; + + private static User loginUser; + + private static ProjectPage projectPage; + + @BeforeAll + public static void setup() { + LoginPage loginPage = new LoginPage(); + HttpResponse loginHttpResponse = loginPage.login(username, password); + sessionId = JSONUtils.convertValue(loginHttpResponse.getBody().getData(), LoginResponseData.class).getSessionId(); + projectPage = new ProjectPage(sessionId); + loginUser = new User(); + loginUser.setUserName("admin"); + loginUser.setId(1); + loginUser.setUserType(UserType.ADMIN_USER); + } + + @AfterAll + public static void cleanup() { + log.info("success cleanup"); + } + + @Test + @Order(1) + public void testQueryAllProjectList() { + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + Assertions.assertTrue(queryAllProjectListResponse.getBody().getSuccess()); + List projects = (List) queryAllProjectListResponse.getBody().getData(); + Assertions.assertEquals(projects.size(), 0); + } + + @Test + @Order(2) + public void testCreateProject() { + HttpResponse createProjectResponse = projectPage.createProject(loginUser, "project-test"); + Assertions.assertTrue(createProjectResponse.getBody().getSuccess()); + + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + Assertions.assertTrue(queryAllProjectListResponse.getBody().getData().toString().contains("project-test")); + } + + @Test + @Order(3) + public void testUpdateProject() { + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + List projects = (List) queryAllProjectListResponse.getBody().getData(); + Long code = (Long) projects.get(0).get("code"); + + HttpResponse updateProjectResponse = projectPage.updateProject(loginUser, code,"project-new", loginUser.getUserName()); + Assertions.assertTrue(updateProjectResponse.getBody().getSuccess()); + + queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + Assertions.assertFalse(queryAllProjectListResponse.getBody().getData().toString().contains("project-test")); + Assertions.assertTrue(queryAllProjectListResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(4) + public void testQueryProjectByCode() { + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + List projects = (List) queryAllProjectListResponse.getBody().getData(); + Long code = (Long) projects.get(0).get("code"); + String projectNameExpected = (String) projects.get(0).get("name"); + + HttpResponse queryProjectByCodeResponse = projectPage.queryProjectByCode(loginUser, code); + Assertions.assertTrue(queryProjectByCodeResponse.getBody().getSuccess()); + + LinkedHashMap project = (LinkedHashMap) queryProjectByCodeResponse.getBody().getData(); + String projectNameActual = (String) project.get("name"); + Assertions.assertEquals(projectNameExpected, projectNameActual); + } + + @Test + @Order(5) + public void testQueryProjectListPaging() { + HttpResponse queryProjectListPagingResponse = projectPage.queryProjectListPaging(loginUser, 1, 1); + Assertions.assertTrue(queryProjectListPagingResponse.getBody().getSuccess()); + Assertions.assertTrue(queryProjectListPagingResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(6) + public void testQueryProjectWithAuthorizedLevelListPaging() { + HttpResponse queryProjectWithAuthorizedLevelListPagingResponse = projectPage.queryProjectWithAuthorizedLevelListPaging(loginUser, loginUser.getId(),1, 1); + Assertions.assertTrue(queryProjectWithAuthorizedLevelListPagingResponse.getBody().getSuccess()); + Assertions.assertTrue(queryProjectWithAuthorizedLevelListPagingResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(7) + public void testQueryUnauthorizedProject() { + HttpResponse queryUnauthorizedProjectResponse = projectPage.queryUnauthorizedProject(loginUser, loginUser.getId()); + Assertions.assertTrue(queryUnauthorizedProjectResponse.getBody().getSuccess()); + // project-new was created by instead of authorized to this user, therefore, it should be in the unauthorized list + Assertions.assertTrue(queryUnauthorizedProjectResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(8) + public void testQueryAuthorizedProject() { + HttpResponse queryAuthorizedProjectResponse = projectPage.queryAuthorizedProject(loginUser, loginUser.getId()); + Assertions.assertTrue(queryAuthorizedProjectResponse.getBody().getSuccess()); + // project-new was created by instead of authorized to this user, therefore, it should not be in the authorized list + Assertions.assertFalse(queryAuthorizedProjectResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(9) + public void testQueryProjectWithAuthorizedLevel() { + HttpResponse queryProjectWithAuthorizedLevelResponse = projectPage.queryProjectWithAuthorizedLevel(loginUser, loginUser.getId()); + Assertions.assertTrue(queryProjectWithAuthorizedLevelResponse.getBody().getSuccess()); + // queryProjectWithAuthorizedLevel api returns a joint-set of projects both created by and authorized to the user + Assertions.assertTrue(queryProjectWithAuthorizedLevelResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(10) + public void testQueryAuthorizedUser() { + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + List projects = (List) queryAllProjectListResponse.getBody().getData(); + Long code = (Long) projects.get(0).get("code"); + HttpResponse queryAuthorizedUserResponse = projectPage.queryAuthorizedUser(loginUser, code); + List users = (List) queryAuthorizedUserResponse.getBody().getData(); + Assertions.assertTrue(queryAuthorizedUserResponse.getBody().getSuccess()); + // admin has not authorized this project to any other users, therefore, the authorized user list should be empty + Assertions.assertEquals(users.size(), 0); + } + + @Test + @Order(11) + public void testQueryProjectCreatedAndAuthorizedByUser() { + HttpResponse queryProjectCreatedAndAuthorizedByUserResponse = projectPage.queryProjectCreatedAndAuthorizedByUser(loginUser); + Assertions.assertTrue(queryProjectCreatedAndAuthorizedByUserResponse.getBody().getSuccess()); + // queryProjectCreatedAndAuthorizedByUser api returns a joint-set of projects both created by and authorized to the user + Assertions.assertTrue(queryProjectCreatedAndAuthorizedByUserResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(12) + public void testQueryAllProjectListForDependent() { + HttpResponse queryAllProjectListForDependentResponse = projectPage.queryAllProjectListForDependent(loginUser); + Assertions.assertTrue(queryAllProjectListForDependentResponse.getBody().getSuccess()); + Assertions.assertTrue(queryAllProjectListForDependentResponse.getBody().getData().toString().contains("project-new")); + } + + @Test + @Order(13) + public void testDeleteProject() { + HttpResponse queryAllProjectListResponse = projectPage.queryAllProjectList(loginUser); + List projects = (List) queryAllProjectListResponse.getBody().getData(); + Long code = (Long) projects.get(0).get("code"); + HttpResponse queryAllProjectListForDependentResponse = projectPage.deleteProject(loginUser, code); + Assertions.assertTrue(queryAllProjectListForDependentResponse.getBody().getSuccess()); + Assertions.assertFalse(queryAllProjectListForDependentResponse.getBody().getData().toString().contains("project-new")); + } +} + + diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/TenantAPITest.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/TenantAPITest.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/TenantAPITest.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/TenantAPITest.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkerGroupAPITest.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/WorkerGroupAPITest.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkerGroupAPITest.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/cases/WorkerGroupAPITest.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/HttpResponse.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/HttpResponse.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/HttpResponse.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/HttpResponse.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/HttpResponseBody.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/HttpResponseBody.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/HttpResponseBody.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/HttpResponseBody.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/LoginResponseData.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/LoginResponseData.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/LoginResponseData.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/LoginResponseData.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/TenantListPagingResponseData.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/TenantListPagingResponseData.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/TenantListPagingResponseData.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/TenantListPagingResponseData.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/TenantListPagingResponseTotalList.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/TenantListPagingResponseTotalList.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/entity/TenantListPagingResponseTotalList.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/entity/TenantListPagingResponseTotalList.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/LoginPage.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/LoginPage.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/LoginPage.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/LoginPage.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/project/ProjectPage.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/project/ProjectPage.java new file mode 100644 index 0000000000..b5f0a31bfc --- /dev/null +++ b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/project/ProjectPage.java @@ -0,0 +1,180 @@ +/* + * Licensed to 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. Apache Software Foundation (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.dolphinscheduler.api.test.pages.project; + +import lombok.AllArgsConstructor; + +import org.apache.dolphinscheduler.api.test.core.Constants; +import org.apache.dolphinscheduler.api.test.entity.HttpResponse; +import org.apache.dolphinscheduler.api.test.utils.RequestClient; +import org.apache.dolphinscheduler.dao.entity.User; + +import java.util.HashMap; +import java.util.Map; + +@AllArgsConstructor +public final class ProjectPage { + private String sessionId; + + public HttpResponse createProject(User loginUser, String projectName) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("projectName", projectName); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.post("/projects", headers, params); + } + + public HttpResponse queryAllProjectList(User loginUser) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/list", headers, params); + } + + public HttpResponse updateProject(User loginUser, Long code, String projectName, String userName) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("projectName", projectName); + params.put("userName", userName); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + String url = String.format("/projects/%d", code); + return requestClient.put(url, headers, params); + } + + public HttpResponse queryProjectByCode(User loginUser, Long code) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + String url = String.format("/projects/%d", code); + return requestClient.get(url, headers, params); + } + + public HttpResponse queryProjectListPaging(User loginUser, Integer pageSize, Integer pageNo) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("pageSize", pageSize); + params.put("pageNo", pageNo); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects", headers, params); + } + + public HttpResponse queryProjectWithAuthorizedLevelListPaging(User loginUser, Integer userId, Integer pageSize, Integer pageNo) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("userId", userId); + params.put("pageSize", pageSize); + params.put("pageNo", pageNo); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/project-with-authorized-level-list-paging", headers, params); + } + + public HttpResponse queryUnauthorizedProject(User loginUser, Integer userId) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("userId", userId); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/unauth-project", headers, params); + } + + public HttpResponse queryAuthorizedProject(User loginUser, Integer userId) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("userId", userId); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/authed-project", headers, params); + } + + public HttpResponse queryProjectWithAuthorizedLevel(User loginUser, Integer userId) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("userId", userId); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/project-with-authorized-level", headers, params); + } + + public HttpResponse queryAuthorizedUser(User loginUser, Long projectCode) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + params.put("projectCode", projectCode); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/authed-user", headers, params); + } + + public HttpResponse queryProjectCreatedAndAuthorizedByUser(User loginUser) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/created-and-authed", headers, params); + } + + public HttpResponse queryAllProjectListForDependent(User loginUser) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + return requestClient.get("/projects/list-dependent", headers, params); + } + + public HttpResponse deleteProject(User loginUser, Long code) { + Map params = new HashMap<>(); + params.put("loginUser", loginUser); + Map headers = new HashMap<>(); + headers.put(Constants.SESSION_ID_KEY, sessionId); + + RequestClient requestClient = new RequestClient(); + String url = String.format("/projects/%d", code); + return requestClient.delete(url, headers, params); + } +} diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/security/TenantPage.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/security/TenantPage.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/security/TenantPage.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/security/TenantPage.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/security/WorkerGroupPage.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/security/WorkerGroupPage.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/security/WorkerGroupPage.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/pages/security/WorkerGroupPage.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/JSONUtils.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/utils/JSONUtils.java similarity index 100% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/JSONUtils.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/utils/JSONUtils.java diff --git a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/RequestClient.java b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/utils/RequestClient.java similarity index 81% rename from dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/RequestClient.java rename to dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/utils/RequestClient.java index 11377e90ed..bcc8631ac5 100644 --- a/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/RequestClient.java +++ b/dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api/test/utils/RequestClient.java @@ -103,22 +103,16 @@ public class RequestClient { } String requestUrl = String.format("%s%s", Constants.DOLPHINSCHEDULER_API_URL, url); - headers.put("Content-Type", Constants.REQUEST_CONTENT_TYPE); - Headers headersBuilder = Headers.of(headers); - RequestBody requestBody = FormBody.create(MediaType.parse(Constants.REQUEST_CONTENT_TYPE), getParams(params)); - log.info("POST request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params); Request request = new Request.Builder() .headers(headersBuilder) .url(requestUrl) .post(requestBody) .build(); - Response response = this.httpClient.newCall(request).execute(); - int responseCode = response.code(); HttpResponseBody responseData = null; if (response.body() != null) { @@ -133,6 +127,38 @@ public class RequestClient { return httpResponse; } + @SneakyThrows + public HttpResponse put(String url, Map headers, Map params) { + if (headers == null) { + headers = new HashMap<>(); + } + + String requestUrl = String.format("%s%s", Constants.DOLPHINSCHEDULER_API_URL, url); + headers.put("Content-Type", Constants.REQUEST_CONTENT_TYPE); + Headers headersBuilder = Headers.of(headers); + RequestBody requestBody = FormBody.create(MediaType.parse(Constants.REQUEST_CONTENT_TYPE), getParams(params)); + log.info("PUT request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params); + Request request = new Request.Builder() + .headers(headersBuilder) + .url(requestUrl) + .put(requestBody) + .build(); + Response response = this.httpClient.newCall(request).execute(); + int responseCode = response.code(); + HttpResponseBody responseData = null; + if (response.body() != null) { + responseData = JSONUtils.parseObject(response.body().string(), HttpResponseBody.class); + } + response.close(); + + HttpResponse httpResponse = new HttpResponse(responseCode, responseData); + + log.info("PUT response: {}", httpResponse); + + return httpResponse; + } + + @SneakyThrows public HttpResponse delete(String url, Map headers, Map params) { if (headers == null) {