Skip to content

Commit 39a6302

Browse files
author
xuguang
committed
部分controller接口集成测试
1 parent 05ceeea commit 39a6302

30 files changed

+2439
-531
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import com.xiaojukeji.kafka.manager.common.entity.Result;
5+
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
6+
import com.xiaojukeji.kafka.manager.web.config.ConfigConstant;
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/18
18+
*/
19+
public class GatewayHeartbeatControllerTest extends BaseTest {
20+
21+
@BeforeClass
22+
public void init() {
23+
super.init();
24+
}
25+
26+
@Test(description = "测试连接信息上报")
27+
public void getSecurityAcls() {
28+
String url = baseUrl + "/gateway/api/v1/heartbeat/survive-user?clusterId=" + physicalClusterId
29+
+ "&brokerId=" + configMap.get(ConfigConstant.ALIVE_BROKER_ID);
30+
31+
JSONObject jsonObject = new JSONObject();
32+
HttpEntity<JSONObject> httpEntity = new HttpEntity<>(jsonObject, httpHeaders);
33+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
34+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
35+
Assert.assertNotNull(result.getBody());
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
2+
3+
import com.xiaojukeji.kafka.manager.web.config.BaseTest;
4+
import org.springframework.http.HttpEntity;
5+
import org.springframework.http.HttpMethod;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
8+
import org.testng.Assert;
9+
import org.testng.annotations.BeforeClass;
10+
import org.testng.annotations.Test;
11+
12+
/**
13+
* @author xuguang
14+
* @Date 2022/2/18
15+
*/
16+
public class GatewayReportControllerTest extends BaseTest {
17+
18+
@BeforeClass
19+
public void init() {
20+
super.init();
21+
}
22+
23+
@Test(description = "测试查询开启JMX采集的Topic")
24+
public void getDiscoveryAddress() {
25+
String url = baseUrl + "/gateway/api/v1/report/jmx/topics?clusterId=" + physicalClusterId;
26+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
27+
ResponseEntity<String> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
28+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
29+
Assert.assertNotNull(result.getBody());
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
2+
3+
import com.xiaojukeji.kafka.manager.common.entity.Result;
4+
import com.xiaojukeji.kafka.manager.common.entity.dto.gateway.KafkaAclSearchDTO;
5+
import com.xiaojukeji.kafka.manager.common.entity.dto.gateway.KafkaUserSearchDTO;
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/18
18+
*/
19+
public class GatewaySecurityControllerTest extends BaseTest {
20+
21+
@BeforeClass
22+
public void init() {
23+
super.init();
24+
}
25+
26+
private KafkaAclSearchDTO getKafkaAclSearchDTO() {
27+
KafkaAclSearchDTO kafkaAclSearchDTO = new KafkaAclSearchDTO();
28+
kafkaAclSearchDTO.setClusterId(physicalClusterId);
29+
kafkaAclSearchDTO.setStart(0L);
30+
long now = System.currentTimeMillis();
31+
kafkaAclSearchDTO.setEnd(now);
32+
return kafkaAclSearchDTO;
33+
}
34+
35+
private KafkaUserSearchDTO getKafkaUserSearchDTO() {
36+
KafkaUserSearchDTO kafkaUserSearchDTO = new KafkaUserSearchDTO();
37+
kafkaUserSearchDTO.setStart(0L);
38+
long now = System.currentTimeMillis();
39+
kafkaUserSearchDTO.setEnd(now);
40+
return kafkaUserSearchDTO;
41+
}
42+
43+
@Test(description = "测试查询Kafka用户权限查询")
44+
public void getSecurityAcls() {
45+
String url = baseUrl + "/gateway/api/v1/security/acls";
46+
HttpEntity<KafkaAclSearchDTO> httpEntity = new HttpEntity<>(getKafkaAclSearchDTO(), httpHeaders);
47+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
48+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
49+
Assert.assertNotNull(result.getBody());
50+
}
51+
52+
@Test(description = "测试查询Kafka用户查询")
53+
public void getSecurityUsers() {
54+
String url = baseUrl + "/gateway/api/v1/security/users";
55+
HttpEntity<KafkaUserSearchDTO> httpEntity = new HttpEntity<>(getKafkaUserSearchDTO(), httpHeaders);
56+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.POST, httpEntity, Result.class);
57+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
58+
Assert.assertNotNull(result.getBody());
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.xiaojukeji.kafka.manager.web.api.versionone.gateway;
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.web.config.BaseTest;
6+
import org.springframework.http.HttpEntity;
7+
import org.springframework.http.HttpMethod;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.ResponseEntity;
10+
import org.testng.Assert;
11+
import org.testng.annotations.BeforeClass;
12+
import org.testng.annotations.Test;
13+
14+
/**
15+
* @author xuguang
16+
* @Date 2022/2/18
17+
*/
18+
public class GatewayServiceDiscoveryControllerTest extends BaseTest {
19+
20+
@BeforeClass
21+
public void init() {
22+
super.init();
23+
}
24+
25+
@Test(description = "测试获取指定集群服务地址")
26+
public void getDiscoveryAddress() {
27+
String url = baseUrl + "/gateway/api/v1/discovery/address?clusterId=" + physicalClusterId;
28+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
29+
ResponseEntity<String> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);
30+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
31+
Assert.assertNotNull(result.getBody());
32+
}
33+
34+
@Test(description = "测试获取最大App请求速率")
35+
public void getDiscoveryAppIdRate() {
36+
String url = baseUrl + "/gateway/api/v1/discovery/appId-rate?versionNumber=1";
37+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
38+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
39+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
40+
Assert.assertNotNull(result.getBody());
41+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
42+
}
43+
44+
@Test(description = "测试获取集群服务地址")
45+
public void getDiscoveryInit() {
46+
String url = baseUrl + "/gateway/api/v1/discovery/init";
47+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
48+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
49+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
50+
Assert.assertNotNull(result.getBody());
51+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
52+
}
53+
54+
@Test(description = "测试获取最大IP请求速率")
55+
public void getDiscoveryIpRate() {
56+
String url = baseUrl + "/gateway/api/v1/discovery/ip-rate?versionNumber=1";
57+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
58+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
59+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
60+
Assert.assertNotNull(result.getBody());
61+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
62+
}
63+
64+
@Test(description = "测试获取最大并发请求数")
65+
public void getDiscoveryMaxRequestNum() {
66+
String url = baseUrl + "/gateway/api/v1/discovery/max-request-num?versionNumber=1";
67+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
68+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
69+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
70+
Assert.assertNotNull(result.getBody());
71+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
72+
}
73+
74+
@Test(description = "测试最大SP请求速率")
75+
public void getDiscoverySpLimit() {
76+
String url = baseUrl + "/gateway/api/v1/discovery/sp-limit?versionNumber=1";
77+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
78+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
79+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
80+
Assert.assertNotNull(result.getBody());
81+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
82+
}
83+
84+
@Test(description = "测试获取集群服务地址")
85+
public void getDiscoveryUpdate() {
86+
String url = baseUrl + "/gateway/api/v1/discovery/update?versionNumber=1";
87+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
88+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
89+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
90+
Assert.assertNotNull(result.getBody());
91+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
92+
}
93+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.web.config.BaseTest;
6+
import org.springframework.http.HttpEntity;
7+
import org.springframework.http.HttpMethod;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.ResponseEntity;
10+
import org.testng.Assert;
11+
import org.testng.annotations.BeforeClass;
12+
import org.testng.annotations.Test;
13+
14+
/**
15+
* @author xuguang
16+
* @Date 2022/2/18
17+
*/
18+
public class NormalAccountControllerTest extends BaseTest {
19+
20+
@BeforeClass
21+
public void init() {
22+
super.init();
23+
}
24+
25+
@Test(description = "测试账号搜索")
26+
public void getAccountsTest() {
27+
String url = baseUrl + "/api/v1/normal/accounts?keyWord=admin";
28+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
29+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
30+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
31+
Assert.assertNotNull(result.getBody());
32+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
33+
}
34+
35+
@Test(description = "测试查询角色")
36+
public void getAccountTest() {
37+
String url = baseUrl + "/api/v1/normal/accounts/account";
38+
HttpEntity<String> httpEntity = new HttpEntity<>("", httpHeaders);
39+
ResponseEntity<Result> result = testRestTemplate.exchange(url, HttpMethod.GET, httpEntity, Result.class);
40+
Assert.assertEquals(result.getStatusCodeValue(), HttpStatus.OK.value());
41+
Assert.assertNotNull(result.getBody());
42+
Assert.assertEquals(result.getBody().getCode(), ResultStatus.SUCCESS.getCode());
43+
}
44+
}

0 commit comments

Comments
 (0)