[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
This commit is contained in:
parent
091d869d66
commit
323129febb
|
|
@ -92,6 +92,8 @@ jobs:
|
||||||
class: org.apache.dolphinscheduler.api.test.cases.TenantAPITest
|
class: org.apache.dolphinscheduler.api.test.cases.TenantAPITest
|
||||||
- name: WorkerGroup
|
- name: WorkerGroup
|
||||||
class: org.apache.dolphinscheduler.api.test.cases.WorkerGroupAPITest
|
class: org.apache.dolphinscheduler.api.test.cases.WorkerGroupAPITest
|
||||||
|
- name: Project
|
||||||
|
class: org.apache.dolphinscheduler.api.test.cases.ProjectAPITest
|
||||||
env:
|
env:
|
||||||
RECORDING_PATH: /tmp/recording-${{ matrix.case.name }}
|
RECORDING_PATH: /tmp/recording-${{ matrix.case.name }}
|
||||||
steps:
|
steps:
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ Every page of DolphinScheduler's api is abstracted into a class for better maint
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
The login page's api is abstracted
|
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,
|
, with the following fields,
|
||||||
|
|
||||||
```java
|
```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<Project> projects = (List<Project>) 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<LinkedHashMap> projects = (List<LinkedHashMap>) 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<LinkedHashMap> projects = (List<LinkedHashMap>) 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<String, Object> 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<LinkedHashMap> projects = (List<LinkedHashMap>) queryAllProjectListResponse.getBody().getData();
|
||||||
|
Long code = (Long) projects.get(0).get("code");
|
||||||
|
HttpResponse queryAuthorizedUserResponse = projectPage.queryAuthorizedUser(loginUser, code);
|
||||||
|
List<LinkedHashMap> users = (List<LinkedHashMap>) 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<LinkedHashMap> projects = (List<LinkedHashMap>) 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"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("projectName", projectName);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("projectName", projectName);
|
||||||
|
params.put("userName", userName);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("pageSize", pageSize);
|
||||||
|
params.put("pageNo", pageNo);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("userId", userId);
|
||||||
|
params.put("pageSize", pageSize);
|
||||||
|
params.put("pageNo", pageNo);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("userId", userId);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("userId", userId);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("userId", userId);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
params.put("projectCode", projectCode);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
Map<String, String> 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<String, Object> params = new HashMap<>();
|
||||||
|
params.put("loginUser", loginUser);
|
||||||
|
Map<String, String> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -103,22 +103,16 @@ public class RequestClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
String requestUrl = String.format("%s%s", Constants.DOLPHINSCHEDULER_API_URL, url);
|
String requestUrl = String.format("%s%s", Constants.DOLPHINSCHEDULER_API_URL, url);
|
||||||
|
|
||||||
headers.put("Content-Type", Constants.REQUEST_CONTENT_TYPE);
|
headers.put("Content-Type", Constants.REQUEST_CONTENT_TYPE);
|
||||||
|
|
||||||
Headers headersBuilder = Headers.of(headers);
|
Headers headersBuilder = Headers.of(headers);
|
||||||
|
|
||||||
RequestBody requestBody = FormBody.create(MediaType.parse(Constants.REQUEST_CONTENT_TYPE), getParams(params));
|
RequestBody requestBody = FormBody.create(MediaType.parse(Constants.REQUEST_CONTENT_TYPE), getParams(params));
|
||||||
|
|
||||||
log.info("POST request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params);
|
log.info("POST request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params);
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.headers(headersBuilder)
|
.headers(headersBuilder)
|
||||||
.url(requestUrl)
|
.url(requestUrl)
|
||||||
.post(requestBody)
|
.post(requestBody)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Response response = this.httpClient.newCall(request).execute();
|
Response response = this.httpClient.newCall(request).execute();
|
||||||
|
|
||||||
int responseCode = response.code();
|
int responseCode = response.code();
|
||||||
HttpResponseBody responseData = null;
|
HttpResponseBody responseData = null;
|
||||||
if (response.body() != null) {
|
if (response.body() != null) {
|
||||||
|
|
@ -133,6 +127,38 @@ public class RequestClient {
|
||||||
return httpResponse;
|
return httpResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
public HttpResponse put(String url, Map<String, String> headers, Map<String, Object> 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
|
@SneakyThrows
|
||||||
public HttpResponse delete(String url, Map<String, String> headers, Map<String, Object> params) {
|
public HttpResponse delete(String url, Map<String, String> headers, Map<String, Object> params) {
|
||||||
if (headers == null) {
|
if (headers == null) {
|
||||||
Loading…
Reference in New Issue