Merge pull request #479 from didi/dev

集成测试&单元测试补充
This commit is contained in:
EricZeng
2022-03-15 13:49:33 +08:00
committed by GitHub
171 changed files with 21563 additions and 124 deletions

View File

@@ -104,6 +104,11 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
* @author zengqiao
* @date 20/8/21
*/
@Api(tags = "RD-Jmx维度相关接口(REST)")
@Api(tags = "Normal-Jmx维度相关接口(REST)")
@RestController
@RequestMapping(ApiPrefix.API_V1_NORMAL_PREFIX)
public class NormalJmxController {

View File

@@ -57,7 +57,7 @@ public class RdLogicalClusterController {
);
}
@ApiOperation(value = "查询逻辑集群列表", notes = "")
@ApiOperation(value = "根据逻辑集群Id获取逻辑集群", notes = "")
@RequestMapping(value = "logical-clusters", method = RequestMethod.GET)
@ResponseBody
public Result<LogicalClusterVO> getByLogicalClusterId(@RequestParam("id") Long physicalClusterId) {

View File

@@ -14,9 +14,9 @@ spring:
active: dev
datasource:
kafka-manager:
jdbc-url: jdbc:mysql://localhost:3306/logi_kafka_manager?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8
jdbc-url: jdbc:mysql://116.85.13.90:3306/logi_kafka_manager?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8
username: root
password: 123456
password: DiDi2020@
driver-class-name: com.mysql.cj.jdbc.Driver
main:
allow-bean-definition-overriding: true

View File

@@ -0,0 +1,40 @@
package com.xiaojukeji.kafka.manager.web.api.versionone;
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.LoginDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.OperateRecordDTO;
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/21
*/
public class LoginControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试登陆")
public void loginTest() {
LoginDTO loginDTO = new LoginDTO();
loginDTO.setUsername("admin");
loginDTO.setPassword("admin");
String url = baseUrl + "/api/v1/sso/login";
HttpEntity<LoginDTO> httpEntity = new HttpEntity<>(loginDTO, 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());
}
}

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

@@ -0,0 +1,417 @@
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.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;
/**
* @author xuguang
* @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);
}
@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(configMap.get(ConfigConstant.APPID));
appDTO.setName("KM管理员");
appDTO.setPrincipals(configMap.get(ConfigConstant.ADMIN_USER));
appDTO.setDescription("KM管理员应用-谨慎对外提供");
return appDTO;
}
@Test(description = "测试获取App列表")
public void getAppsTest() {
String url = baseUrl + "/api/v1/normal/apps";
// 有headers登陆
getAppsWithHeadersTest(url);
// 无headers登陆
getAppsWithoutHeadersTest(url);
}
private void getAppsWithHeadersTest(String url) {
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());
}
private void getAppsWithoutHeadersTest(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", new HttpHeaders());
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.UNAUTHORIZED.value());
}
@Test(description = "测试由appId获取app")
public void getAppBasicInfoTest() {
String url = baseUrl + "/api/v1/normal/apps/{appId}/basic-info";
// 查询结果不为空
getAppBasicInfo2ResultNotEmptyTest(url);
// 查询结果为空
getAppBasicInfo2ResultEmptyTest(url);
}
private void getAppBasicInfo2ResultNotEmptyTest(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
Assert.assertNotNull(result.getBody().getData());
}
private void getAppBasicInfo2ResultEmptyTest(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
Assert.assertNull(result.getBody().getData());
}
@Test(description = "测试修改app")
public void modifyApp() {
String url = baseUrl + "/api/v1/normal/apps";
// 修改成功
modifyApp2SuccessTest(url);
// 传的dto为空, 修改不成功
modifyApp2FailureTest(url);
}
private void modifyApp2SuccessTest(String url) {
AppDTO appDTO = getAppDTO();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<AppDTO> httpEntity =
new HttpEntity<>(appDTO, 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 void modifyApp2FailureTest(String url) {
AppDTO appDTO = new AppDTO();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<AppDTO> httpEntity =
new HttpEntity<>(appDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertNotEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取有权限的Topic信息")
public void getAppTopicsTest() {
String url = baseUrl + "/api/v1/normal/apps/{appId}/topics";
// 参数appId
getAppTopics1Test(url);
// 参数有appIdmine=true
getAppTopics2Test(url);
// 参数有appIdmine=false
getAppTopics3Test(url);
// appId无效mine=false
getAppTopics4Test(url);
}
private void getAppTopics1Test(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void getAppTopics2Test(String url) {
url = url + "?mine=true";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void getAppTopics3Test(String url) {
url = url + "?mine=false";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
private void getAppTopics4Test(String url) {
url = url + "?mine=false";
HttpEntity<String> httpEntity = new HttpEntity<>(null, httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试Quota查询")
public void getAppIdQuotaTest() {
String url = baseUrl + "/api/v1/normal/apps/{appId}/quotas";
// appId不为空clusterId和topicName在数据库中真实存在isPhysicalClusterId=true
getAppIdQuota1Test(url);
// appId无效
getAppIdQuota2Test(url);
// topicName无效
getAppIdQuota3Test(url);
// clusterId无效
getAppIdQuota4Test(url);
}
private void getAppIdQuota1Test(String url) {
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", configMap.get(ConfigConstant.APPID));
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 getAppIdQuota2Test(String url) {
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", configMap.get(ConfigConstant.APPID));
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 getAppIdQuota3Test(String url) {
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", configMap.get(ConfigConstant.APPID));
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.TOPIC_NOT_EXIST.getCode());
}
private void getAppIdQuota4Test(String url) {
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", configMap.get(ConfigConstant.APPID));
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 = "测试获取应用连接信息")
public void getAppIdConnectionsTest() {
String url = baseUrl + "/api/v1/normal/apps/{appId}/connections";
// appId存在数据库
getAppIdConnections1Test(url);
// appId不存在数据库
getAppIdConnections2Test(url);
}
public void getAppIdConnections1Test(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
Assert.assertNotNull(result.getBody().getData());
}
public void getAppIdConnections2Test(String url) {
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, String> urlVariables = new HashMap<>();
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());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
Assert.assertNotNull(result.getBody().getData());
}
@Test(description = "测试app对Topic权限信息")
public void getAppIdAuthorityTest() {
// appId, clusterId, topicName在数据库中存在
getAppIdAuthority1Test();
// appId无效
getAppIdAuthority2Test();
// clusterId无效
getAppIdAuthority3Test();
// topicName无效
getAppIdAuthority4Test();
}
private void getAppIdAuthority1Test() {
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", configMap.get(ConfigConstant.APPID));
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 getAppIdAuthority2Test() {
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", configMap.get(ConfigConstant.APPID));
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 getAppIdAuthority3Test() {
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", configMap.get(ConfigConstant.APPID));
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());
}
private void getAppIdAuthority4Test() {
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", configMap.get(ConfigConstant.APPID));
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.TOPIC_NOT_EXIST.getCode());
}
}

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

@@ -0,0 +1,168 @@
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.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 Long logicalClusterId;
@BeforeClass
public void init() {
super.init();
logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
}
@Test(description = "测试获取集群列表")
public void getLogicClusterVOListTest() {
String url = baseUrl + "/api/v1/normal/clusters/basic-info";
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 = "测试由逻辑集群id获取集群")
public void getLogicClusterVOByIdTest() {
// 获取成功
getLogicClusterVOById1();
// 集群不存在
getLogicClusterVOById2();
}
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, 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,84 @@
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.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/22
*/
public class NormalConsumerControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@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 resetOffsetTest() {
}
@Test(description = "测试查询消费Topic的消费组")
public void getConsumerGroups() {
String url = baseUrl + "/api/v1/normal/{clusterId}/consumers/{topicName}/consumer-groups";
Map<String, Object> mp = new HashMap<>();
mp.put("clusterId", configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
mp.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, mp);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,88 @@
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.JmxSwitchDTO;
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.List;
/**
* @author xuguang
* @Date 2022/2/21
*/
public class NormalJmxControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@AfterClass
public void afterTest() {
// 删除Topic成功
String url = baseUrl + "/api/v1/op/topics";
deleteTopics(url);
}
private JmxSwitchDTO getJmxSwitchDTO() {
JmxSwitchDTO jmxSwitchDTO = new JmxSwitchDTO();
jmxSwitchDTO.setClusterId(physicalClusterId);
jmxSwitchDTO.setPhysicalClusterId(true);
jmxSwitchDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
jmxSwitchDTO.setOpenAppIdTopicMetrics(false);
jmxSwitchDTO.setOpenDiskMetrics(false);
jmxSwitchDTO.setOpenClientRequestMetrics(false);
jmxSwitchDTO.setOpenTopicRequestMetrics(false);
return jmxSwitchDTO;
}
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 = "测试开启TopicJMX")
public void jmxSwitchTest() {
JmxSwitchDTO jmxSwitchDTO = getJmxSwitchDTO();
String url = baseUrl + "/api/v1/normal/jmx-switch";
HttpEntity<JmxSwitchDTO> httpEntity = new HttpEntity<>(jmxSwitchDTO, 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());
}
}

View File

@@ -0,0 +1,45 @@
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.monitor.common.entry.dto.MonitorRuleDTO;
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/22
*/
public class NormalMonitorControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
// createCommonTopic(url);
}
// private MonitorRuleDTO getMonitorRuleDTO() {
// MonitorRuleDTO monitorRuleDTO = new MonitorRuleDTO();
// monitorRuleDTO.set
// }
@Test(description = "测试告警屏蔽创建")
public void monitorSilences() {
String url = baseUrl + "/api/v1/normal/monitor-silences";
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,155 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
import com.alibaba.fastjson.JSON;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.OrderDTO;
import com.xiaojukeji.kafka.manager.bpm.common.handle.OrderHandleBaseDTO;
import com.xiaojukeji.kafka.manager.bpm.common.handle.OrderHandleBatchDTO;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.vo.normal.order.OrderVO;
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.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/18
*/
public class NormalOrderControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
createOrderSuccess();
}
@AfterClass
public void destroy() {
deleteOrder();
}
private void createOrderSuccess() {
String url = baseUrl + "/api/v1/normal/orders";
OrderDTO orderDTO = CustomDataSource.getOrderDTO(configMap);
HttpEntity<OrderDTO> httpEntity = new HttpEntity<>(orderDTO, 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 getOrderId() {
String url = baseUrl + "/api/v1/normal/orders?status=0";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
String s = JSON.toJSONString(result.getBody().getData());
List<OrderVO> orders = JSON.parseArray(s, OrderVO.class);
for (OrderVO order : orders) {
if (order.getDescription().equals(ConfigConstant.DESCRIPTION)) {
return order.getId();
}
}
return null;
}
@Test(description = "测试获取工单申请列表")
public void getOrders() {
String url = baseUrl + "/api/v1/normal/orders?status=0";
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 getTypeEnums() {
String url = baseUrl + "/api/v1/normal/orders/type-enums";
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 getDetailOrder() {
String url = baseUrl + "/api/v1/normal/orders/{orderId}/detail";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("orderId", getOrderId());
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 deleteOrder() {
String url = baseUrl + "/api/v1/normal/orders?id=" + getOrderId();
HttpEntity<String> httpEntity = new HttpEntity<>("", 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 getApprovalOrders() {
String url = baseUrl + "/api/v1/normal/approvals?status=0";
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 handleOrderTest() {
// 单个工单审批
handleOrder();
// // 工单批量处理
// handleBatchOrders();
}
private void handleOrder() {
String url = baseUrl + "/api/v1/normal/orders";
OrderHandleBaseDTO orderHandleBaseDTO = new OrderHandleBaseDTO();
orderHandleBaseDTO.setId(getOrderId());
orderHandleBaseDTO.setStatus(1);
HttpEntity<OrderHandleBaseDTO> httpEntity = new HttpEntity<>(orderHandleBaseDTO, httpHeaders);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity, Result.class);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNull(result.getBody());
}
public void handleBatchOrders() {
String url = baseUrl + "/api/v1/normal/orders";
OrderHandleBatchDTO orderHandleBatchDTO = new OrderHandleBatchDTO();
orderHandleBatchDTO.setOrderIdList(Arrays.asList(getOrderId()));
orderHandleBatchDTO.setStatus(1);
HttpEntity<OrderHandleBatchDTO> httpEntity = new HttpEntity<>(orderHandleBatchDTO, 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());
}
}

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

@@ -0,0 +1,130 @@
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.TopicModifyDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.normal.TopicRetainDTO;
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.List;
/**
* @author xuguang
* @Date 2022/2/21
*/
public class NormalTopicMineControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@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 getAllTopicsTest() {
String url = baseUrl + "/api/v1/normal/topics";
HttpEntity<String> httpEntity2 = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.GET, 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 getMyTopicsTest() {
String url = baseUrl + "/api/v1/normal/topics/mine";
HttpEntity<String> httpEntity2 = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.GET, 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 getExpiredTopicsTest() {
String url = baseUrl + "/api/v1/normal/topics/expired";
HttpEntity<String> httpEntity2 = new HttpEntity<>("", httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.GET, 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 retainExpiredTopicsTest() {
String url = baseUrl + "/api/v1/normal/topics/expired";
TopicRetainDTO topicRetainDTO = new TopicRetainDTO();
topicRetainDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
topicRetainDTO.setRetainDays(1);
Long logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
topicRetainDTO.setClusterId(logicalClusterId);
HttpEntity<TopicRetainDTO> httpEntity2 = new HttpEntity<>(topicRetainDTO, httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.PUT, 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 modifyTopicsTest() {
String url = baseUrl + "/api/v1/normal/topics";
TopicModifyDTO topicModifyDTO = new TopicModifyDTO();
topicModifyDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
Long logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
topicModifyDTO.setClusterId(logicalClusterId);
topicModifyDTO.setDescription("");
HttpEntity<TopicModifyDTO> httpEntity2 = new HttpEntity<>(topicModifyDTO, httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.PUT, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,96 @@
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.ConfigConstant;
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
import org.springframework.boot.test.web.client.TestRestTemplate;
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();
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 = baseUrl + "/topic-authorities";
addAuthority1Test(url);
}
private void addAuthority1Test(String url) {
TopicAuthorityDTO topicAuthorityDTO = getTopicAuthorityDTO();
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.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,381 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.op;
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.op.ControllerPreferredCandidateDTO;
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.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;
/**
* @author xuguang
* @Date 2022/1/13
*/
public class OpClusterControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/clusters";
// 接入成功
addNewCluter1Test(url);
}
@AfterClass
public void deleteCluster() {
String url = baseUrl + "/api/v1/op/clusters";
// 删除集群成功
deleteCluster1Test(url);
}
private Long getPhysicalClusterId() {
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());
Assert.assertNotNull(result.getBody());
String s = JSON.toJSONString(result.getBody().getData());
List<ClusterDetailVO> clusterDetailVOS = JSON.parseArray(s, ClusterDetailVO.class);
for (ClusterDetailVO clusterDetailVO : clusterDetailVOS) {
if (clusterDetailVO.getClusterName().equals(clusterName)) {
return clusterDetailVO.getClusterId();
}
}
return null;
}
private ClusterDTO getClusterDTO() {
ClusterDTO clusterDTO = new ClusterDTO();
Long physicalClusterId = getPhysicalClusterId();
clusterDTO.setClusterId(physicalClusterId);
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 = baseUrl + "/api/v1/op/clusters";
// 参数无效
addNewCluster2Test(url);
// 无效的zk地址
addNewCluster3Test(url);
// 重复创建
addNewCluster4Test(url);
}
private void addNewCluter1Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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 addNewCluster2Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setZookeeper(null);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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 addNewCluster3Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setZookeeper(ConfigConstant.INVALID_STRING);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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.ZOOKEEPER_CONNECT_FAILED.getCode());
}
private void addNewCluster4Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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.RESOURCE_ALREADY_EXISTED.getCode());
}
@Test(description = "测试修改物理集群")
public void modifyClusterTest() {
String url = baseUrl + "/api/v1/op/clusters";
// 修改成功
modifyCluster1Test(url);
// 参数错误
modifyCluster2Test(url);
// 集群不存在
modifyCluster3Test(url);
// 不能修改zk地址
modifyCluster4Test(url);
}
private void modifyCluster1Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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 void modifyCluster2Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setClusterId(null);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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 modifyCluster3Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setClusterId(ConfigConstant.INVALID_CLUSTER_ID);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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());
}
private void modifyCluster4Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
clusterDTO.setZookeeper(ConfigConstant.INVALID_STRING);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ClusterDTO> httpEntity =
new HttpEntity<>(clusterDTO, 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.CHANGE_ZOOKEEPER_FORBIDDEN.getCode());
}
@Test(description = "测试开启|关闭集群监控")
public void clusterMonitorTest() {
String url = baseUrl + "/api/v1/op/clusters/{clusterId}/monitor";
// 监控关闭成功
clusterMonitor1Test(url);
// 监控开启成功
clusterMonitor2Test(url);
// 无效的集群
clusterMonitor3Test(url);
}
private void clusterMonitor1Test(String url) {
url = url + "?status=0";
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", getPhysicalClusterId());
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.PUT, 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 clusterMonitor2Test(String url) {
url = url + "?status=1";
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", getPhysicalClusterId());
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.PUT, 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 clusterMonitor3Test(String url) {
url = url + "?status=1";
HttpEntity<Long> httpEntity =
new HttpEntity<>(null, httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", ConfigConstant.INVALID_CLUSTER_ID);
ResponseEntity<Result> result = testRestTemplate.exchange(
url, HttpMethod.PUT, 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 = "测试增加Controller优先候选的Broker")
public void addControllerPreferredCandidatesTest() {
String url = baseUrl + "/api/v1/op/cluster-controller/preferred-candidates";
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
// 增加成功
addControllerPreferredCandidates1Test(url, physicalClusterId);
// broker不存在
addControllerPreferredCandidates2Test(url, physicalClusterId);
// 参数错误
addControllerPreferredCandidates3Test(url, physicalClusterId);
}
private void addControllerPreferredCandidates1Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(physicalClusterId);
String aliveBrokerId = configMap.get(ConfigConstant.ALIVE_BROKER_ID);
dto.setBrokerIdList(Arrays.asList(Integer.parseInt(aliveBrokerId)));
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, 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 addControllerPreferredCandidates2Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(physicalClusterId);
dto.setBrokerIdList(Arrays.asList(ConfigConstant.INVALID_ID));
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, 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.BROKER_NOT_EXIST.getCode());
}
private void addControllerPreferredCandidates3Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(physicalClusterId);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, 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());
}
@Test(description = "测试删除Controller优先候选的Broker")
public void deleteControllerPreferredCandidatesTest() {
String url = baseUrl + "/api/v1/op/cluster-controller/preferred-candidates";
Long physicalClusterId = Long.parseLong(configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
// 删除成功
deleteControllerPreferredCandidates1Test(url, physicalClusterId);
// 参数错误
deleteControllerPreferredCandidates2Test(url, physicalClusterId);
}
private void deleteControllerPreferredCandidates1Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(physicalClusterId);
String aliveBrokerId = configMap.get(ConfigConstant.ALIVE_BROKER_ID);
dto.setBrokerIdList(Arrays.asList(Integer.parseInt(aliveBrokerId)));
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, 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 deleteControllerPreferredCandidates2Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(physicalClusterId);
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity =
new HttpEntity<>(dto, 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());
}
@Test(description = "测试删除物理集群")
public void deleteClusterTest() {
String url = baseUrl + "/api/v1/op/clusters";
// 集群不存在
deleteCluster2Test(url);
}
private void deleteCluster1Test(String url) {
ClusterDTO clusterDTO = getClusterDTO();
url = url + "?clusterId=" + clusterDTO.getClusterId();
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 deleteCluster2Test(String url) {
url = url + "?clusterId=" + ConfigConstant.INVALID_CLUSTER_ID;
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.MYSQL_ERROR.getCode());
}
}

View File

@@ -0,0 +1,146 @@
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.kcm.common.bizenum.ClusterTaskTypeEnum;
import com.xiaojukeji.kafka.manager.kcm.common.entry.dto.ClusterHostTaskDTO;
import com.xiaojukeji.kafka.manager.kcm.common.entry.dto.ClusterTaskActionDTO;
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;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/23
*/
public class OpClusterTaskControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试创建集群任务")
public void createClusterTaskTest() {
createClusterTask();
}
private ClusterHostTaskDTO getClusterHostTaskDTO() {
ClusterHostTaskDTO clusterHostTaskDTO = new ClusterHostTaskDTO();
clusterHostTaskDTO.setClusterId(physicalClusterId);
clusterHostTaskDTO.setHostList(Arrays.asList("127.0.0.1"));
clusterHostTaskDTO.setTaskType(ClusterTaskTypeEnum.HOST_UPGRADE.getName());
clusterHostTaskDTO.setKafkaFileBaseUrl("127.0.0.1");
clusterHostTaskDTO.setKafkaPackageMd5("md5");
clusterHostTaskDTO.setKafkaPackageName("name");
clusterHostTaskDTO.setServerPropertiesMd5("md5");
clusterHostTaskDTO.setServerPropertiesName("name");
return clusterHostTaskDTO;
}
private void createClusterTask() {
String url = baseUrl + "/api/v1/op/cluster-tasks";
ClusterHostTaskDTO clusterHostTaskDTO = getClusterHostTaskDTO();
HttpEntity<ClusterHostTaskDTO> httpEntity = new HttpEntity<>(clusterHostTaskDTO, 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 startTaskTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks";
ClusterTaskActionDTO clusterHostTaskDTO = new ClusterTaskActionDTO();
clusterHostTaskDTO.setTaskId(-1L);
clusterHostTaskDTO.setAction("action");
HttpEntity<ClusterTaskActionDTO> httpEntity = new HttpEntity<>(clusterHostTaskDTO, 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.RESOURCE_NOT_EXIST.getCode());
}
@Test(description = "测试触发集群任务")
public void listClusterTasksTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks";
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 listTaskEnumsTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks/enums";
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 listKafkaFilesTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks/kafka-files?clusterId=" + physicalClusterId;
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 getKafkaTaskLogsTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks/{taskId}/log?hostname=127.0.0.1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("taskId", -1L);
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.TASK_NOT_EXIST.getCode());
}
@Test(description = "测试获取集群任务元信息")
public void getTaskMetadataTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks/{taskId}/metadata";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("taskId", -1L);
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.RESOURCE_NOT_EXIST.getCode());
}
@Test(description = "测试获取集群任务状态")
public void getTaskStatusTest() {
String url = baseUrl + "/api/v1/op/cluster-tasks/{taskId}/metadata";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("taskId", -1L);
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.RESOURCE_NOT_EXIST.getCode());
}
}

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,127 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.op;
import com.alibaba.fastjson.JSON;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.gateway.OrderExtensionAddGatewayConfigDTO;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.gateway.OrderExtensionDeleteGatewayConfigDTO;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.gateway.OrderExtensionModifyGatewayConfigDTO;
import com.xiaojukeji.kafka.manager.common.entity.Result;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.vo.rd.GatewayConfigVO;
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.List;
/**
* @author xuguang
* @Date 2022/2/21
*/
public class OpGatewayConfigControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
createGatewayConfigSuccess();
}
@AfterClass
public void destroy() {
// 删除成功
deleteGatewayConfigSuccess();
}
@Test(description = "测试创建Gateway配置")
public void createGatewayConfigTest() {
// paramIllegal
createGatewayConfig2ParamIllegal();
}
private void createGatewayConfigSuccess() {
String url = baseUrl + "/api/v1/op/gateway-configs";
OrderExtensionAddGatewayConfigDTO dto = CustomDataSource.getOrderExtensionAddGatewayConfigDTO(configMap);
HttpEntity<OrderExtensionAddGatewayConfigDTO> httpEntity = new HttpEntity<>(dto, 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 createGatewayConfig2ParamIllegal() {
String url = baseUrl + "/api/v1/op/gateway-configs";
OrderExtensionAddGatewayConfigDTO dto = CustomDataSource.getOrderExtensionAddGatewayConfigDTO(configMap);
dto.setName(null);
HttpEntity<OrderExtensionAddGatewayConfigDTO> httpEntity = new HttpEntity<>(dto, 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 Long getGatewayConfigId() {
String url = baseUrl + "/api/v1/rd/gateway-configs";
String gatewayName = configMap.get(ConfigConstant.GATEWAY_NAME);
String gatewayType = configMap.get(ConfigConstant.GATEWAY_TYPE);
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());
String s = JSON.toJSONString(result.getBody().getData());
List<GatewayConfigVO> GatewayConfigVOS = JSON.parseArray(s, GatewayConfigVO.class);
for (GatewayConfigVO gatewayConfigVO : GatewayConfigVOS) {
if (gatewayConfigVO.getName().equals(gatewayName) && gatewayConfigVO.getType().equals(gatewayType)) {
return gatewayConfigVO.getId();
}
}
return null;
}
@Test(description = "测试修改Gateway配置")
public void modifyGatewayConfigTest() {
String url = baseUrl + "/api/v1/op/gateway-configs";
OrderExtensionModifyGatewayConfigDTO dto =
CustomDataSource.getOrderExtensionModifyGatewayConfigDTO(configMap);
dto.setId(getGatewayConfigId());
HttpEntity<OrderExtensionModifyGatewayConfigDTO> httpEntity = new HttpEntity<>(dto, 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 = "测试删除Gateway配置")
public void deleteGatewayConfigTest() {
}
private void deleteGatewayConfigSuccess() {
String url = baseUrl + "/api/v1/op/gateway-configs";
OrderExtensionDeleteGatewayConfigDTO dto = new OrderExtensionDeleteGatewayConfigDTO();
dto.setId(getGatewayConfigId());
HttpEntity<OrderExtensionDeleteGatewayConfigDTO> httpEntity = new HttpEntity<>(dto, 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 = "测试获取Gateway配置类型")
public void getTypeEnumsTest() {
String url = baseUrl + "/api/v1/op/gateway-configs/type-enums";
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,60 @@
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.RebalanceDTO;
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/23
*/
public class OpLeaderControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
private RebalanceDTO getRebalanceDTO() {
RebalanceDTO rebalanceDTO = new RebalanceDTO();
rebalanceDTO.setClusterId(physicalClusterId);
rebalanceDTO.setDimension(0);
return rebalanceDTO;
}
@Test(description = "测试优先副本选举")
public void preferredReplicaElectionTest() {
// String url = baseUrl + "/api/v1/op/leaders/preferred-replica-election";
String url = baseUrl + "/api/v1/op/utils/rebalance";
RebalanceDTO rebalanceDTO = getRebalanceDTO();
HttpEntity<RebalanceDTO> httpEntity = new HttpEntity<>(rebalanceDTO, 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 getRebalanceStatus() {
String url = baseUrl + "/api/v1/op/leaders/preferred-replica-election-status?clusterId=" + physicalClusterId;
// String url = baseUrl + "/api/v1/op/utils/rebalance-status?clusterId=" + physicalClusterId;
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,83 @@
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.gateway.TopicQuotaDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.normal.JmxSwitchDTO;
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.List;
/**
* @author xuguang
* @Date 2022/2/21
*/
public class OpQuotaControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@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 = "测试配额调整")
public void getTopicQuotas() {
TopicQuotaDTO topicQuotaDTO = new TopicQuotaDTO();
Long logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
topicQuotaDTO.setClusterId(logicalClusterId);
topicQuotaDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
topicQuotaDTO.setProduceQuota(1L);
topicQuotaDTO.setConsumeQuota(1L);
topicQuotaDTO.setAppId(configMap.get(ConfigConstant.APPID));
String url = baseUrl + "/api/v1/op/topic-quotas";
HttpEntity<TopicQuotaDTO> httpEntity2 = new HttpEntity<>(topicQuotaDTO, httpHeaders);
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity2, Result.class);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,121 @@
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.reassign.ReassignExecDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.reassign.ReassignExecSubDTO;
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;
/**
* @author xuguang
* @Date 2022/2/24
*/
public class OpReassignTasksTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试创建迁移任务")
public void createReassignTasksTest() {
String url = baseUrl + "/api/v1/op/reassign-tasks";
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 getReassignTaskListTest() {
String url = baseUrl + "/api/v1/op/reassign-tasks";
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 getReassignTaskDetailTest() {
String url = baseUrl + "/api/v1/op/reassign-tasks/{taskId}/detail";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("taskId", ConfigConstant.INVALID_ID);
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 = "测试获取迁移任务信息")
public void getReassignTaskStatusTest() {
String url = baseUrl + "/api/v1/op/reassign-tasks/{taskId}/status";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("taskId", ConfigConstant.INVALID_ID);
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 = "测试操作迁移任务")
public void operateReassignTaskTest() {
String url = baseUrl + "/api/v1/op/reassign-tasks/{taskId}/status";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("taskId", ConfigConstant.INVALID_ID);
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 = "测试操作迁移任务")
public void reassignTasks() {
String url = baseUrl + "/api/v1/op/reassign-tasks";
ReassignExecDTO reassignExecDTO = new ReassignExecDTO();
reassignExecDTO.setTaskId(-1L);
reassignExecDTO.setAction("cancel");
long now = System.currentTimeMillis();
reassignExecDTO.setBeginTime(now);
HttpEntity<ReassignExecDTO> httpEntity = new HttpEntity<>(reassignExecDTO, 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_FORBIDDEN.getCode());
}
@Test(description = "测试操作迁移子任务")
public void reassignSubTasks() {
String url = baseUrl + "/api/v1/op/reassign-tasks/sub-tasks";
ReassignExecSubDTO reassignExecSubDTO = new ReassignExecSubDTO();
reassignExecSubDTO.setAction("cancel");
reassignExecSubDTO.setSubTaskId(-1L);
HttpEntity<ReassignExecSubDTO> httpEntity = new HttpEntity<>(reassignExecSubDTO, 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());
}
}

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(description = "测试创建Topic")
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(description = "测试删除Topic")
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

@@ -0,0 +1,100 @@
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.rd.AccountDTO;
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.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/22
*/
public class RdAccountControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
createAccountSuccess();
}
@AfterClass
public void destroy() {
deleteAccount();
}
private AccountDTO getAccountDTO() {
AccountDTO accountDTO = new AccountDTO();
accountDTO.setRole(Integer.parseInt(configMap.get(ConfigConstant.ACCOUNT_ROLE)));
accountDTO.setUsername(configMap.get(ConfigConstant.ACCOUNT_USERNAME));
accountDTO.setPassword(configMap.get(ConfigConstant.ACCOUNT_PASSWORD));
return accountDTO;
}
@Test(description = "测试创建账号")
public void createAccountTest() {
}
private void createAccountSuccess() {
String url = baseUrl + "/api/v1/rd/accounts";
AccountDTO accountDTO = getAccountDTO();
HttpEntity<AccountDTO> httpEntity = new HttpEntity<>(accountDTO, 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 listAccountsTest() {
String url = baseUrl + "/api/v1/rd/accounts";
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 deleteAccountTest() {
Map<String, String> mp = new HashMap<>();
mp.put(null, null);
}
private void deleteAccount() {
String userName = configMap.get(ConfigConstant.ACCOUNT_USERNAME);
String url = baseUrl + "/api/v1/rd/accounts?username=" + userName;
HttpEntity<String> httpEntity = new HttpEntity<>("", 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 modifyAccountTest() {
String url = baseUrl + "/api/v1/rd/accounts";
AccountDTO accountDTO = getAccountDTO();
HttpEntity<AccountDTO> httpEntity = new HttpEntity<>(accountDTO, 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

@@ -0,0 +1,52 @@
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.normal.AppDTO;
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/24
*/
public class RdAppControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "获取App列表测试")
public void listAppsTest() {
String url = baseUrl + "/api/v1/rd/apps";
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 = "获取App列表测试")
public void modifyAppTest() {
String url = baseUrl + "/api/v1/rd/apps";
AppDTO appDTO = new AppDTO();
appDTO.setAppId(configMap.get(ConfigConstant.APPID));
appDTO.setName(configMap.get(ConfigConstant.APPID));
appDTO.setPrincipals(ConfigConstant.ADMIN_USER);
HttpEntity<AppDTO> httpEntity = new HttpEntity<>(appDTO, 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

@@ -0,0 +1,68 @@
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.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;
/**
* @author xuguang
* @Date 2022/2/24
*/
public class RdBillControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试用户账单概览")
public void getStaffSummaryTest() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/rd/bills/staff-summary?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 = "测试用户账单详情")
public void getStaffDetailTest() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/rd/bills/{username}/staff-detail?timestamp=" + now;
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("username", ConfigConstant.ADMIN_USER);
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 = "测试用户账单概览")
public void getStaffSummary2Test() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/rd/bills/{username}/staff-summary?startTime=0&endTime=" + now;
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("username", ConfigConstant.ADMIN_USER);
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,167 @@
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.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;
/**
* @author xuguang
* @Date 2022/2/23
*/
public class RdBrokerControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试获取broker基本信息列表")
public void getBrokersBasicInfo() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/brokers/basic-info";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取broker元信息")
public void getBrokerMetadata() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/broker-metadata";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试brokerTopic分析")
public void getBrokerTopicAnalysis() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/analysis";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取broker基本信息")
public void getBrokerBasicInfo() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/basic-info";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取broker实时流量")
public void getBrokerMetrics() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/metrics";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取broker历史指标")
public void getBrokerHistoryMetrics() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/metrics-history?startTime=0&endTime=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取broker分区信息")
public void getBrokerPartitions() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/partitions";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取broker磁盘分区")
public void getBrokerPartitionsLocation() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/partitions-location";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试获取brokerTopic信息")
public void getBrokerPartitionsTopic() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers/{brokerId}/topics";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
variableUrls.put("brokerId", configMap.get(ConfigConstant.ALIVE_BROKER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "测试删除broker")
public void deleteBroker() {
String url = baseUrl + "/api/v1/rd/{clusterId}/brokers?brokerId=-1";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", physicalClusterId);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.OPERATION_FAILED.getCode());
}
}

View File

@@ -0,0 +1,169 @@
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.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;
import java.util.HashMap;
import java.util.Map;
/**
* @author xuguang
* @Date 2022/2/24
*/
public class RdClusterControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "获取集群基本信息列表")
public void getClustersBasicInfo() {
String url = baseUrl + "/api/v1/rd/clusters/basic-info?need-detail=true";
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 getClusterBasicInfo() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/basic-info?need-detail=true";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 = "获取集群Broker列表")
public void getClusterBrokers() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/brokers";
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());
}
@Test(description = "获取集群Broker状态")
public void getClusterBrokersStatus() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/brokers-status";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 = "获取集群Controller变更历史")
public void getClusterControllerHistory() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/controller-history";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 = "获取集群Controller优先候选的Broker")
public void getClusterControllerPreferredCandidates() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/controller-preferred-candidates";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 = "获取集群实时流量")
public void getClusterMetrics() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/metrics";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 = "获取集群历史流量")
public void getClusterHistoryMetrics() {
long now = System.currentTimeMillis();
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/metrics-history?startTime=0&endTime=" + now;
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 = "获取集群限流信息")
public void getClusterThrottles() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/throttles";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 getClusterTopicMetadata() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/topic-metadata";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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 getClusterTopics() {
String url = baseUrl + "/api/v1/rd/clusters/{clusterId}/topics";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
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,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,53 @@
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.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;
/**
* @author xuguang
* @Date 2022/2/21
*/
public class RdConsumerControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试获取集群ConsumerGroup列表")
public void getConsumerGroupsTest() {
String url = baseUrl + "/api/v1/rd/{clusterId}/consumer-groups";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
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/rd/{clusterId}/consumer-groups/{consumerGroup}/topics?location=broker";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> variableUrls = new HashMap<>();
variableUrls.put("clusterId", configMap.get(ConfigConstant.PHYSICAL_CLUSTER_ID));
variableUrls.put("consumerGroup", "test");
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, variableUrls);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result.getBody());
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
}

View File

@@ -0,0 +1,34 @@
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.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/21
*/
public class RdGatewayConfigControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "获取Gateway相关配置信息")
public void getGatewayConfigsTest() {
String url = baseUrl + "/api/v1/rd/gateway-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());
}
}

View File

@@ -0,0 +1,70 @@
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.normal.KafkaFileDTO;
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/24
*/
public class RdKafkaFileControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试上传文件")
public void uploadFileTest() {
String url = baseUrl + "/api/v1/rd/kafka-files";
KafkaFileDTO kafkaFileDTO = new KafkaFileDTO();
HttpEntity<KafkaFileDTO> httpEntity = new HttpEntity<>(kafkaFileDTO, 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 listFilesTest() {
String url = baseUrl + "/api/v1/rd/kafka-files";
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 listFileEnumsTest() {
String url = baseUrl + "/api/v1/rd/kafka-files/enums";
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 deleteKafkaFilesTest() {
String url = baseUrl + "/api/v1/rd/kafka-files?id=-1";
HttpEntity<String> httpEntity = new HttpEntity<>("", 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.MYSQL_ERROR.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,41 @@
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.rd.OperateRecordDTO;
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/21
*/
public class RdOperateRecordControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试查询操作记录")
public void operateRecordTest() {
OperateRecordDTO operateRecordDTO = new OperateRecordDTO();
operateRecordDTO.setOperateId(0);
operateRecordDTO.setModuleId(0);
operateRecordDTO.setStartTime(0L);
operateRecordDTO.setEndTime(System.currentTimeMillis());
String url = baseUrl + "/api/v1/rd/operate-record";
HttpEntity<OperateRecordDTO> httpEntity = new HttpEntity<>(operateRecordDTO, 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());
}
}

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,66 @@
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.rd.CustomScheduledTaskDTO;
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;
/**
* @author xuguang
* @Date 2022/2/24
*/
public class RdScheduledControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
}
@Test(description = "测试获取调度任务列表")
public void listScheduledTasksTest() {
String url = baseUrl + "/api/v1/rd/scheduled-tasks";
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 modifyScheduledTasksTest() {
String url = baseUrl + "/api/v1/rd/scheduled-tasks";
CustomScheduledTaskDTO customScheduledTaskDTO = new CustomScheduledTaskDTO();
customScheduledTaskDTO.setCron("");
customScheduledTaskDTO.setName(ConfigConstant.ADMIN_USER);
HttpEntity<CustomScheduledTaskDTO> httpEntity = new HttpEntity<>(customScheduledTaskDTO, 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 runScheduledTask() {
String url = baseUrl + "/api/v1/rd/scheduled-tasks/{scheduledName}/run";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("scheduledName", ConfigConstant.ADMIN_USER);
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, urlVariables);
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNull(result.getBody());
}
}

View File

@@ -0,0 +1,92 @@
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.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/21
*/
public class RdTopicControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@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 = "获取TopicBroker信息")
public void getTopicBrokersTest() {
String url = baseUrl + "/api/v1/rd/{clusterId}/topics/{topicName}/brokers?isPhysicalClusterId=true";
HttpEntity<String> httpEntity2 = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("clusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity2, Result.class, urlVariables);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
}
@Test(description = "获取TopicBroker信息")
public void getTopicBasicInfoTest() {
String url = baseUrl + "/api/v1/rd/{physicalClusterId}/topics/{topicName}/basic-info";
HttpEntity<String> httpEntity2 = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity2, Result.class, urlVariables);
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
Assert.assertNotNull(result2.getBody());
Assert.assertEquals(result2.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,124 @@
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.openapi.common.dto.ConsumeHealthDTO;
import com.xiaojukeji.kafka.manager.openapi.common.dto.OffsetResetDTO;
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.*;
/**
* @author xuguang
* @Date 2022/2/24
*/
public class ThirdPartConsumerControllerTest extends BaseTest {
@BeforeClass
public void init() {
super.init();
String url = baseUrl + "/api/v1/op/topics";
createCommonTopic(url);
}
@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 = "测c消费组健康")
public void consumerHealthTest() {
ConsumeHealthDTO consumeHealthDTO = new ConsumeHealthDTO();
consumeHealthDTO.setClusterId(physicalClusterId);
consumeHealthDTO.setTopicNameList(Arrays.asList(configMap.get(ConfigConstant.TOPIC_NAME)));
consumeHealthDTO.setConsumerGroup("test");
consumeHealthDTO.setMaxDelayTime(System.currentTimeMillis());
String url = baseUrl + "/api/v1/third-part/clusters/consumer-health";
HttpEntity<ConsumeHealthDTO> httpEntity = new HttpEntity<>(consumeHealthDTO, 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 resetOffsetTest() {
}
private void resetOffset() {
OffsetResetDTO offsetResetDTO = new OffsetResetDTO();
offsetResetDTO.setClusterId(physicalClusterId);
offsetResetDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
offsetResetDTO.setConsumerGroup("test");
offsetResetDTO.setLocation("broker");
offsetResetDTO.setOffsetResetType(0);
offsetResetDTO.setAppId(configMap.get(ConfigConstant.APPID));
offsetResetDTO.setOperator(ConfigConstant.ADMIN_USER);
offsetResetDTO.setPassword(ConfigConstant.ADMIN_USER);
offsetResetDTO.setSubscribeReset(true);
offsetResetDTO.setPartitionOffsetDTOList(new ArrayList<>());
offsetResetDTO.setTimestamp(System.currentTimeMillis());
offsetResetDTO.setSystemCode("kafka-manager");
String url = "/api/v1/third-part/consumers/offsets";
HttpEntity<OffsetResetDTO> httpEntity = new HttpEntity<>(offsetResetDTO, 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());
}
@Test(description = "测试查询消费组的消费详情")
public void getConsumeDetailTest() {
String url = baseUrl + "/api/v1/third-part/{physicalClusterId}" +
"/consumers/{consumerGroup}/topics/{topicName}/consume-details?location=broker";
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
Map<String, Object> urlVariables = new HashMap<>();
urlVariables.put("physicalClusterId", physicalClusterId);
urlVariables.put("consumerGroup", "test");
urlVariables.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
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.OPERATION_FAILED.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

@@ -0,0 +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,95 @@
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 ACCOUNT_USERNAME = "account.username";
String ACCOUNT_ROLE = "account.role";
String ACCOUNT_PASSWORD = "account.password";
/**
* 登陆参数
*/
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;
/**
* 无效id
*/
Integer INVALID_ID = -1;
/**
* 数据中心
*/
String IDC = "cn";
String CONFIG_KEY = "key";
String CONFIG_VALUE = "value";
String KAFKA_MANAGER = "kafka-manager";
String DESCRIPTION = "integrationTest";
/**
* 操作权限
*/
Integer ACCESS = 100;
}

View File

@@ -0,0 +1,112 @@
package com.xiaojukeji.kafka.manager.web.config;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.OrderDTO;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.gateway.OrderExtensionAddGatewayConfigDTO;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.gateway.OrderExtensionModifyGatewayConfigDTO;
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;
}
public static OrderExtensionModifyGatewayConfigDTO getOrderExtensionModifyGatewayConfigDTO(Map<String, String> configMap) {
OrderExtensionModifyGatewayConfigDTO orderExtensionModifyGatewayConfigDTO = new OrderExtensionModifyGatewayConfigDTO();
orderExtensionModifyGatewayConfigDTO.setName(configMap.get(ConfigConstant.GATEWAY_NAME));
orderExtensionModifyGatewayConfigDTO.setType(configMap.get(ConfigConstant.GATEWAY_TYPE));
orderExtensionModifyGatewayConfigDTO.setValue(configMap.get(ConfigConstant.GATEWAY_VALUE));
orderExtensionModifyGatewayConfigDTO.setDescription(configMap.get(ConfigConstant.GATEWAY_DESCRIPTION));
return orderExtensionModifyGatewayConfigDTO;
}
public static OrderDTO getOrderDTO(Map<String, String> configMap) {
OrderDTO orderDTO = new OrderDTO();
orderDTO.setApplicant(ConfigConstant.ADMIN_USER);
orderDTO.setType(0);
orderDTO.setDescription(ConfigConstant.DESCRIPTION);
long logicalClusterId = Long.parseLong(configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
String topicName = configMap.get(ConfigConstant.TOPIC_NAME);
String appId = configMap.get(ConfigConstant.APPID);
String extensions = "{\"clusterId\":\"" + logicalClusterId +
"\",\"topicName\":\"" + topicName + "\",\"appId\":\"" + appId + "\",\"peakBytesIn\":104857600000}";
orderDTO.setExtensions(extensions);
return orderDTO;
}
}

View File

@@ -0,0 +1,38 @@
# 接口基本地址
base-url = http://localhost:8080
# appId
appId = dkm_admin
# 存活的brokerId
alive-brokerId = 1
# 集群名称
cluster.name = integrationTestCluster
# 集群地址
cluster.bootstrap.address = 127.0.0.1
# zk地址
cluster.zookeeper.address = 127.0.0.1
# 物理集群在数据库中的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
# 测试账号
account.username = integrationTest
account.password = integrationTest
account.role = 0