Browse Source

[Improvement][API Test] Add API tests for worker group related APIs (#13936)

* Add worker group api test

* Add more cases

* Remove useless comments

* Remove useless code and add missing license header

* Remove debug logging

* Restore changes for testing
3.2.0-release
Eric Gao 1 year ago committed by GitHub
parent
commit
4545093c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/pom.xml
  2. 18
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/TenantAPITest.java
  3. 132
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkerGroupAPITest.java
  4. 100
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/security/WorkerGroupPage.java
  5. 12
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/RequestClient.java
  6. 10
      dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/resources/docker/basic/docker-compose.yaml
  7. 2
      dolphinscheduler-api-test/dolphinscheduler-api-test-core/src/main/java/org/apache/dolphinscheduler/api/test/core/DolphinSchedulerExtension.java
  8. 21
      dolphinscheduler-api-test/lombok.config

12
dolphinscheduler-api-test/dolphinscheduler-api-test-case/pom.xml

@ -36,5 +36,17 @@
<artifactId>dolphinscheduler-api-test-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-dao</artifactId>
<version>dev-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dolphinscheduler</groupId>
<artifactId>dolphinscheduler-api</artifactId>
<version>dev-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

18
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/TenantAPITest.java

@ -54,12 +54,12 @@ public class TenantAPITest {
LoginPage loginPage = new LoginPage();
HttpResponse loginHttpResponse = loginPage.login(user, password);
sessionId = JSONUtils.convertValue(loginHttpResponse.body().data(), LoginResponseData.class).sessionId();
sessionId = JSONUtils.convertValue(loginHttpResponse.getBody().getData(), LoginResponseData.class).getSessionId();
}
@AfterAll
public static void cleanup() {
LOGGER.info("success cleanup");
log.info("success cleanup");
}
@Test
@ -69,7 +69,7 @@ public class TenantAPITest {
HttpResponse createTenantHttpResponse = tenantPage.createTenant(sessionId, tenant, 1, "");
Assertions.assertTrue(createTenantHttpResponse.body().success());
Assertions.assertTrue(createTenantHttpResponse.getBody().getSuccess());
}
@Test
@ -79,7 +79,7 @@ public class TenantAPITest {
HttpResponse createTenantHttpResponse = tenantPage.createTenant(sessionId, tenant, 1, "");
Assertions.assertFalse(createTenantHttpResponse.body().success());
Assertions.assertFalse(createTenantHttpResponse.getBody().getSuccess());
}
@Test
@ -90,15 +90,15 @@ public class TenantAPITest {
HttpResponse createTenantHttpResponse = tenantPage.getTenantListPaging(sessionId, 1, 10, "");
boolean result = false;
for (TenantListPagingResponseTotalList tenantListPagingResponseTotalList : JSONUtils.convertValue(createTenantHttpResponse.body().data(), TenantListPagingResponseData.class).totalList()) {
if (tenantListPagingResponseTotalList.tenantCode().equals(tenant)) {
for (TenantListPagingResponseTotalList tenantListPagingResponseTotalList : JSONUtils.convertValue(createTenantHttpResponse.getBody().getData(), TenantListPagingResponseData.class).getTotalList()) {
if (tenantListPagingResponseTotalList.getTenantCode().equals(tenant)) {
result = true;
existTenantId = tenantListPagingResponseTotalList.id();
existTenantId = tenantListPagingResponseTotalList.getId();
break;
}
}
Assertions.assertTrue(createTenantHttpResponse.body().success());
Assertions.assertTrue(createTenantHttpResponse.getBody().getSuccess());
Assertions.assertTrue(result);
}
@ -109,6 +109,6 @@ public class TenantAPITest {
HttpResponse deleteTenantHttpResponse = tenantPage.deleteTenant(sessionId, existTenantId);
Assertions.assertTrue(deleteTenantHttpResponse.body().success());
Assertions.assertTrue(deleteTenantHttpResponse.getBody().getSuccess());
}
}

132
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/cases/WorkerGroupAPITest.java

@ -0,0 +1,132 @@
/*
* 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.security.WorkerGroupPage;
import org.apache.dolphinscheduler.api.test.utils.JSONUtils;
import org.apache.dolphinscheduler.common.enums.UserType;
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.Order;
import org.junit.jupiter.api.Test;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.fasterxml.jackson.databind.ObjectMapper;
@DolphinScheduler(composeFiles = "docker/basic/docker-compose.yaml")
@Slf4j
public class WorkerGroupAPITest {
private static final String username = "admin";
private static final String password = "dolphinscheduler123";
private static String sessionId;
private static User loginUser;
private static WorkerGroupPage workerGroupPage;
@BeforeAll
public static void setup() {
LoginPage loginPage = new LoginPage();
HttpResponse loginHttpResponse = loginPage.login(username, password);
sessionId = JSONUtils.convertValue(loginHttpResponse.getBody().getData(), LoginResponseData.class).getSessionId();
workerGroupPage = new WorkerGroupPage(sessionId);
loginUser = new User();
loginUser.setId(123);
loginUser.setUserType(UserType.GENERAL_USER);
}
@AfterAll
public static void cleanup() {
log.info("success cleanup");
}
@Test
@Order(1)
public void testSaveWorkerGroup() {
HttpResponse saveWorkerGroupHttpResponse = workerGroupPage
.saveWorkerGroup(loginUser, 1, "test_worker_group", "10.5.0.5:1234", "test", null);
Assertions.assertTrue(saveWorkerGroupHttpResponse.getBody().getSuccess());
HttpResponse queryAllWorkerGroupsResponse = workerGroupPage.queryAllWorkerGroups(loginUser);
List<String> workerGroupsList = (List<String>) queryAllWorkerGroupsResponse.getBody().getData();
Set<String> workerGroupsActual = new HashSet<>(workerGroupsList);
Set<String> workerGroupsExpected = new HashSet<>(Arrays.asList("test_worker_group", "default"));
Assertions.assertEquals(workerGroupsExpected, workerGroupsActual);
}
@Test
@Order(2)
public void testQueryAllWorkerGroupsPaging() {
HttpResponse queryAllWorkerGroupsPagingResponse = workerGroupPage.queryAllWorkerGroupsPaging(loginUser, 1, 2, null);
Assertions.assertTrue(queryAllWorkerGroupsPagingResponse.getBody().getSuccess());
String workerGroupPageInfoData = queryAllWorkerGroupsPagingResponse.getBody().getData().toString();
Assertions.assertTrue(workerGroupPageInfoData.contains("test_worker_group"));
}
@Test
@Order(3)
public void testQueryAllWorkerGroups() {
HttpResponse queryAllWorkerGroupsResponse = workerGroupPage.queryAllWorkerGroups(loginUser);
Assertions.assertTrue(queryAllWorkerGroupsResponse.getBody().getSuccess());
String workerGroupPageInfoData = queryAllWorkerGroupsResponse.getBody().getData().toString();
Assertions.assertTrue(workerGroupPageInfoData.contains("test_worker_group"));
}
@Test
@Order(4)
public void queryWorkerAddressList() {
HttpResponse queryWorkerAddressListResponse = workerGroupPage.queryWorkerAddressList(loginUser);
Assertions.assertTrue(queryWorkerAddressListResponse.getBody().getSuccess());
Assertions.assertTrue(queryWorkerAddressListResponse.getBody().getData().toString().contains("10.5.0.5:1234"));
}
@Test
@Order(5)
public void testDeleteWorkerGroupById() {
HttpResponse queryAllWorkerGroupsResponse = workerGroupPage.queryAllWorkerGroups(loginUser);
String workerGroupsBeforeDelete = queryAllWorkerGroupsResponse.getBody().getData().toString();
Assertions.assertTrue(queryAllWorkerGroupsResponse.getBody().getSuccess());
Assertions.assertTrue(workerGroupsBeforeDelete.contains("test_worker_group"));
HttpResponse deleteWorkerGroupResponse = workerGroupPage.deleteWorkerGroupById(loginUser, 1);
Assertions.assertTrue(deleteWorkerGroupResponse.getBody().getSuccess());
queryAllWorkerGroupsResponse = workerGroupPage.queryAllWorkerGroups(loginUser);
String workerGroupsAfterDelete = queryAllWorkerGroupsResponse.getBody().getData().toString();
Assertions.assertTrue(!workerGroupsAfterDelete.contains("test_worker_group"));
}
}

100
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/pages/security/WorkerGroupPage.java

@ -0,0 +1,100 @@
/*
* 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.security;
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 class WorkerGroupPage {
private String sessionId;
public HttpResponse saveWorkerGroup(User loginUser, int id, String name, String addrList, String description, String otherParamsJson) {
Map<String, Object> params = new HashMap<>();
params.put("loginUser", loginUser);
params.put("id", id);
params.put("name", name);
params.put("addrList", addrList);
params.put("description", description);
params.put("otherParamsJson", otherParamsJson);
Map<String, String> headers = new HashMap<>();
headers.put(Constants.SESSION_ID_KEY, sessionId);
RequestClient requestClient = new RequestClient();
return requestClient.post("/worker-groups", headers, params);
}
public HttpResponse queryAllWorkerGroups(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("/worker-groups/all", headers, params);
}
public HttpResponse queryAllWorkerGroupsPaging(User loginUser, Integer pageNo, Integer pageSize, String searchVal) {
Map<String, Object> params = new HashMap<>();
params.put("loginUser", loginUser);
params.put("pageNo", pageNo);
params.put("pageSize", pageSize);
params.put("searchVal", searchVal);
Map<String, String> headers = new HashMap<>();
headers.put(Constants.SESSION_ID_KEY, sessionId);
RequestClient requestClient = new RequestClient();
return requestClient.get("/worker-groups", headers, params);
}
public HttpResponse deleteWorkerGroupById(User loginUser, Integer id) {
Map<String, Object> params = new HashMap<>();
params.put("loginUser", loginUser);
params.put("id", id);
Map<String, String> headers = new HashMap<>();
headers.put(Constants.SESSION_ID_KEY, sessionId);
RequestClient requestClient = new RequestClient();
final String url = String.format("/worker-groups/%s", id);
return requestClient.delete(url, headers, params);
}
public HttpResponse queryWorkerAddressList(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("/worker-groups/worker-address-list", headers, params);
}
}

12
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/java/org/apache/dolphinscheduler/api.test/utils/RequestClient.java

@ -56,7 +56,7 @@ public class RequestClient {
headersBuilder = Headers.of(headers);
}
LOGGER.info("GET request to {}, Headers: {}", requestUrl, headersBuilder);
log.info("GET request to {}, Headers: {}", requestUrl, headersBuilder);
Request request = new Request.Builder()
.url(requestUrl)
.headers(headersBuilder)
@ -74,7 +74,7 @@ public class RequestClient {
HttpResponse httpResponse = new HttpResponse(responseCode, responseData);
LOGGER.info("GET response: {}", httpResponse);
log.info("GET response: {}", httpResponse);
return httpResponse;
}
@ -111,7 +111,7 @@ public class RequestClient {
RequestBody requestBody = FormBody.create(MediaType.parse(Constants.REQUEST_CONTENT_TYPE), getParams(params));
LOGGER.info("POST request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params);
log.info("POST request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params);
Request request = new Request.Builder()
.headers(headersBuilder)
.url(requestUrl)
@ -129,7 +129,7 @@ public class RequestClient {
HttpResponse httpResponse = new HttpResponse(responseCode, responseData);
LOGGER.info("POST response: {}", httpResponse);
log.info("POST response: {}", httpResponse);
return httpResponse;
}
@ -146,7 +146,7 @@ public class RequestClient {
Headers headersBuilder = Headers.of(headers);
LOGGER.info("DELETE request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params);
log.info("DELETE request to {}, Headers: {}, Params: {}", requestUrl, headersBuilder, params);
Request request = new Request.Builder()
.headers(headersBuilder)
.url(requestUrl)
@ -164,7 +164,7 @@ public class RequestClient {
HttpResponse httpResponse = new HttpResponse(responseCode, responseData);
LOGGER.info("DELETE response: {}", httpResponse);
log.info("DELETE response: {}", httpResponse);
return httpResponse;
}

10
dolphinscheduler-api-test/dolphinscheduler-api-test-case/src/test/resources/docker/basic/docker-compose.yaml

@ -26,7 +26,8 @@ services:
ports:
- "12345:12345"
networks:
- api-test
network:
ipv4_address: 10.5.0.5
healthcheck:
test: [ "CMD", "curl", "http://localhost:12345/actuator/health" ]
interval: 5s
@ -34,4 +35,9 @@ services:
retries: 120
networks:
api-test:
network:
driver: bridge
ipam:
config:
- subnet: 10.5.0.0/16
gateway: 10.5.0.1

2
dolphinscheduler-api-test/dolphinscheduler-api-test-core/src/main/java/org/apache/dolphinscheduler/api/test/core/DolphinSchedulerExtension.java

@ -71,7 +71,7 @@ final class DolphinSchedulerExtension implements BeforeAllCallback, AfterAllCall
compose = new DockerComposeContainer<>(files)
.withPull(true)
.withTailChildContainers(true)
.withLogConsumer(serviceName, outputFrame -> LOGGER.info(outputFrame.getUtf8String()))
.withLogConsumer(serviceName, outputFrame -> log.info(outputFrame.getUtf8String()))
.waitingFor(serviceName, Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(Constants.DOCKER_COMPOSE_DEFAULT_TIMEOUT)));
return compose;

21
dolphinscheduler-api-test/lombok.config

@ -1,21 +0,0 @@
#
# 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.
#
lombok.accessors.fluent=true
lombok.log.fieldname=LOGGER
lombok.accessors.fluent=true
lombok.anyConstructor.addConstructorProperties=true
Loading…
Cancel
Save