Skip to content

Commit e120b32

Browse files
author
xuguang
committed
剩余controller接口集成测试
1 parent de54966 commit e120b32

27 files changed

+2135
-3
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone;
2+
3+
import com.xiaojukeji.kafka.manager.common.entity.Result;
4+
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
5+
import com.xiaojukeji.kafka.manager.common.entity.dto.normal.LoginDTO;
6+
import com.xiaojukeji.kafka.manager.common.entity.dto.rd.OperateRecordDTO;
7+
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
8+
import org.springframework.http.HttpEntity;
9+
import org.springframework.http.HttpMethod;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.testng.Assert;
13+
import org.testng.annotations.BeforeClass;
14+
import org.testng.annotations.Test;
15+
16+
/**
17+
* @author xuguang
18+
* @Date 2022/2/21
19+
*/
20+
public class LoginControllerTest extends BaseTest {
21+
22+
@BeforeClass
23+
public void init() {
24+
super.init();
25+
}
26+
27+
@Test(description = "测试登陆")
28+
public void loginTest() {
29+
LoginDTO loginDTO = new LoginDTO();
30+
loginDTO.setUsername("admin");
31+
loginDTO.setPassword("admin");
32+
33+
String url = baseUrl + "/api/v1/sso/login";
34+
HttpEntity<LoginDTO> httpEntity = new HttpEntity<>(loginDTO, httpHeaders);
35+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
36+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
37+
Assert.assertNotNull(result.getBody());
38+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
39+
}
40+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
2+
3+
import com.xiaojukeji.kafka.manager.common.entity.Result;
4+
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
5+
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
6+
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
7+
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
8+
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
9+
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
10+
import org.springframework.http.HttpEntity;
11+
import org.springframework.http.HttpMethod;
12+
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.ResponseEntity;
14+
import org.testng.Assert;
15+
import org.testng.annotations.AfterClass;
16+
import org.testng.annotations.BeforeClass;
17+
import org.testng.annotations.Test;
18+
19+
import java.util.Arrays;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
/**
25+
* @author xuguang
26+
* @Date 2022/2/22
27+
*/
28+
public class NormalConsumerControllerTest extends BaseTest {
29+
30+
@BeforeClass
31+
public void init() {
32+
super.init();
33+
34+
String url = baseUrl + "/api/v1/op/topics";
35+
createCommonTopic(url);
36+
}
37+
38+
@AfterClass
39+
public void afterTest() {
40+
// 删除Topic成功
41+
String url = baseUrl + "/api/v1/op/topics";
42+
deleteTopics(url);
43+
}
44+
45+
private void createCommonTopic(String url) {
46+
// 创建Topic
47+
48+
TopicCreationDTO creationDTO = CustomDataSource.getTopicCreationDTO(configMap);
49+
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
50+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
51+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
52+
Assert.assertNotNull(result.getBody());
53+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
54+
}
55+
56+
private void deleteTopics(String url) {
57+
// 删除创建的topic
58+
TopicDeletionDTO topicDeletionDTO = CustomDataSource.getTopicDeletionDTO(configMap);
59+
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
60+
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
61+
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
62+
Assert.assertNotNull(result2.getBody());
63+
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
64+
}
65+
66+
@Test(description = "测试重置Topic消费偏移")
67+
public void resetOffsetTest() {
68+
69+
}
70+
71+
@Test(description = "测试查询消费Topic的消费组")
72+
public void getConsumerGroups() {
73+
String url = baseUrl + "/api/v1/normal/{clusterId}/consumers/{topicName}/consumer-groups";
74+
75+
Map<String, Object> mp = new HashMap<>();
76+
mp.put("clusterId", configMap.get(ConfigConstant.LOGICAL_CLUSTER_ID));
77+
mp.put("topicName", configMap.get(ConfigConstant.TOPIC_NAME));
78+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
79+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class, mp);
80+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
81+
Assert.assertNotNull(result.getBody());
82+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
83+
}
84+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
2+
3+
import com.xiaojukeji.kafka.manager.common.entity.Result;
4+
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
5+
import com.xiaojukeji.kafka.manager.common.entity.dto.normal.JmxSwitchDTO;
6+
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicCreationDTO;
7+
import com.xiaojukeji.kafka.manager.common.entity.dto.op.topic.TopicDeletionDTO;
8+
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
9+
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
10+
import com.xiaojukeji.kafka.manager.web.config.CustomDataSource;
11+
import org.springframework.http.HttpEntity;
12+
import org.springframework.http.HttpMethod;
13+
import org.springframework.http.HttpStatus;
14+
import org.springframework.http.ResponseEntity;
15+
import org.testng.Assert;
16+
import org.testng.annotations.AfterClass;
17+
import org.testng.annotations.BeforeClass;
18+
import org.testng.annotations.Test;
19+
20+
import java.util.Arrays;
21+
import java.util.List;
22+
23+
/**
24+
* @author xuguang
25+
* @Date 2022/2/21
26+
*/
27+
public class NormalJmxControllerTest extends BaseTest {
28+
29+
@BeforeClass
30+
public void init() {
31+
super.init();
32+
33+
String url = baseUrl + "/api/v1/op/topics";
34+
createCommonTopic(url);
35+
}
36+
37+
@AfterClass
38+
public void afterTest() {
39+
// 删除Topic成功
40+
String url = baseUrl + "/api/v1/op/topics";
41+
deleteTopics(url);
42+
}
43+
44+
private JmxSwitchDTO getJmxSwitchDTO() {
45+
JmxSwitchDTO jmxSwitchDTO = new JmxSwitchDTO();
46+
jmxSwitchDTO.setClusterId(physicalClusterId);
47+
jmxSwitchDTO.setPhysicalClusterId(true);
48+
jmxSwitchDTO.setTopicName(configMap.get(ConfigConstant.TOPIC_NAME));
49+
jmxSwitchDTO.setOpenAppIdTopicMetrics(false);
50+
jmxSwitchDTO.setOpenDiskMetrics(false);
51+
jmxSwitchDTO.setOpenClientRequestMetrics(false);
52+
jmxSwitchDTO.setOpenTopicRequestMetrics(false);
53+
return jmxSwitchDTO;
54+
}
55+
56+
private void createCommonTopic(String url) {
57+
// 创建Topic
58+
59+
TopicCreationDTO creationDTO = CustomDataSource.getTopicCreationDTO(configMap);
60+
HttpEntity<TopicCreationDTO> httpEntity = new HttpEntity<>(creationDTO, httpHeaders);
61+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
62+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
63+
Assert.assertNotNull(result.getBody());
64+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
65+
}
66+
67+
private void deleteTopics(String url) {
68+
// 删除创建的topic
69+
TopicDeletionDTO topicDeletionDTO = CustomDataSource.getTopicDeletionDTO(configMap);
70+
HttpEntity<List<TopicDeletionDTO>> httpEntity2 = new HttpEntity<>(Arrays.asList(topicDeletionDTO), httpHeaders);
71+
ResponseEntity<Result> result2 = testRestTemplate.exchange(url, HttpMethod.DELETE, httpEntity2, Result.class);
72+
Assert.assertEquals(result2.getStatusCodeValue(), HttpStatus.OK.value());
73+
Assert.assertNotNull(result2.getBody());
74+
Assert.assertEquals(result2.getBody().getCode(), ResultStatus.SUCCESS.getCode());
75+
}
76+
77+
@Test(description = "测试开启TopicJMX")
78+
public void jmxSwitchTest() {
79+
JmxSwitchDTO jmxSwitchDTO = getJmxSwitchDTO();
80+
81+
String url = baseUrl + "/api/v1/normal/jmx-switch";
82+
HttpEntity<JmxSwitchDTO> httpEntity = new HttpEntity<>(jmxSwitchDTO, httpHeaders);
83+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
84+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
85+
Assert.assertNotNull(result.getBody());
86+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
87+
}
88+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.normal;
2+
3+
import com.xiaojukeji.kafka.manager.common.entity.Result;
4+
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
5+
import com.xiaojukeji.kafka.manager.monitor.common.entry.dto.MonitorRuleDTO;
6+
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
7+
import org.springframework.http.HttpEntity;
8+
import org.springframework.http.HttpMethod;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.testng.Assert;
12+
import org.testng.annotations.BeforeClass;
13+
import org.testng.annotations.Test;
14+
15+
/**
16+
* @author xuguang
17+
* @Date 2022/2/22
18+
*/
19+
public class NormalMonitorControllerTest extends BaseTest {
20+
21+
@BeforeClass
22+
public void init() {
23+
super.init();
24+
25+
String url = baseUrl + "/api/v1/op/topics";
26+
// createCommonTopic(url);
27+
28+
}
29+
30+
// private MonitorRuleDTO getMonitorRuleDTO() {
31+
// MonitorRuleDTO monitorRuleDTO = new MonitorRuleDTO();
32+
// monitorRuleDTO.set
33+
// }
34+
35+
@Test(description = "测试告警屏蔽创建")
36+
public void monitorSilences() {
37+
String url = baseUrl + "/api/v1/normal/monitor-silences";
38+
39+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
40+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
41+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
42+
Assert.assertNotNull(result.getBody());
43+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
44+
}
45+
}

0 commit comments

Comments
 (0)