-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(xxl-rpc):重构 OpenApiControllerTest 并添加新的数据传输对象
- 将 OpenApiControllerTest 类移动到新的包 com.xxl.rpc.admin.registry.openapi - 重写测试方法,使用新的数据传输对象 XxlRpcRegisterDTO - 添加新的数据传输对象类: - RegisterInstance -
- Loading branch information
Showing
3 changed files
with
479 additions
and
82 deletions.
There are no files selected for viewing
82 changes: 0 additions & 82 deletions
82
xxl-rpc-admin/src/test/java/com/xxl/rpc/admin/registry/OpenApiControllerTest.java
This file was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
xxl-rpc-admin/src/test/java/com/xxl/rpc/admin/registry/openapi/OpenApiControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.xxl.rpc.admin.registry.openapi; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.xxl.rpc.admin.registry.model.*; | ||
import com.xxl.tool.net.HttpTool; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.context.request.async.DeferredResult; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
public class OpenApiControllerTest { | ||
private static final Logger logger = LoggerFactory.getLogger(OpenApiControllerTest.class); | ||
|
||
// admin-client | ||
private static String adminAddress = "http://127.0.0.1:8080/xxl-rpc-admin"; | ||
|
||
|
||
@Test | ||
public void test_register() { | ||
|
||
// 1、register | ||
XxlRpcRegisterDTO.RegisterRequest request = new XxlRpcRegisterDTO.RegisterRequest(); | ||
request.setAccessToken("defaultaccesstoken"); | ||
request.setEnv("test"); | ||
request.setInstance(new XxlRpcRegisterDTO.RegisterInstance("app01", "127.0.0.1", 8080, "{}")); | ||
|
||
String responseBody = HttpTool.postBody(adminAddress + "/openapi/register", | ||
JSON.toJSONString(request), | ||
null, | ||
3000); | ||
|
||
XxlRpcRegisterDTO.OpenApiResponse openApiResponse = JSON.parseObject(responseBody, XxlRpcRegisterDTO.OpenApiResponse.class); | ||
|
||
logger.info("result:{}, request:{}, responseBody:{}", openApiResponse.isSuccess()?"success":"fail", request, responseBody); | ||
} | ||
|
||
@Test | ||
public void test_unregister() { | ||
|
||
// 2、unregister | ||
XxlRpcRegisterDTO.RegisterRequest request = new XxlRpcRegisterDTO.RegisterRequest(); | ||
request.setAccessToken("defaultaccesstoken"); | ||
request.setEnv("test"); | ||
request.setInstance(new XxlRpcRegisterDTO.RegisterInstance("app01", "127.0.0.1", 8080, "{}")); | ||
|
||
String responseBody = HttpTool.postBody(adminAddress + "/openapi/unregister", | ||
JSON.toJSONString(request), | ||
null, | ||
3000); | ||
|
||
XxlRpcRegisterDTO.OpenApiResponse openApiResponse = JSON.parseObject(responseBody, XxlRpcRegisterDTO.OpenApiResponse.class); | ||
logger.info("result:{}, request:{}, responseBody:{}", openApiResponse.isSuccess()?"success":"fail", request, responseBody); | ||
} | ||
|
||
@Test | ||
public void test_discovery() { | ||
|
||
// 3、discovery | ||
XxlRpcRegisterDTO.DiscoveryRequest request = new XxlRpcRegisterDTO.DiscoveryRequest(); | ||
request.setAccessToken("defaultaccesstoken"); | ||
request.setEnv("test"); | ||
request.setAppnameList(Arrays.asList("app01", "app02")); | ||
request.setSimpleQuery(false); | ||
|
||
String responseBody = HttpTool.postBody(adminAddress + "/openapi/discovery", | ||
JSON.toJSONString(request), | ||
null, | ||
3000 | ||
); | ||
XxlRpcRegisterDTO.DiscoveryResponse discoveryResponse = JSON.parseObject(responseBody, XxlRpcRegisterDTO.DiscoveryResponse.class); | ||
logger.info("result:{}, request:{}, responseBody:{}", discoveryResponse.isSuccess()?"success":"fail", request, responseBody); | ||
} | ||
|
||
@Test | ||
public void test_monitor() { | ||
|
||
// 4、monitor | ||
DiscoveryRequest request = new DiscoveryRequest(); | ||
request.setAccessToken("defaultaccesstoken"); | ||
request.setEnv("test"); | ||
request.setAppnameList(Arrays.asList("app01", "app02")); | ||
request.setSimpleQuery(false); | ||
|
||
String responseBody = HttpTool.postBody(adminAddress + "/openapi/monitor", | ||
JSON.toJSONString(request), | ||
null, | ||
3000); | ||
|
||
DeferredResult<OpenApiResponse<String>> discoveryResponse = JSON.parseObject(responseBody, DeferredResult.class); | ||
OpenApiResponse<String> result = (OpenApiResponse<String>) discoveryResponse.getResult(); | ||
logger.info("result:{}, request:{}, responseBody:{}", result.isSuccess()?"success":"fail", request, responseBody); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.