剩余controller接口集成测试

This commit is contained in:
xuguang
2022-02-25 17:04:46 +08:00
parent de54966d30
commit e120b32375
27 changed files with 2136 additions and 4 deletions

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,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

@@ -1,7 +1,29 @@
package com.xiaojukeji.kafka.manager.web.api.versionone.normal; 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.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.BeforeClass;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author xuguang * @author xuguang
@@ -13,10 +35,121 @@ public class NormalOrderControllerTest extends BaseTest {
public void init() { public void init() {
super.init(); super.init();
createOrderSuccess();
}
@AfterClass
public void destroy() {
deleteOrder();
} }
private void createOrderSuccess() { 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,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

@@ -280,7 +280,7 @@ public class OpClusterControllerTest extends BaseTest {
private void addControllerPreferredCandidates2Test(String url, Long physicalClusterId) { private void addControllerPreferredCandidates2Test(String url, Long physicalClusterId) {
ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO(); ControllerPreferredCandidateDTO dto = new ControllerPreferredCandidateDTO();
dto.setClusterId(physicalClusterId); dto.setClusterId(physicalClusterId);
dto.setBrokerIdList(Arrays.asList(ConfigConstant.INVALID_BROKER_ID)); dto.setBrokerIdList(Arrays.asList(ConfigConstant.INVALID_ID));
httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<ControllerPreferredCandidateDTO> httpEntity = HttpEntity<ControllerPreferredCandidateDTO> httpEntity =

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,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,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,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,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,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,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

@@ -39,6 +39,12 @@ public interface ConfigConstant {
String GATEWAY_DESCRIPTION = "gateway.config.description"; String GATEWAY_DESCRIPTION = "gateway.config.description";
String ACCOUNT_USERNAME = "account.username";
String ACCOUNT_ROLE = "account.role";
String ACCOUNT_PASSWORD = "account.password";
/** /**
* 登陆参数 * 登陆参数
@@ -65,9 +71,9 @@ public interface ConfigConstant {
Long INVALID_CLUSTER_ID = Long.MAX_VALUE; Long INVALID_CLUSTER_ID = Long.MAX_VALUE;
/** /**
* 无效broker id * 无效id
*/ */
Integer INVALID_BROKER_ID = -1; Integer INVALID_ID = -1;
/** /**
* 数据中心 * 数据中心
@@ -80,6 +86,8 @@ public interface ConfigConstant {
String KAFKA_MANAGER = "kafka-manager"; String KAFKA_MANAGER = "kafka-manager";
String DESCRIPTION = "integrationTest";
/** /**
* 操作权限 * 操作权限
*/ */

View File

@@ -1,6 +1,8 @@
package com.xiaojukeji.kafka.manager.web.config; 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.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.config.ConfigDTO;
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO; 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.TopicDeletionDTO;
@@ -83,4 +85,28 @@ public class CustomDataSource {
orderExtensionAddGatewayConfigDTO.setValue(configMap.get(ConfigConstant.GATEWAY_DESCRIPTION)); orderExtensionAddGatewayConfigDTO.setValue(configMap.get(ConfigConstant.GATEWAY_DESCRIPTION));
return orderExtensionAddGatewayConfigDTO; 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

@@ -28,6 +28,11 @@ gateway.config.name = integrationTest_SD
gateway.config.value = 127.0.0.1 gateway.config.value = 127.0.0.1
gateway.config.description = integrationTest gateway.config.description = integrationTest
# 测试账号
account.username = integrationTest
account.password = integrationTest
account.role = 0