部分controller接口集成测试

This commit is contained in:
xuguang
2022-02-21 10:43:54 +08:00
parent 05ceeea4b0
commit 39a6302c18
30 changed files with 2441 additions and 533 deletions

View File

@@ -0,0 +1,37 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
import com.alibaba.fastjson.JSONObject;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class GatewayHeartbeatControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试连接信息上报")
public void getSecurityAcls() {
String url = baseUrl + "/gateway/api/v1/heartbeat/survive-user?clusterId=" + physicalClusterId
+ "&brokerId=" + configMap.get(ConfigConstant.ALIVE_BROKER_ID);
JSONObject jsonObject = new JSONObject();
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(jsonObject, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
}
}

View File

@@ -0,0 +1,31 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class GatewayReportControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试查询开启JMX采集的Topic")
public void getDiscoveryAddress() {
String url = baseUrl + "/gateway/api/v1/report/jmx/topics?clusterId=" + physicalClusterId;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<String> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
}
}

View File

@@ -0,0 +1,60 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.dto.gateway.KafkaAclSearchDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.gateway.KafkaUserSearchDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class GatewaySecurityControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
private KafkaAclSearchDTO getKafkaAclSearchDTO() {
KafkaAclSearchDTO kafkaAclSearchDTO = new KafkaAclSearchDTO();
kafkaAclSearchDTO.setClusterId(physicalClusterId);
kafkaAclSearchDTO.setStart(0L);
long now = System.currentTimeMillis();
kafkaAclSearchDTO.setEnd(now);
return kafkaAclSearchDTO;
}
private KafkaUserSearchDTO getKafkaUserSearchDTO() {
KafkaUserSearchDTO kafkaUserSearchDTO = new KafkaUserSearchDTO();
kafkaUserSearchDTO.setStart(0L);
long now = System.currentTimeMillis();
kafkaUserSearchDTO.setEnd(now);
return kafkaUserSearchDTO;
}
@Test(description = "测试查询Kafka用户权限查询")
public void getSecurityAcls() {
String url = baseUrl + "/gateway/api/v1/security/acls";
HttpEntity<KafkaAclSearchDTO> httpEntity = new HttpEntity<>(getKafkaAclSearchDTO(), httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
}
@Test(description = "测试查询Kafka用户查询")
public void getSecurityUsers() {
String url = baseUrl + "/gateway/api/v1/security/users";
HttpEntity<KafkaUserSearchDTO> httpEntity = new HttpEntity<>(getKafkaUserSearchDTO(), httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
}
}

View File

@@ -0,0 +1,93 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class GatewayServiceDiscoveryControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试获取指定集群服务地址")
public void getDiscoveryAddress() {
String url = baseUrl + "/gateway/api/v1/discovery/address?clusterId=" + physicalClusterId;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<String> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
}
@Test(description = "测试获取最大App请求速率")
public void getDiscoveryAppIdRate() {
String url = baseUrl + "/gateway/api/v1/discovery/appId-rate?versionNumber=1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取集群服务地址")
public void getDiscoveryInit() {
String url = baseUrl + "/gateway/api/v1/discovery/init";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取最大IP请求速率")
public void getDiscoveryIpRate() {
String url = baseUrl + "/gateway/api/v1/discovery/ip-rate?versionNumber=1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取最大并发请求数")
public void getDiscoveryMaxRequestNum() {
String url = baseUrl + "/gateway/api/v1/discovery/max-request-num?versionNumber=1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试最大SP请求速率")
public void getDiscoverySpLimit() {
String url = baseUrl + "/gateway/api/v1/discovery/sp-limit?versionNumber=1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取集群服务地址")
public void getDiscoveryUpdate() {
String url = baseUrl + "/gateway/api/v1/discovery/update?versionNumber=1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,44 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class NormalAccountControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试账号搜索")
public void getAccountsTest() {
String url = baseUrl + "/api/v1/normal/accounts?keyWord=admin";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试查询角色")
public void getAccountTest() {
String url = baseUrl + "/api/v1/normal/accounts/account";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -3,15 +3,19 @@ package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.normal.AppDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.Constant;
import com.xiaojukeji.kafka.manager.web.config.HttpUtils;
import org.springframework.boot.test.web.client.TestRestTemplate;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.*;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -19,22 +23,82 @@ import java.util.Map;
* @Date 2022/1/7
*/
public class NormalAppControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
// 成功创建Topic
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
private final TestRestTemplate testRestTemplate = new TestRestTemplate();
@AfterClass
public void afterTest() {
// 删除Topic成功
String url = baseUrl + "/api/v1/op/topics";
deleteTopic(url);
}
private TopicCreationDTO getTopicCreationDTO() {
// 在broker1上创建1分区1副本的createTopicTest
TopicCreationDTO creationDTO = new TopicCreationDTO();
creationDTO.setAppId(configMap.get(ConfigConstant.APPID));
// 在broker1上创建
Integer brokerId = Integer.parseInt(configMap.get(ConfigConstant.ALIVE_BROKER_ID));
creationDTO.setBrokerIdList(Arrays.asList(brokerId));
creationDTO.setPartitionNum(1);
creationDTO.setReplicaNum(1);
creationDTO.setRetentionTime(1000L * 60 * 60 * 168);
creationDTO.setPeakBytesIn(10L * 1024 * 1024);
// 物理集群id
creationDTO.setClusterId(physicalClusterId);
creationDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
return creationDTO;
}
private void createCommonTopic(String url) {
// 创建Topic
TopicCreationDTO creationDTO = getTopicCreationDTO();
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void deleteTopic(String url) {
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = getTopicDeletionDTO();
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private TopicDeletionDTO getTopicDeletionDTO() {
TopicDeletionDTO deletionDTO = new TopicDeletionDTO();
deletionDTO.setClusterId(physicalClusterId);
deletionDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
deletionDTO.setUnForce(true);
return deletionDTO;
}
private AppDTO getAppDTO() {
AppDTO appDTO = new AppDTO();
appDTO.setAppId(Constant.APPID_IN_MYSQL);
appDTO.setAppId(configMap.get(ConfigConstant.APPID));
appDTO.setName("KM管理员");
appDTO.setPrincipals("admin");
appDTO.setPrincipals(configMap.get(ConfigConstant.ADMIN_USER));
appDTO.setDescription("KM管理员应用-谨慎对外提供");
return appDTO;
}
@Test(description = "测试获取App列表")
public void getAppsTest() {
String url = Constant.BASE_URL + "/api/v1/normal/apps";
String url = baseUrl + "/api/v1/normal/apps";
// 有headers登陆
getAppsWithHeadersTest(url);
@@ -43,7 +107,6 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppsWithHeadersTest(String url) {
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -59,7 +122,7 @@ public class NormalAppControllerTest extends BaseTest {
@Test(description = "测试由appId获取app")
public void getAppBasicInfoTest() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/basic-info";
String url = baseUrl + "/api/v1/normal/apps/{appId}/basic-info";
// 查询结果不为空
getAppBasicInfo2ResultNotEmptyTest(url);
@@ -68,9 +131,9 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppBasicInfo2ResultNotEmptyTest(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -80,9 +143,9 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppBasicInfo2ResultEmptyTest(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.INVALID_APPID);
urlVariables.put("appId", ConfigConstant.INVALID_STRING);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -93,7 +156,7 @@ public class NormalAppControllerTest extends BaseTest {
@Test(description = "测试修改app")
public void modifyApp() {
String url = Constant.BASE_URL + "/api/v1/normal/apps";
String url = baseUrl + "/api/v1/normal/apps";
// 修改成功
modifyApp2SuccessTest(url);
// 传的dto为空, 修改不成功
@@ -102,7 +165,6 @@ public class NormalAppControllerTest extends BaseTest {
private void modifyApp2SuccessTest(String url) {
AppDTO appDTO = getAppDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<AppDTO> httpEntity =
new HttpEntity<>(appDTO, httpHeaders);
@@ -115,7 +177,6 @@ public class NormalAppControllerTest extends BaseTest {
private void modifyApp2FailureTest(String url) {
AppDTO appDTO = new AppDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<AppDTO> httpEntity =
new HttpEntity<>(appDTO, httpHeaders);
@@ -128,7 +189,7 @@ public class NormalAppControllerTest extends BaseTest {
@Test(description = "测试获取有权限的Topic信息")
public void getAppTopicsTest() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/topics";
String url = baseUrl + "/api/v1/normal/apps/{appId}/topics";
// 参数appId
getAppTopics1Test(url);
// 参数有appIdmine=true
@@ -140,9 +201,9 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppTopics1Test(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -153,9 +214,9 @@ public class NormalAppControllerTest extends BaseTest {
private void getAppTopics2Test(String url) {
url = url + "?mine=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -165,9 +226,9 @@ public class NormalAppControllerTest extends BaseTest {
private void getAppTopics3Test(String url) {
url = url + "?mine=false";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -177,9 +238,9 @@ public class NormalAppControllerTest extends BaseTest {
private void getAppTopics4Test(String url) {
url = url + "?mine=false";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.INVALID_APPID);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -189,7 +250,7 @@ public class NormalAppControllerTest extends BaseTest {
@Test(description = "测试Quota查询")
public void getAppIdQuotaTest() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/quotas";
String url = baseUrl + "/api/v1/normal/apps/{appId}/quotas";
// appId不为空clusterId和topicName在数据库中真实存在isPhysicalClusterId=true
getAppIdQuota1Test(url);
// appId无效
@@ -201,11 +262,11 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdQuota1Test(String url) {
url = url + "?clusterId=" + Constant.PHYSICAL_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.TOPIC_NAME_IN_MYSQL + "&isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
url = url + "?clusterId=" + physicalClusterId + "&topicName=" +
configMap.get(ConfigConstant.TOPIC_NAME) + "&isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -214,11 +275,11 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdQuota2Test(String url) {
url = url + "?clusterId=" + Constant.PHYSICAL_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.TOPIC_NAME_IN_MYSQL + "&isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
url = url + "?clusterId=" + physicalClusterId + "&topicName=" +
configMap.get(ConfigConstant.TOPIC_NAME) + "&isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.INVALID_APPID);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -227,11 +288,11 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdQuota3Test(String url) {
url = url + "?clusterId=" + Constant.PHYSICAL_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.INVALID_TOPIC_NAME + "&isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
url = url + "?clusterId=" + physicalClusterId + "&topicName=" +
ConfigConstant.INVALID_STRING + "&isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -240,11 +301,11 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdQuota4Test(String url) {
url = url + "?clusterId=" + Constant.INVALID_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.TOPIC_NAME_IN_MYSQL + "&isPhysicalClusterId=false";
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
url = url + "?clusterId=" + ConfigConstant.INVALID_CLUSTER_ID + "&topicName=" +
configMap.get(ConfigConstant.TOPIC_NAME) + "&isPhysicalClusterId=false";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -254,7 +315,7 @@ public class NormalAppControllerTest extends BaseTest {
@Test(description = "测试获取应用连接信息")
public void getAppIdConnectionsTest() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/connections";
String url = baseUrl + "/api/v1/normal/apps/{appId}/connections";
// appId存在数据库
getAppIdConnections1Test(url);
// appId不存在数据库
@@ -262,9 +323,9 @@ public class NormalAppControllerTest extends BaseTest {
}
public void getAppIdConnections1Test(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -274,9 +335,9 @@ public class NormalAppControllerTest extends BaseTest {
}
public void getAppIdConnections2Test(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", HttpUtils.getHttpHeaders());
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.INVALID_APPID);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -298,12 +359,12 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdAuthority1Test() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + Constant.LOGICAL_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.TOPIC_NAME_IN_MYSQL;
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
String url = baseUrl + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID) + "&topicName=" +
configMap.get(ConfigConstant.TOPIC_NAME);
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -312,12 +373,12 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdAuthority2Test() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + Constant.LOGICAL_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.TOPIC_NAME_IN_MYSQL;
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
String url = baseUrl + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID) + "&topicName=" +
configMap.get(ConfigConstant.TOPIC_NAME);
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.INVALID_APPID);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -326,12 +387,12 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdAuthority3Test() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + Constant.INVALID_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.TOPIC_NAME_IN_MYSQL;
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
String url = baseUrl + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" +ConfigConstant.INVALID_CLUSTER_ID + "&topicName=" +
configMap.get(ConfigConstant.TOPIC_NAME);
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -340,12 +401,12 @@ public class NormalAppControllerTest extends BaseTest {
}
private void getAppIdAuthority4Test() {
String url = Constant.BASE_URL + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + Constant.LOGICAL_CLUSTER_ID_IN_MYSQL + "&topicName=" +
Constant.INVALID_TOPIC_NAME;
HttpEntity<String> httpEntity = new HttpEntity<>(null, HttpUtils.getHttpHeaders());
String url = baseUrl + "/api/v1/normal/apps/{appId}/authorities";
url = url + "?clusterId=" + configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID) + "&topicName=" +
ConfigConstant.INVALID_STRING;
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("appId", Constant.APPID_IN_MYSQL);
urlVariables.put("appId", configMap.get(ConfigConstant.APPID));
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());

View File

@@ -0,0 +1,46 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class NormalBillControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试用户账单概览")
public void getBillStaffSummaryTest() {
Long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/normal/bills/staff-summary?startTime=0&endTime=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试用户账单详情")
public void getBillStaffDetailTest() {
Long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/normal/bills/staff-detail?timestamp=0" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -3,26 +3,37 @@ package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.Constant;
import com.xiaojukeji.kafka.manager.web.config.HttpUtils;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/1/14
*/
public class NormalClusterControllerTest extends BaseTest {
private final TestRestTemplate testRestTemplate = new TestRestTemplate();
private Long logicalClusterId;
@BeforeClass
public void init() {
super.init();
logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
}
@Test(description = "测试获取集群列表")
public void getLogicClusterVOListTest() {
String url = Constant.BASE_URL + "/api/v1/normal/clusters/basic-info";
String url = baseUrl + "/api/v1/normal/clusters/basic-info";
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -33,11 +44,123 @@ public class NormalClusterControllerTest extends BaseTest {
@Test(description = "测试由逻辑集群id获取集群")
public void getLogicClusterVOByIdTest() {
String url = Constant.BASE_URL + "/api/v1/normal/clusters/{logicalClusterId}/basic-info";
// 获取成功
getLogicClusterVOById1();
// 集群不存在
getLogicClusterVOById2();
}
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
private void getLogicClusterVOById1() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/basic-info";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void getLogicClusterVOById2() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/basic-info";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", ConfigConstant.INVALID_CLUSTER_ID);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.CLUSTER_NOT_EXIST.getCode());
}
@Test(description = "测试由逻辑集群id获取集群元信息列表")
public void getBrokerMetadataTest() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/broker-metadata";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群id获取集群")
public void getBrokersTest() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/brokers";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群id获取集群实时流量")
public void getMetricsTest() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/metrics";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群id获取集群历史流量")
public void getMetricsHistoryTest() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/metrics-history?startTime=0&endTime=" + now;
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群id获取集群限流信息")
public void getThrottlesTest() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/throttles";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群id获取集群topic元信息列表")
public void getTopicMetadataTest() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/topic-metadata";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群id获取集群列表")
public void getTopicsTest() {
String url = baseUrl + "/api/v1/normal/clusters/{logicalClusterId}/topics";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("logicalClusterId", logicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());

View File

@@ -0,0 +1,74 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class NormalConfigControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试获取集群套餐")
public void getClusterCombos() {
String url = baseUrl + "/api/v1/normal/configs/cluster-combos";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取集群套餐")
public void getClusterModes() {
String url = baseUrl + "/api/v1/normal/configs/cluster-combos";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取数据中心")
public void getIdc() {
String url = baseUrl + "/api/v1/normal/configs/idc";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取峰值状态")
public void getPeakFlowStatus() {
String url = baseUrl + "/api/v1/normal/configs/peak-flow-status";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取峰值状态")
public void getTaskStatus() {
String url = baseUrl + "/api/v1/normal/configs/task-status";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,22 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.testng.annotations.BeforeClass;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class NormalOrderControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
private void createOrderSuccess() {
}
}

View File

@@ -0,0 +1,274 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.normal.TopicDataSampleDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class NormalTopicControllerTest extends BaseTest {
private String topicName;
@BeforeClass
public void init() {
super.init();
// 成功创建Topic
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
topicName = configMap.get(ConfigConstant.TOPIC_NAME);
}
@AfterClass
public void afterTest() {
// 删除Topic成功
String url = baseUrl + "/api/v1/op/topics";
deleteTopics(url);
}
private void createCommonTopic(String url) {
// 创建Topic
TopicCreationDTO creationDTO = CustomDataSource.getTopicCreationDTO(configMap);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void deleteTopics(String url) {
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = CustomDataSource.getTopicDeletionDTO(configMap);
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试Topic有权限的应用信息")
public void getApps() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/apps?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic基本信息")
public void getBasicInfo() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/basic-info?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic账单信息")
public void getTopicBills() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/basic-info?" +
"isPhysicalClusterId=true&startTime=0&endTime=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic业务信息")
public void getBusiness() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/business?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic连接信息")
public void getConnection() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/connections?isPhysicalClusterId=true" +
"&appId=" + configMap.get(ConfigConstant.APPID);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic实时流量信息")
public void getMetrics() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/metrics?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic历史流量信息")
public void getMetricsHistory() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/metrics-history?isPhysicalClusterId=true" +
"&startTime=0&endTime=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic历史流量信息")
public void getMyApps() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/my-apps?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic分区信息")
public void getPartitions() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/partitions?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic实时请求耗时信息")
public void getRequestTime() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/request-time?isPhysicalClusterId=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic历史流量信息")
public void getRequestTimeHistory() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/request-time-history?isPhysicalClusterId=true" +
"&startTime=0&endTime=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic历史流量信息")
public void getSample() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/sample";
HttpEntity<TopicDataSampleDTO> httpEntity = new HttpEntity<>(getTopicDataSampleDTO(), httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private TopicDataSampleDTO getTopicDataSampleDTO() {
TopicDataSampleDTO topicDataSampleDTO = new TopicDataSampleDTO();
topicDataSampleDTO.setIsPhysicalClusterId(true);
topicDataSampleDTO.setOffset(0L);
topicDataSampleDTO.setTimeout(0);
topicDataSampleDTO.setMaxMsgNum(0);
topicDataSampleDTO.setTruncate(false);
topicDataSampleDTO.setPartitionId(0);
return topicDataSampleDTO;
}
@Test(description = "测试获取Topic流量统计信息")
public void getStatisticMetrics() {
String url = baseUrl + "/api/v1/normal/{clusterId}/topics/{topicName}/statistic-metrics?isPhysicalClusterId=true" +
"&latest-day=1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", topicName);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -2,53 +2,89 @@ package com.xiaojukeji.kafka.manager.web.api.versionone.op;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.openapi.common.dto.TopicAuthorityDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.Constant;
import com.xiaojukeji.kafka.manager.web.config.HttpUtils;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.List;
/**
* @author xuguang
* @Date 2022/1/11
*/
public class OpAuthorityControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
// 成功创建Topic
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic3Test(url);
}
@AfterClass
public void afterTest() {
// 删除Topic成功
String url = baseUrl + "/api/v1/op/topics";
deleteTopics3Test(url);
}
private void createCommonTopic3Test(String url) {
// 创建Topic
TopicCreationDTO creationDTO = CustomDataSource.getTopicCreationDTO(configMap);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void deleteTopics3Test(String url) {
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = CustomDataSource.getTopicDeletionDTO(configMap);
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private final TestRestTemplate testRestTemplate = new TestRestTemplate();
private TopicAuthorityDTO getTopicAuthorityDTO() {
TopicAuthorityDTO topicAuthorityDTO = new TopicAuthorityDTO();
topicAuthorityDTO.setClusterId(Constant.LOGICAL_CLUSTER_ID_IN_MYSQL);
topicAuthorityDTO.setTopicName(Constant.TOPIC_NAME_IN_MYSQL);
topicAuthorityDTO.setAppId(Constant.APPID_IN_MYSQL);
topicAuthorityDTO.setAccess(Constant.ACCESS);
long logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
topicAuthorityDTO.setClusterId(logicalClusterId);
topicAuthorityDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
topicAuthorityDTO.setAppId(configMap.get(ConfigConstant.APPID));
topicAuthorityDTO.setAccess(ConfigConstant.ACCESS);
return topicAuthorityDTO;
}
@Test(description = "测试权限调整")
public void addAuthorityTest() {
String url = Constant.BASE_URL + "/topic-authorities";
String url = baseUrl + "/topic-authorities";
addAuthority1Test(url);
// cluster not exist
addAuthority2Test(url);
// param illegal
addAuthority3Test(url);
// app not exist
addAuthority4Test(url);
// topic not exist
addAuthority5Test(url);
// mysqlError, 权限一致,无法插入
addAuthority6Test(url);
}
private void addAuthority1Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<TopicAuthorityDTO> httpEntity =
new HttpEntity<>(topicAuthorityDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
@@ -57,73 +93,4 @@ public class OpAuthorityControllerTest extends BaseTest {
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void addAuthority2Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
topicAuthorityDTO.setClusterId(Constant.INVALID_CLUSTER_ID_IN_MYSQL);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<TopicAuthorityDTO> httpEntity =
new HttpEntity<>(topicAuthorityDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.CLUSTER_NOT_EXIST.getCode());
}
private void addAuthority3Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
topicAuthorityDTO.setClusterId(Constant.INVALID_ID);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<TopicAuthorityDTO> httpEntity =
new HttpEntity<>(topicAuthorityDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void addAuthority4Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
topicAuthorityDTO.setAppId(Constant.INVALID_APPID);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<TopicAuthorityDTO> httpEntity =
new HttpEntity<>(topicAuthorityDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.APP_NOT_EXIST.getCode());
}
private void addAuthority5Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
topicAuthorityDTO.setTopicName(Constant.INVALID_TOPIC_NAME);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<TopicAuthorityDTO> httpEntity =
new HttpEntity<>(topicAuthorityDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.TOPIC_NOT_EXIST.getCode());
}
private void addAuthority6Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<TopicAuthorityDTO> httpEntity =
new HttpEntity<>(topicAuthorityDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.MYSQL_ERROR.getCode());
}
}

View File

@@ -7,13 +7,11 @@ import com.xiaojukeji.kafka.manager.common.entity.dto.op.ControllerPreferredCand
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.ClusterDTO;
import com.xiaojukeji.kafka.manager.common.entity.vo.rd.cluster.ClusterDetailVO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.Constant;
import com.xiaojukeji.kafka.manager.web.config.HttpUtils;
import org.springframework.boot.test.web.client.TestRestTemplate;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.*;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
@@ -27,26 +25,26 @@ import java.util.Map;
*/
public class OpClusterControllerTest extends BaseTest {
private final TestRestTemplate testRestTemplate = new TestRestTemplate();
@BeforeClass
public void init() {
super.init();
@BeforeMethod
public void addNewCluster() {
String url = Constant.BASE_URL + "/api/v1/op/clusters";
String url = baseUrl + "/api/v1/op/clusters";
// 接入成功
addnewCluster1Test(url);
addNewCluter1Test(url);
}
@AfterMethod
@AfterClass
public void deleteCluster() {
String url = Constant.BASE_URL + "/api/v1/op/clusters";
String url = baseUrl + "/api/v1/op/clusters";
// 删除集群成功
deleteCluster1Test(url);
}
private Long getPhysicalClusterId() {
String url = Constant.BASE_URL + "/api/v1/rd/clusters/basic-info?need-detail=true";
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
String url = baseUrl + "/api/v1/rd/clusters/basic-info?need-detail=true";
String clusterName = configMap.get(ConfigConstant.CLUSTER_NAME);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
@@ -54,7 +52,7 @@ public class OpClusterControllerTest extends BaseTest {
String s = JSON.toJSONString(result.getBody().getData());
List<ClusterDetailVO> clusterDetailVOS = JSON.parseArray(s, ClusterDetailVO.class);
for (ClusterDetailVO clusterDetailVO : clusterDetailVOS) {
if (clusterDetailVO.getClusterName().equals(Constant.CLUSTER_NAME)) {
if (clusterDetailVO.getClusterName().equals(clusterName)) {
return clusterDetailVO.getClusterId();
}
}
@@ -65,28 +63,27 @@ public class OpClusterControllerTest extends BaseTest {
ClusterDTO clusterDTO = new ClusterDTO();
Long physicalClusterId = getPhysicalClusterId();
clusterDTO.setClusterId(physicalClusterId);
clusterDTO.setClusterName(Constant.CLUSTER_NAME);
clusterDTO.setZookeeper(Constant.ZK_ADDRESS);
clusterDTO.setBootstrapServers(Constant.BOOTSTRAP_SERVERS);
clusterDTO.setIdc(Constant.IDC);
clusterDTO.setClusterName(configMap.get(ConfigConstant.CLUSTER_NAME));
clusterDTO.setZookeeper(configMap.get(ConfigConstant.ZOOKEEPER_ADDRESS));
clusterDTO.setBootstrapServers(configMap.get(ConfigConstant.BOOTSTRAP_ADDRESS));
clusterDTO.setIdc(ConfigConstant.IDC);
return clusterDTO;
}
@Test(description = "测试接入集群")
public void addNewClusterTest() {
String url = Constant.BASE_URL + "/api/v1/op/clusters";
String url = baseUrl + "/api/v1/op/clusters";
// 参数无效
addnewCluster2Test(url);
addNewCluster2Test(url);
// 无效的zk地址
addnewCluster3Test(url);
addNewCluster3Test(url);
// 重复创建
addnewCluster4Test(url);
addNewCluster4Test(url);
}
private void addnewCluster1Test(String url) {
private void addNewCluter1Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -97,10 +94,9 @@ public class OpClusterControllerTest extends BaseTest {
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void addnewCluster2Test(String url) {
private void addNewCluster2Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setZookeeper(null);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -111,10 +107,9 @@ public class OpClusterControllerTest extends BaseTest {
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void addnewCluster3Test(String url) {
private void addNewCluster3Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setZookeeper(Constant.INVALID);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
clusterDTO.setZookeeper(ConfigConstant.INVALID_STRING);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -125,9 +120,8 @@ public class OpClusterControllerTest extends BaseTest {
Assert.assertEquals(result.getBody().getCode(), ResultStatus.ZOOKEEPER_CONNECT_FAILED.getCode());
}
private void addnewCluster4Test(String url) {
private void addNewCluster4Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -140,7 +134,7 @@ public class OpClusterControllerTest extends BaseTest {
@Test(description = "测试修改物理集群")
public void modifyClusterTest() {
String url = Constant.BASE_URL + "/api/v1/op/clusters";
String url = baseUrl + "/api/v1/op/clusters";
// 修改成功
modifyCluster1Test(url);
// 参数错误
@@ -153,7 +147,6 @@ public class OpClusterControllerTest extends BaseTest {
private void modifyCluster1Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -167,7 +160,6 @@ public class OpClusterControllerTest extends BaseTest {
private void modifyCluster2Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setClusterId(null);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -180,8 +172,7 @@ public class OpClusterControllerTest extends BaseTest {
private void modifyCluster3Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setClusterId(Constant.INVALID_CLUSTER_ID_IN_MYSQL);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
clusterDTO.setClusterId(ConfigConstant.INVALID_CLUSTER_ID);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -194,8 +185,7 @@ public class OpClusterControllerTest extends BaseTest {
private void modifyCluster4Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setZookeeper(Constant.INVALID);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
clusterDTO.setZookeeper(ConfigConstant.INVALID_STRING);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, httpHeaders);
@@ -208,7 +198,7 @@ public class OpClusterControllerTest extends BaseTest {
@Test(description = "测试开启|关闭集群监控")
public void clusterMonitorTest() {
String url = Constant.BASE_URL + "/api/v1/op/clusters/{clusterId}/monitor";
String url = baseUrl + "/api/v1/op/clusters/{clusterId}/monitor";
// 监控关闭成功
clusterMonitor1Test(url);
// 监控开启成功
@@ -219,7 +209,6 @@ public class OpClusterControllerTest extends BaseTest {
private void clusterMonitor1Test(String url) {
url = url + "?status=0";
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
@@ -234,7 +223,6 @@ public class OpClusterControllerTest extends BaseTest {
private void clusterMonitor2Test(String url) {
url = url + "?status=1";
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
@@ -249,11 +237,10 @@ public class OpClusterControllerTest extends BaseTest {
private void clusterMonitor3Test(String url) {
url = url + "?status=1";
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", Constant.INVALID_ID);
urlVariables.put("clusterId", ConfigConstant.INVALID_CLUSTER_ID);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.PUT, httpEntity, Result.class, urlVariables);
@@ -264,21 +251,22 @@ public class OpClusterControllerTest extends BaseTest {
@Test(description = "测试增加Controller优先候选的Broker")
public void addControllerPreferredCandidatesTest() {
String url = Constant.BASE_URL + "/api/v1/op/cluster-controller/preferred-candidates";
String url = baseUrl + "/api/v1/op/cluster-controller/preferred-candidates";
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
// 增加成功
addControllerPreferredCandidates1Test(url);
addControllerPreferredCandidates1Test(url, physicalClusterId);
// broker不存在
addControllerPreferredCandidates2Test(url);
addControllerPreferredCandidates2Test(url, physicalClusterId);
// 参数错误
addControllerPreferredCandidates3Test(url);
addControllerPreferredCandidates3Test(url, physicalClusterId);
}
private void addControllerPreferredCandidates1Test(String url) {
private void addControllerPreferredCandidates1Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(getPhysicalClusterId());
dto.setBrokerIdList(Arrays.asList(Constant.ALIVE_BROKER_ID));
dto.setClusterId(physicalClusterId);
String aliveBrokerId = configMap.get(ConfigConstant.ALIVE_BROKER_ID);
dto.setBrokerIdList(Arrays.asList(Integer.parseInt(aliveBrokerId)));
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, httpHeaders);
@@ -289,12 +277,11 @@ public class OpClusterControllerTest extends BaseTest {
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void addControllerPreferredCandidates2Test(String url) {
private void addControllerPreferredCandidates2Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(getPhysicalClusterId());
dto.setBrokerIdList(Arrays.asList(-1));
dto.setClusterId(physicalClusterId);
dto.setBrokerIdList(Arrays.asList(ConfigConstant.INVALID_BROKER_ID));
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, httpHeaders);
@@ -305,11 +292,10 @@ public class OpClusterControllerTest extends BaseTest {
Assert.assertEquals(result.getBody().getCode(), ResultStatus.BROKER_NOT_EXIST.getCode());
}
private void addControllerPreferredCandidates3Test(String url) {
private void addControllerPreferredCandidates3Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(getPhysicalClusterId());
dto.setClusterId(physicalClusterId);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, httpHeaders);
@@ -323,19 +309,20 @@ public class OpClusterControllerTest extends BaseTest {
@Test(description = "测试删除Controller优先候选的Broker")
public void deleteControllerPreferredCandidatesTest() {
String url = Constant.BASE_URL + "/api/v1/op/cluster-controller/preferred-candidates";
String url = baseUrl + "/api/v1/op/cluster-controller/preferred-candidates";
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
// 删除成功
deleteControllerPreferredCandidates1Test(url);
deleteControllerPreferredCandidates1Test(url, physicalClusterId);
// 参数错误
deleteControllerPreferredCandidates2Test(url);
deleteControllerPreferredCandidates2Test(url, physicalClusterId);
}
private void deleteControllerPreferredCandidates1Test(String url) {
private void deleteControllerPreferredCandidates1Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(getPhysicalClusterId());
dto.setBrokerIdList(Arrays.asList(Constant.ALIVE_BROKER_ID));
dto.setClusterId(physicalClusterId);
String aliveBrokerId = configMap.get(ConfigConstant.ALIVE_BROKER_ID);
dto.setBrokerIdList(Arrays.asList(Integer.parseInt(aliveBrokerId)));
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, httpHeaders);
@@ -346,11 +333,10 @@ public class OpClusterControllerTest extends BaseTest {
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void deleteControllerPreferredCandidates2Test(String url) {
private void deleteControllerPreferredCandidates2Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(getPhysicalClusterId());
dto.setClusterId(physicalClusterId);
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, httpHeaders);
@@ -363,7 +349,7 @@ public class OpClusterControllerTest extends BaseTest {
@Test(description = "测试删除物理集群")
public void deleteClusterTest() {
String url = Constant.BASE_URL + "/api/v1/op/clusters";
String url = baseUrl + "/api/v1/op/clusters";
// 集群不存在
deleteCluster2Test(url);
}
@@ -371,7 +357,6 @@ public class OpClusterControllerTest extends BaseTest {
private void deleteCluster1Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
url = url + "?clusterId=" + clusterDTO.getClusterId();
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
@@ -382,8 +367,7 @@ public class OpClusterControllerTest extends BaseTest {
}
private void deleteCluster2Test(String url) {
url = url + "?clusterId=" + Constant.INVALID_CLUSTER_ID_IN_MYSQL;
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
url = url + "?clusterId=" + ConfigConstant.INVALID_CLUSTER_ID;
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);

View File

@@ -0,0 +1,65 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.op;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class OpExpertControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试查询热点Topic")
public void getHotTopics() {
String url = baseUrl + "/api/v1/op/expert/regions/hot-topics";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试Topic流量异常诊断")
public void getAnomalyFlow() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/op/expert/topics/anomaly-flow?timestamp=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取过期Topic")
public void getExpiredTopic() {
String url = baseUrl + "/api/v1/op/expert/topics/expired";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic分区不足")
public void getInsufficientPartitions() {
String url = baseUrl + "/api/v1/op/expert/topics/insufficient-partitions";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,276 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.op;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicExpansionDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicModificationDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author wyc
* @date 2022/1/20
*/
public class OpTopicControllerTest extends BaseTest {
/**
* Topic保存时间
*/
private static final Long RETENTION_TIME = 1000L * 60 * 60 * 168;
@BeforeClass
public void init() {
super.init();
// 成功创建Topic
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@AfterClass
public void afterTest() {
// 删除Topic成功
String url = baseUrl + "/api/v1/op/topics";
deleteTopics(url);
}
private TopicCreationDTO getTopicCreationDTO() {
// 在broker1上创建1分区1副本的createTopicTest
TopicCreationDTO creationDTO = new TopicCreationDTO();
creationDTO.setAppId(configMap.get(ConfigConstant.APPID));
// 在broker1上创建
Integer brokerId = Integer.parseInt(configMap.get(ConfigConstant.ALIVE_BROKER_ID));
creationDTO.setBrokerIdList(Arrays.asList(brokerId));
creationDTO.setPartitionNum(1);
creationDTO.setReplicaNum(1);
creationDTO.setRetentionTime(RETENTION_TIME);
creationDTO.setPeakBytesIn(10L * 1024 * 1024);
// 物理集群id
creationDTO.setClusterId(physicalClusterId);
creationDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
return creationDTO;
}
private TopicDeletionDTO getTopicDeletionDTO() {
TopicDeletionDTO deletionDTO = new TopicDeletionDTO();
deletionDTO.setClusterId(physicalClusterId);
deletionDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
deletionDTO.setUnForce(true);
return deletionDTO;
}
@Test
public void createCommonTopicTest() {
String url = baseUrl + "/api/v1/op/topics";
// PARAM_ILLEGAL
createCommonTopic1Test(url);
// CLUSTER_NOT_EXIST
createCommonTopic2Test(url);
}
private void createCommonTopic1Test(String url) {
TopicCreationDTO creationDTO = getTopicCreationDTO();
creationDTO.setClusterId(null);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void createCommonTopic2Test(String url) {
TopicCreationDTO creationDTO = getTopicCreationDTO();
creationDTO.setClusterId(-1L);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.CLUSTER_NOT_EXIST.getCode());
}
private void createCommonTopic(String url) {
// 创建Topic
TopicCreationDTO creationDTO = CustomDataSource.getTopicCreationDTO(configMap);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test
public void deleteTopicsTest() {
String url = baseUrl + "/api/v1/op/topics";
// PARAM_ILLEGAL
deleteTopics1Test(url);
// OPERATION_FAILED
deleteTopics2Test(url);
}
private void deleteTopics1Test(String url) {
ArrayList<TopicDeletionDTO> deletionDTOArrayList = new ArrayList<>();
for (int i = 0; i < 11; i++) {
deletionDTOArrayList.add(getTopicDeletionDTO());
}
HttpEntity<List<TopicDeletionDTO>> httpEntity = new HttpEntity<>(deletionDTOArrayList, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void deleteTopics2Test(String url) {
TopicDeletionDTO topicDeletionDTO = getTopicDeletionDTO();
topicDeletionDTO.setClusterId(ConfigConstant.INVALID_CLUSTER_ID);
HttpEntity<List<TopicDeletionDTO>> httpEntity = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.OPERATION_FAILED.getCode());
}
private void deleteTopics(String url) {
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = CustomDataSource.getTopicDeletionDTO(configMap);
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private TopicModificationDTO getTopicModificationDTO() {
TopicModificationDTO modificationDTO = new TopicModificationDTO();
modificationDTO.setAppId(configMap.get(ConfigConstant.APPID));
modificationDTO.setClusterId(physicalClusterId);
modificationDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
modificationDTO.setRetentionTime(RETENTION_TIME);
modificationDTO.setDescription("");
return modificationDTO;
}
@Test(description = "测试修改Topic")
public void modifyTopicTest() {
String url = baseUrl + "/api/v1/op/topics";
// paramIllegal
modifyTopic1Test(url);
// cluster not exist
modifyTopic2Test(url);
// topic未知
modifyTopic3Test(url);
// 修改成功
modifyTopic4Test(url);
}
public void modifyTopic1Test(String url) {
// 修改topic
TopicModificationDTO topicModificationDTO = getTopicModificationDTO();
topicModificationDTO.setTopicName(null);
HttpEntity<TopicModificationDTO> httpEntity = new HttpEntity<>(topicModificationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
public void modifyTopic2Test(String url) {
// 修改topic
TopicModificationDTO topicModificationDTO = getTopicModificationDTO();
topicModificationDTO.setClusterId(ConfigConstant.INVALID_CLUSTER_ID);
HttpEntity<TopicModificationDTO> httpEntity = new HttpEntity<>(topicModificationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.CLUSTER_NOT_EXIST.getCode());
}
public void modifyTopic3Test(String url) {
// 修改topic
TopicModificationDTO topicModificationDTO = getTopicModificationDTO();
topicModificationDTO.setTopicName(ConfigConstant.INVALID_STRING);
HttpEntity<TopicModificationDTO> httpEntity = new HttpEntity<>(topicModificationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.TOPIC_OPERATION_UNKNOWN_TOPIC_PARTITION.getCode());
}
public void modifyTopic4Test(String url) {
// 修改topic
TopicModificationDTO topicModificationDTO = getTopicModificationDTO();
HttpEntity<TopicModificationDTO> httpEntity = new HttpEntity<>(topicModificationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private TopicExpansionDTO getTopicExpansionDTO() {
TopicExpansionDTO topicExpansionDTO= new TopicExpansionDTO();
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
topicExpansionDTO.setClusterId(physicalClusterId);
topicExpansionDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
topicExpansionDTO.setPartitionNum(2);
Integer brokerId = Integer.parseInt(configMap.get(ConfigConstant.ALIVE_BROKER_ID));
topicExpansionDTO.setBrokerIdList(Arrays.asList(brokerId));
return topicExpansionDTO;
}
@Test(description = "测试Topic扩分区")
public void expandTopicPartitionTest() {
String url = baseUrl + "/api/v1/op/topics/expand-partitions";
// operation failed
expandTopicPartition1Test(url);
// success
expandTopicPartition2Test(url);
}
private void expandTopicPartition1Test(String url) {
// topic扩分区
TopicExpansionDTO topicExpansionDTO = getTopicExpansionDTO();
topicExpansionDTO.setClusterId(null);
HttpEntity<List<TopicExpansionDTO>> httpEntity = new HttpEntity<>(Arrays.asList(topicExpansionDTO), httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.OPERATION_FAILED.getCode());
}
private void expandTopicPartition2Test(String url) {
// topic扩分区
TopicExpansionDTO topicExpansionDTO = getTopicExpansionDTO();
HttpEntity<List<TopicExpansionDTO>> httpEntity = new HttpEntity<>(Arrays.asList(topicExpansionDTO), httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -1,201 +0,0 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.op;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicModificationDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.Constant;
import com.xiaojukeji.kafka.manager.web.config.HttpUtils;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.*;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author wyc
* @date 2022/1/20
*/
public class opTopicControllerTest extends BaseTest {
private final TestRestTemplate testRestTemplate = new TestRestTemplate();
private TopicCreationDTO getTopicCreationDTO() {
// 在broker1上创建1分区1副本的createTopicTest
TopicCreationDTO creationDTO = new TopicCreationDTO();
creationDTO.setAppId(Constant.APPID_IN_MYSQL);
// 在broker1上创建
creationDTO.setBrokerIdList(Arrays.asList(1));
creationDTO.setPartitionNum(1);
creationDTO.setReplicaNum(1);
creationDTO.setRetentionTime(1000L * 60 * 60 * 168);
creationDTO.setPeakBytesIn(10L * 1024 * 1024);
// 物理集群id
creationDTO.setClusterId(Constant.PHYSICAL_CLUSTER_ID_IN_MYSQL);
creationDTO.setTopicName("createTopicTest");
return creationDTO;
}
private TopicDeletionDTO getTopicDeletionDTO() {
TopicDeletionDTO deletionDTO = new TopicDeletionDTO();
deletionDTO.setClusterId(1L);
deletionDTO.setTopicName("createTopicTest");
deletionDTO.setUnForce(true);
return deletionDTO;
}
@Test
public void createCommonTopicTest() {
String url = Constant.BASE_URL + "/api/v1/op/topics";
// PARAM_ILLEGAL
createCommonTopic1Test(url);
// CLUSTER_NOT_EXIST
createCommonTopic2Test(url);
// SUCCESS
createCommonTopic3Test(url);
}
private void createCommonTopic1Test(String url) {
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
TopicCreationDTO creationDTO = getTopicCreationDTO();
creationDTO.setClusterId(null);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void createCommonTopic2Test(String url) {
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
TopicCreationDTO creationDTO = getTopicCreationDTO();
creationDTO.setClusterId(-1L);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.CLUSTER_NOT_EXIST.getCode());
}
private void createCommonTopic3Test(String url) {
// 创建Topic
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
TopicCreationDTO creationDTO = getTopicCreationDTO();
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = getTopicDeletionDTO();
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test
public void deleteTopicsTest() {
String url = Constant.BASE_URL + "/api/v1/op/topics";
// PARAM_ILLEGAL
deleteTopics1Test(url);
// OPERATION_FAILED
deleteTopics2Test(url);
// SUCCESS
deleteTopics3Test(url);
}
private void deleteTopics1Test(String url) {
ArrayList<TopicDeletionDTO> deletionDTOArrayList = new ArrayList<>();
for (int i = 0; i < 11; i++) {
deletionDTOArrayList.add(getTopicDeletionDTO());
}
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<List<TopicDeletionDTO>> httpEntity = new HttpEntity<>(deletionDTOArrayList, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void deleteTopics2Test(String url) {
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
TopicDeletionDTO topicDeletionDTO = getTopicDeletionDTO();
topicDeletionDTO.setClusterId(-1L);
HttpEntity<List<TopicDeletionDTO>> httpEntity = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.OPERATION_FAILED.getCode());
}
private void deleteTopics3Test(String url) {
// 创建Topic
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
TopicCreationDTO creationDTO = getTopicCreationDTO();
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = getTopicDeletionDTO();
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private TopicModificationDTO getTopicModificationDTO() {
TopicModificationDTO modificationDTO = new TopicModificationDTO();
modificationDTO.setAppId(Constant.APPID_IN_MYSQL);
modificationDTO.setClusterId(Constant.PHYSICAL_CLUSTER_ID_IN_MYSQL);
modificationDTO.setTopicName("createTopicName");
return modificationDTO;
}
public void modifyTopicTest() {
String url = Constant.BASE_URL + "/api/v1/op/topics";
}
public void modifyTopic1Test(String url) {
// 创建Topic
HttpHeaders httpHeaders = HttpUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
TopicCreationDTO creationDTO = getTopicCreationDTO();
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
// 修改topic
TopicModificationDTO topicModificationDTO = getTopicModificationDTO();
HttpEntity<TopicModificationDTO> httpEntity2 = new HttpEntity<>(topicModificationDTO, httpHeaders);
}
}

View File

@@ -0,0 +1,129 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.rd;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.config.ConfigDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class RdConfigControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
// 创建config
createConfigSuccess();
}
@AfterClass
public void destroy() {
// 删除config
deleteConfig();
}
@Test(description = "测试新增配置")
public void createConfigTest() {
// 参数错误
createConfig1();
}
private void createConfig1() {
String url = baseUrl + "/api/v1/rd/configs";
ConfigDTO configDTO = CustomDataSource.getConfigDTO();
configDTO.setConfigKey(null);
HttpEntity<ConfigDTO> httpEntity = new HttpEntity<>(configDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void createConfigSuccess() {
String url = baseUrl + "/api/v1/rd/configs";
ConfigDTO configDTO = CustomDataSource.getConfigDTO();
HttpEntity<ConfigDTO> httpEntity = new HttpEntity<>(configDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "删除配置")
public void deleteConfigTest() {
}
private void deleteConfig() {
String url = baseUrl + "/api/v1/rd/configs?config-key=" + ConfigConstant.CONFIG_KEY;
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试修改配置")
public void modifyConfigTest() {
// 参数错误
modifyConfig1();
// 修改成功
modifyConfig2();
}
private void modifyConfig1() {
String url = baseUrl + "/api/v1/rd/configs";
ConfigDTO configDTO = CustomDataSource.getConfigDTO();
configDTO.setConfigKey(null);
HttpEntity<ConfigDTO> httpEntity = new HttpEntity<>(configDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void modifyConfig2() {
String url = baseUrl + "/api/v1/rd/configs";
ConfigDTO configDTO = CustomDataSource.getConfigDTO();
HttpEntity<ConfigDTO> httpEntity = new HttpEntity<>(configDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取配置列表")
public void getConfigList() {
String url = baseUrl + "/api/v1/rd/configs";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获Kafka的角色列表")
public void getKafkaRoles() {
String url = baseUrl + "/api/v1/rd/configs/kafka-roles";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,207 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.rd;
import com.alibaba.fastjson.JSON;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.LogicalClusterDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.RegionDTO;
import com.xiaojukeji.kafka.manager.common.entity.vo.rd.RegionVO;
import com.xiaojukeji.kafka.manager.common.entity.vo.rd.cluster.LogicalClusterVO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/17
*/
public class RdLogicalClusterControllerTest extends BaseTest {
private Long regionId;
private Long logicalClusterId;
@BeforeClass
public void init() {
super.init();
// 创建region
createRegionSuccess();
// 获取regionId
regionId = getRegionId();
// 创建逻辑集群
createLogicalClusterSuccess();
logicalClusterId = getLogicalClusterId();
}
@AfterClass
public void destroy() {
deleteLogicalClusterSuccess();
deleteRegionSuccess();
}
@Test(description = "测试增加逻辑集群")
public void createLogicalClusterTest() {
String url = baseUrl + "/api/v1/rd/logical-clusters";
// 参数错误
createLogicalCluster1(url);
}
private void createLogicalCluster1(String url) {
LogicalClusterDTO logicalClusterDTO = CustomDataSource.getLogicalClusterDTO(configMap);
logicalClusterDTO.setRegionIdList(null);
HttpEntity<LogicalClusterDTO> httpEntity = new HttpEntity<>(logicalClusterDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void createLogicalClusterSuccess() {
String url = baseUrl + "/api/v1/rd/logical-clusters";
LogicalClusterDTO logicalClusterDTO = CustomDataSource.getLogicalClusterDTO(configMap);
logicalClusterDTO.setRegionIdList(Arrays.asList(regionId));
HttpEntity<LogicalClusterDTO> httpEntity = new HttpEntity<>(logicalClusterDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void createRegionSuccess() {
String url = baseUrl + "/api/v1/rd/regions";
RegionDTO regionDTO = CustomDataSource.getRegionDTO(configMap);
HttpEntity<RegionDTO> httpEntity = new HttpEntity<>(regionDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private Long getRegionId() {
String url = baseUrl + "/api/v1/rd/{clusterId}/regions";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
String s = JSON.toJSONString(result.getBody().getData());
List<RegionVO> regions = JSON.parseArray(s, RegionVO.class);
for (RegionVO region : regions) {
if (region.getName().equals(configMap.get(ConfigConstant.REGION_NAME))) {
return region.getId();
}
}
return null;
}
private Long getLogicalClusterId() {
String url = baseUrl + "/api/v1/rd/{physicalClusterId}/logical-clusters";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
String s = JSON.toJSONString(result.getBody().getData());
List<LogicalClusterVO> logicalClusters = JSON.parseArray(s, LogicalClusterVO.class);
for (LogicalClusterVO logicalCLuster : logicalClusters) {
if (logicalCLuster.getLogicalClusterName().equals(configMap.get(ConfigConstant.LOGICAL_CLUSTER_NAME))) {
return logicalCLuster.getLogicalClusterId();
}
}
return null;
}
@Test(description = "测试修改逻辑集群")
public void modifyLogicalClusterTest() {
// 参数失败
modifyLogicalCluster1();
// 修改成功
modifyLogicalCluster2();
}
private void modifyLogicalCluster1() {
String url = baseUrl + "/api/v1/rd/logical-clusters";
LogicalClusterDTO logicalClusterDTO = CustomDataSource.getLogicalClusterDTO(configMap);
logicalClusterDTO.setRegionIdList(Arrays.asList(regionId));
logicalClusterDTO.setId(null);
HttpEntity<LogicalClusterDTO> httpEntity = new HttpEntity<>(logicalClusterDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void modifyLogicalCluster2() {
String url = baseUrl + "/api/v1/rd/logical-clusters";
LogicalClusterDTO logicalClusterDTO = CustomDataSource.getLogicalClusterDTO(configMap);
logicalClusterDTO.setRegionIdList(Arrays.asList(regionId));
logicalClusterDTO.setId(getLogicalClusterId());
HttpEntity<LogicalClusterDTO> httpEntity = new HttpEntity<>(logicalClusterDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试删除逻辑集群")
public void deleteLogicalClusterTest() {
}
private void deleteLogicalClusterSuccess() {
String url = baseUrl + "/api/v1/rd/logical-clusters?id=" + logicalClusterId;
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void deleteRegionSuccess() {
Long regionId = getRegionId();
String url = baseUrl + "/api/v1/rd/regions?id=" + regionId;
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取逻辑集群列表")
public void getLogicalClustersTest() {
String url = baseUrl + "/api/v1/rd/{physicalClusterId}/logical-clusters";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试由逻辑集群Id获取逻辑集群")
public void getLogicalClusterTest() {
String url = baseUrl + "/api/v1/rd/logical-clusters?id=" + getLogicalClusterId();
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,145 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.rd;
import com.alibaba.fastjson.JSON;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.RegionDTO;
import com.xiaojukeji.kafka.manager.common.entity.vo.rd.RegionVO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
*/
public class RdRegionControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
// 创建region
createRegionSuccess();
}
@AfterClass
public void deleteRegion() {
// 删除region
deleteRegionSuccess();
}
private Long getRegionId() {
String url = baseUrl + "/api/v1/rd/{clusterId}/regions";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
String s = JSON.toJSONString(result.getBody().getData());
List<RegionVO> regions = JSON.parseArray(s, RegionVO.class);
for (RegionVO region : regions) {
if (region.getName().equals(configMap.get(ConfigConstant.REGION_NAME))) {
return region.getId();
}
}
return null;
}
@Test(description = "测试创建region")
public void createRegion() {
String url = baseUrl + "/api/v1/op/topics";
// 参数错误
createRegion1Test(url);
}
private void createRegion1Test(String url) {
RegionDTO regionDTO = CustomDataSource.getRegionDTO(configMap);
regionDTO.setClusterId(null);
HttpEntity<RegionDTO> httpEntity = new HttpEntity<>(regionDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void createRegionSuccess() {
String url = baseUrl + "/api/v1/rd/regions";
RegionDTO regionDTO = CustomDataSource.getRegionDTO(configMap);
HttpEntity<RegionDTO> httpEntity = new HttpEntity<>(regionDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试删除region")
public void deleteRegionTest() {
}
private void deleteRegionSuccess() {
Long regionId = getRegionId();
String url = baseUrl + "/api/v1/rd/regions?id=" + regionId;
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.DELETE, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试修改region")
public void modifyRegionTest() {
String url = baseUrl + "/api/v1/rd/regions";
// 参数错误
modifyRegion1(url);
// 修改成功
modifyRegion2(url);
}
private void modifyRegion1(String url) {
RegionDTO regionDTO = CustomDataSource.getRegionDTO(configMap);
regionDTO.setId(null);
HttpEntity<RegionDTO> httpEntity = new HttpEntity<>(regionDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.PARAM_ILLEGAL.getCode());
}
private void modifyRegion2(String url) {
RegionDTO regionDTO = CustomDataSource.getRegionDTO(configMap);
regionDTO.setId(getRegionId());
HttpEntity<RegionDTO> httpEntity = new HttpEntity<>(regionDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "获取region列表")
public void getRegionListTest() {
String url = baseUrl + "/api/v1/rd/{clusterId}/regions";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,39 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.thirdpart;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class ThirdPartAppControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试查询负责的应用")
public void getPrincipalAppsTest() {
String url = baseUrl + "/api/v1/third-part/principal-apps/{principal}/basic-info?system-code=" + ConfigConstant.KAFKA_MANAGER;
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("principal", "admin");
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,50 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.thirdpart;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class ThirdPartBrokerControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试获取BrokerRegion信息")
public void getBrokerRegionsTest() {
String url = baseUrl + "/api/v1/third-part/op/broker-regions";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Broker信息概览")
public void getBrokerOverviewTest() {
String url = baseUrl + "/api/v1/third-part/op/{clusterId}/brokers/{brokerId}/overview";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,39 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.thirdpart;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class ThirdPartClusterControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试Broker信息概览")
public void getBrokerRegionsTest() {
String url = baseUrl + "/api/v1/third-part/{clusterId}/broker-stabled?hostname=" + ConfigConstant.INVALID_STRING;
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.BROKER_NOT_EXIST.getCode());
}
}

View File

@@ -0,0 +1,147 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.thirdpart;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class ThirdPartTopicControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
// 成功创建Topic
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic3Test(url);
}
@AfterClass
public void afterTest() {
// 删除Topic成功
String url = baseUrl + "/api/v1/op/topics";
deleteTopics3Test(url);
}
private void createCommonTopic3Test(String url) {
// 创建Topic
TopicCreationDTO creationDTO = CustomDataSource.getTopicCreationDTO(configMap);
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void deleteTopics3Test(String url) {
// 删除创建的topic
TopicDeletionDTO topicDeletionDTO = CustomDataSource.getTopicDeletionDTO(configMap);
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic元信息")
public void getTopicMetadataTest() {
String url = baseUrl + "/api/v1/third-part/clusters/{clusterId}/topics/{topicName}/metadata";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取Topic应用信息")
public void getTopicAppsTest() {
String url = baseUrl + "/api/v1/third-part/{physicalClusterId}/topics/{topicName}/apps";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试查询Topic的消费组列表")
public void getTopicConsumerGroupsTest() {
String url = baseUrl + "/api/v1/third-part/{physicalClusterId}/topics/{topicName}/consumer-groups";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试查询Topic实时流量信息")
public void getTopicMetricsTest() {
String url = baseUrl + "/api/v1/third-part/{physicalClusterId}/topics/{topicName}/metrics";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试查询Topic是否有流量")
public void getTopicOffsetChangedTest() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/third-part/{physicalClusterId}/topics/{topicName}/offset-changed?latest-time=" + now;
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试查询Topic实时请求耗时信息")
public void getTopicRequestTimeTest() {
String url = baseUrl + "/api/v1/third-part/{physicalClusterId}/topics/{topicName}/request-time";
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -1,7 +1,40 @@
package com.xiaojukeji.kafka.manager.web.config;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import java.io.IOException;
import java.util.Map;
public class BaseTest extends AbstractTestNGSpringContextTests {
protected final TestRestTemplate testRestTemplate = new TestRestTemplate();
protected Map<String, String> configMap;
protected HttpHeaders httpHeaders;
protected String baseUrl = "http://localhost:8080";
// 默认物理集群Id为1
protected Long physicalClusterId = 1L;
public void init() {
// 加载本地配置
try {
configMap = CommonUtils.readSettings();
httpHeaders = CommonUtils.getHttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
baseUrl = configMap.get(ConfigConstant.BASE_URL);
physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,49 @@
package com.xiaojukeji.kafka.manager.web.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* @author xuguang
* @Date 2022/1/11
*/
public class CommonUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(CommonUtils.class.getName());
private static String settingsFile = "integrationTest-settings.properties";
public static HttpHeaders getHttpHeaders() {
// 需要在管控平台上配置教程见docs -> user_guide -> call_api_bypass_login
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(ConfigConstant.TRICK_LOGIN_SWITCH, ConfigConstant.OPEN_TRICK_LOGIN);
httpHeaders.add(ConfigConstant.TRICK_LOGIN_USER, ConfigConstant.ADMIN_USER);
return httpHeaders;
}
/**
* 读取本地配置
*
* @return
* @throws IOException
*/
public static Map<String, String> readSettings() throws IOException {
InputStream is = CommonUtils.class.getClassLoader().getResourceAsStream(settingsFile);
Properties prop = new Properties();
try {
prop.load(is);
} catch (IOException e) {
LOGGER.error("CommonUtil error!", "load " + settingsFile + " error, {}", e.getMessage());
} finally {
is.close();
}
return new HashMap<String, String>((Map) prop);
}
}

View File

@@ -0,0 +1,87 @@
package com.xiaojukeji.kafka.manager.web.config;
/**
* 集成测试配置变量
* @author xuguang
* @Date 2022/1/11
*/
public interface ConfigConstant {
/**
* 本地配置属性
*/
String BASE_URL = "base-url";
String CLUSTER_NAME = "cluster.name";
String ZOOKEEPER_ADDRESS = "cluster.zookeeper.address";
String BOOTSTRAP_ADDRESS = "cluster.bootstrap.address";
String ALIVE_BROKER_ID = "alive-brokerId";
String PHYSICAL_CLUSTER_ID = "physicalCluster.id.in.mysql";
String LOGICAL_CLUSTER_ID = "logicalCluster.id.in.mysql";
String LOGICAL_CLUSTER_NAME = "logicalCluster.name";
String TOPIC_NAME = "topic.name";
String APPID = "appId";
String REGION_NAME = "region.name";
String GATEWAY_TYPE = "gateway.config.type";
String GATEWAY_NAME = "gateway.config.name";
String GATEWAY_VALUE = "gateway.config.value";
String GATEWAY_DESCRIPTION = "gateway.config.description";
/**
* 登陆参数
*/
String TRICK_LOGIN_SWITCH = "Trick-Login-Switch";
String TRICK_LOGIN_USER = "Trick-Login-User";
String OPEN_TRICK_LOGIN = "on";
/**
* 管理员用户
*/
String ADMIN_USER = "admin";
/**
* 无效字符串
*/
String INVALID_STRING = "%_";
/**
* 无效集群id
*/
Long INVALID_CLUSTER_ID = Long.MAX_VALUE;
/**
* 无效broker id
*/
Integer INVALID_BROKER_ID = -1;
/**
* 数据中心
*/
String IDC = "cn";
String CONFIG_KEY = "key";
String CONFIG_VALUE = "value";
String KAFKA_MANAGER = "kafka-manager";
/**
* 操作权限
*/
Integer ACCESS = 100;
}

View File

@@ -1,74 +0,0 @@
package com.xiaojukeji.kafka.manager.web.config;
/**
* @author xuguang
* @Date 2022/1/11
*/
public class Constant {
public static final String BASE_URL = "http://localhost:8080";
public static final String TRICK_LOGIN_SWITCH = "Trick-Login-Switch";
public static final String TRICK_LOGIN_USER = "Trick-Login-User";
/**
* on表示开启trick_login
*/
public static final String ON = "on";
/**
* 数据库中实际存在的user
*/
public static final String USER_ADMIN = "admin";
/**
* 数据库中实际存在的APPID
*/
public static final String APPID_IN_MYSQL = "dkm_admin";
/**
* 无效字符串
*/
public static final String INVALID = "xxxx";
public static final String INVALID_APPID = INVALID;
/**
* 数据库中实际存在的物理集群Id
*/
public static final Long PHYSICAL_CLUSTER_ID_IN_MYSQL = 1L;
/**
* 数据库中实际存在的逻辑集群Id
*/
public static final Long LOGICAL_CLUSTER_ID_IN_MYSQL = 7L;
public static final Integer ALIVE_BROKER_ID = 3;
/**
* 无效的集群Id
*/
public static final Long INVALID_CLUSTER_ID_IN_MYSQL = Long.MAX_VALUE;
public static final Long INVALID_ID = -1L;
/**
* 数据库中实际存在的TopicName
*/
public static final String TOPIC_NAME_IN_MYSQL = "moduleTest";
public static final String INVALID_TOPIC_NAME = INVALID;
/**
* 操作权限
*/
public static final Integer ACCESS = 100;
public static final String ZK_ADDRESS = "10.190.46.198:2181,10.190.14.237:2181,10.190.50.65:2181/xg";
public static final String BOOTSTRAP_SERVERS = "10.190.46.198:9093,10.190.14.237:9093,10.190.50.65:9093";
public static final String CLUSTER_NAME = "clusterTest";
public static final String IDC = "China";
}

View File

@@ -0,0 +1,86 @@
package com.xiaojukeji.kafka.manager.web.config;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.gateway.OrderExtensionAddGatewayConfigDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.config.ConfigDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.LogicalClusterDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.RegionDTO;
import java.util.Arrays;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/17
*/
public class CustomDataSource {
public static RegionDTO getRegionDTO(Map<String, String> configMap) {
RegionDTO regionDTO = new RegionDTO();
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
regionDTO.setClusterId(physicalClusterId);
Integer brokerId = Integer.parseInt(configMap.get(ConfigConstant.ALIVE_BROKER_ID));
regionDTO.setBrokerIdList(Arrays.asList(brokerId));
regionDTO.setDescription("");
regionDTO.setName(configMap.get(ConfigConstant.REGION_NAME));
regionDTO.setStatus(0);
return regionDTO;
}
public static LogicalClusterDTO getLogicalClusterDTO(Map<String, String> configMap) {
LogicalClusterDTO logicalClusterDTO = new LogicalClusterDTO();
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
logicalClusterDTO.setClusterId(physicalClusterId);
logicalClusterDTO.setName(configMap.get(ConfigConstant.LOGICAL_CLUSTER_NAME));
logicalClusterDTO.setAppId(configMap.get(ConfigConstant.APPID));
logicalClusterDTO.setIdentification(configMap.get(ConfigConstant.LOGICAL_CLUSTER_NAME));
logicalClusterDTO.setDescription("");
logicalClusterDTO.setMode(0);
return logicalClusterDTO;
}
public static ConfigDTO getConfigDTO() {
ConfigDTO configDTO = new ConfigDTO();
configDTO.setConfigKey(ConfigConstant.CONFIG_KEY);
configDTO.setConfigValue(ConfigConstant.CONFIG_VALUE);
configDTO.setConfigDescription("测试config");
return configDTO;
}
public static TopicDeletionDTO getTopicDeletionDTO(Map<String, String> configMap) {
TopicDeletionDTO deletionDTO = new TopicDeletionDTO();
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
deletionDTO.setClusterId(physicalClusterId);
deletionDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
deletionDTO.setUnForce(true);
return deletionDTO;
}
public static TopicCreationDTO getTopicCreationDTO(Map<String, String> configMap) {
// 在broker1上创建1分区1副本的createTopicTest
TopicCreationDTO creationDTO = new TopicCreationDTO();
creationDTO.setAppId(configMap.get(ConfigConstant.APPID));
// 在broker1上创建
Integer brokerId = Integer.parseInt(configMap.get(ConfigConstant.ALIVE_BROKER_ID));
creationDTO.setBrokerIdList(Arrays.asList(brokerId));
creationDTO.setPartitionNum(1);
creationDTO.setReplicaNum(1);
creationDTO.setRetentionTime(1000L * 60 * 60 * 168);
creationDTO.setPeakBytesIn(10L * 1024 * 1024);
// 物理集群id
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
creationDTO.setClusterId(physicalClusterId);
creationDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
return creationDTO;
}
public static OrderExtensionAddGatewayConfigDTO getOrderExtensionAddGatewayConfigDTO(Map<String, String> configMap) {
OrderExtensionAddGatewayConfigDTO orderExtensionAddGatewayConfigDTO = new OrderExtensionAddGatewayConfigDTO();
orderExtensionAddGatewayConfigDTO.setName(configMap.get(ConfigConstant.GATEWAY_NAME));
orderExtensionAddGatewayConfigDTO.setType(configMap.get(ConfigConstant.GATEWAY_TYPE));
orderExtensionAddGatewayConfigDTO.setValue(configMap.get(ConfigConstant.GATEWAY_VALUE));
orderExtensionAddGatewayConfigDTO.setValue(configMap.get(ConfigConstant.GATEWAY_DESCRIPTION));
return orderExtensionAddGatewayConfigDTO;
}
}

View File

@@ -1,18 +0,0 @@
package com.xiaojukeji.kafka.manager.web.config;
import org.springframework.http.HttpHeaders;
/**
* @author xuguang
* @Date 2022/1/11
*/
public class HttpUtils {
public static HttpHeaders getHttpHeaders() {
// 需要在管控平台上配置教程见docs -> user_guide -> call_api_bypass_login
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(Constant.TRICK_LOGIN_SWITCH, Constant.ON);
httpHeaders.add(Constant.TRICK_LOGIN_USER, Constant.USER_ADMIN);
return httpHeaders;
}
}

View File

@@ -0,0 +1,33 @@
# 接口基本地址
base-url = http://localhost:8080
# appId
appId = dkm_admin
# 存活的brokerId
alive-brokerId = 1
# 集群名称
cluster.name = integrationTestCluster
# 集群地址
cluster.bootstrap.address = 10.190.46.198:9093,10.190.14.237:9093,10.190.50.65:9093
# zk地址
cluster.zookeeper.address = 10.190.46.198:2181,10.190.14.237:2181,10.190.50.65:2181/xg
# 物理集群在数据库中的Id
physicalCluster.id.in.mysql = 1
# 逻辑集群在数据库中的Id新创建的逻辑集群并不能立即加载到缓存中所以需要用已创建好的
logicalCluster.id.in.mysql = 7
logicalCluster.name = integrationTestLogicalCluster
# 集成测试用的Topic
topic.name = integrationTestTopic
# 集成测试用的region
region.name = integrationTestRegion
# gateway相关配置
gateway.config.type = SD_CLUSTER_ID
gateway.config.name = integrationTest_SD
gateway.config.value = 127.0.0.1
gateway.config.description = integrationTest