Skip to content

Commit

Permalink
Adjust integration tests for common modules in the core module to com…
Browse files Browse the repository at this point in the history
…ply with checkstyle. (#12349)

* Fix exception code error.(#10925)

* [IT]Adjust integration tests for ability, base, and client modules in the core module to comply with checkstyle.

* [IT]Optimize the class naming.

* [IT]Adjust integration tests for common modules in the core module to comply with checkstyle.
  • Loading branch information
stone-98 authored Jul 18, 2024
1 parent c717538 commit 4f827ca
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,33 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* This class contains integration tests for the FileTypeEnum enumeration. It verifies the functionality of the
* getFileTypeEnumByFileExtensionOrFileType method. The tests ensure that the FileTypeEnum correctly maps file
* extensions and file types to their respective enum values.
*
* @author by jiangmin.wu on 2020/12/30
*/
class FileTypeEnum_ITCase {
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
class FileTypeEnumCoreITCase {

@Test
void fileTypeEnum_test1() {
void fileTypeEnumTest1() {
for (FileTypeEnum value : FileTypeEnum.values()) {
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.name());
assertEquals(fileTypeEnum, value);
}
}

@Test
void fileTypeEnum_test2() {
void fileTypeEnumTest2() {
for (FileTypeEnum value : FileTypeEnum.values()) {
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType(value.getFileType());
assertNotNull(fileTypeEnum);
}
}

@Test
void fileTypeEnum_test3() {
void fileTypeEnumTest3() {
FileTypeEnum fileTypeEnum = FileTypeEnum.getFileTypeEnumByFileExtensionOrFileType("t");
assertEquals(FileTypeEnum.TEXT, fileTypeEnum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,51 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* NacosAsyncRestTemplate_ITCase.
* This class provides integration tests for NacosAsyncRestTemplate. These tests cover various HTTP methods such as
* POST, GET, PUT, and DELETE to ensure the correct functioning of asynchronous HTTP requests in the context of Nacos.
*
* @author mai.jh
*/
@SuppressWarnings("all")
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@TestMethodOrder(MethodName.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class NacosAsyncRestTemplate_ITCase {
class NacosAsyncRestTemplateCoreITCase {

private static final HttpClientFactory PROCESSOR_ASYNC_HTTP_CLIENT_FACTORY = new ProcessorHttpClientFactory();

private final String CONFIG_INSTANCE_PATH = "/nacos/v1/ns";
private static final String CONFIG_INSTANCE_PATH = "/nacos/v1/ns";

private final NacosAsyncRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(
LoggerFactory.getLogger(NacosAsyncRestTemplateCoreITCase.class));

@SuppressWarnings("deprecation")
@LocalServerPort
private int port;

private NacosAsyncRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(
LoggerFactory.getLogger(NacosAsyncRestTemplate_ITCase.class));

private NacosAsyncRestTemplate processorRestTemplate = null;

private String IP = null;
private String ip = null;

@Autowired
private Environment environment;

@BeforeEach
void init() throws NacosException {
IP = String.format("http://localhost:%d", port);
ip = String.format("http://localhost:%d", port);
EnvUtil.setEnvironment((ConfigurableEnvironment) environment);
processorRestTemplate = HttpClientBeanHolder.getNacosAsyncRestTemplate(PROCESSOR_ASYNC_HTTP_CLIENT_FACTORY);
}

@Test
void test_url_post_form() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
void testUrlPostForm() throws Exception {
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test");
param.put("port", "8080");
param.put("ip", "11.11.11.11");
CallbackMap<String> callbackMap = new CallbackMap<>();
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
Thread.sleep(2000);
HttpRestResult<String> restResult = callbackMap.getRestResult();
Expand All @@ -100,14 +102,15 @@ void test_url_post_form() throws Exception {
}

@Test
void test_url_post_form_by_processor() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
void testUrlPostFormByProcessor() throws Exception {
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test2");
param.put("port", "8080");
param.put("ip", "11.11.11.11");
CallbackMap<String> callbackMap = new CallbackMap<>();
processorRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
processorRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class,
callbackMap);
Thread.sleep(2000);
HttpRestResult<String> restResult = callbackMap.getRestResult();
System.out.println(restResult.getData());
Expand All @@ -116,13 +119,13 @@ void test_url_post_form_by_processor() throws Exception {
}

@Test
void test_url_put_form() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
void testUrlPutForm() throws Exception {
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test-change");
param.put("port", "8080");
param.put("ip", "11.11.11.11");
CallbackMap<String> callbackMap = new CallbackMap<>();
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
nacosRestTemplate.postForm(url, Header.newInstance(), Query.newInstance(), param, String.class, callbackMap);
Thread.sleep(2000);
HttpRestResult<String> restResult = callbackMap.getRestResult();
Expand All @@ -132,38 +135,39 @@ void test_url_put_form() throws Exception {
}

@Test
void test_url_get() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance/list";
void testUrlGet() throws Exception {
String url = ip + CONFIG_INSTANCE_PATH + "/instance/list";
Query query = Query.newInstance().addParam("serviceName", "app-test");
CallbackMap<Map> callbackMap = new CallbackMap<>();
CallbackMap<Map<String, String>> callbackMap = new CallbackMap<>();
nacosRestTemplate.get(url, Header.newInstance(), query, Map.class, callbackMap);
Thread.sleep(2000);
HttpRestResult<Map> restResult = callbackMap.getRestResult();
HttpRestResult<Map<String, String>> restResult = callbackMap.getRestResult();
System.out.println(restResult.getData());
System.out.println(restResult.getHeader());
assertTrue(restResult.ok());
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
}

@Test
void test_url_by_map() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance/list";
void testUrlByMap() throws Exception {
String url = ip + CONFIG_INSTANCE_PATH + "/instance/list";
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test");
CallbackMap<Map> callbackMap = new CallbackMap<>();
CallbackMap<Map<String, String>> callbackMap = new CallbackMap<>();
nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class, callbackMap);
Thread.sleep(2000);
HttpRestResult<Map> restResult = callbackMap.getRestResult();
HttpRestResult<Map<String, String>> restResult = callbackMap.getRestResult();
System.out.println(restResult.getData());
System.out.println(restResult.getHeader());
assertTrue(restResult.ok());
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
}

@Test
void test_url_delete() throws Exception {
String url = IP + CONFIG_INSTANCE_PATH + "/instance";
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test");
void testUrlDelete() throws Exception {
String url = ip + CONFIG_INSTANCE_PATH + "/instance";
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080")
.addParam("serviceName", "app-test");
CallbackMap<String> callbackMap = new CallbackMap<>();
nacosRestTemplate.delete(url, Header.newInstance(), query, String.class, callbackMap);
Thread.sleep(2000);
Expand All @@ -173,7 +177,7 @@ void test_url_delete() throws Exception {
assertTrue(restResult.ok());
}

private class CallbackMap<T> implements Callback<T> {
private static class CallbackMap<T> implements Callback<T> {

private HttpRestResult<T> restResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,38 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* NacosRestTemplate_ITCase.
* Integration tests for NacosRestTemplate.This class contains integration tests for NacosRestTemplate using various
* HTTP methods.
*
* @author mai.jh
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestMethodOrder(MethodName.class)
class NacosRestTemplate_ITCase {
class NacosRestTemplateCoreITCase {

private final String INSTANCE_PATH = "/nacos/v1/ns";
private static final String INSTANCE_PATH = "/nacos/v1/ns";

private final String CONFIG_PATH = "/nacos/v1/cs";
private static final String CONFIG_PATH = "/nacos/v1/cs";

private final NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate(
LoggerFactory.getLogger(NacosRestTemplateCoreITCase.class));

@LocalServerPort
private int port;

private NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate(
LoggerFactory.getLogger(NacosRestTemplate_ITCase.class));

private String IP = null;
private String ip = null;

@BeforeEach
void init() throws NacosException {
IP = String.format("http://localhost:%d", port);
ip = String.format("http://localhost:%d", port);
}

@Test
void test_url_post_config() throws Exception {
String url = IP + CONFIG_PATH + "/configs";
void testUrlPostConfig() throws Exception {
String url = ip + CONFIG_PATH + "/configs";
Map<String, String> param = new HashMap<>();
param.put("dataId", "test-1");
param.put("group", "DEFAULT_GROUP");
Expand All @@ -85,9 +87,10 @@ void test_url_post_config() throws Exception {
}

@Test
void test_url_get_return_restResult() throws Exception {
String url = IP + CONFIG_PATH + "/configs";
Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1").addParam("group", "DEFAULT_GROUP");
void testUrlGetReturnRestResult() throws Exception {
String url = ip + CONFIG_PATH + "/configs";
Query query = Query.newInstance().addParam("beta", true).addParam("dataId", "test-1")
.addParam("group", "DEFAULT_GROUP");
HttpRestResult<ConfigInfo4Beta> restResult = nacosRestTemplate.get(url, Header.newInstance(), query,
new TypeReference<RestResult<ConfigInfo4Beta>>() {
}.getType());
Expand All @@ -96,10 +99,9 @@ void test_url_get_return_restResult() throws Exception {
System.out.println(restResult.getHeader());
}


@Test
void test_url_post_form() throws Exception {
String url = IP + INSTANCE_PATH + "/instance";
void testUrlPostForm() throws Exception {
String url = ip + INSTANCE_PATH + "/instance";
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test");
param.put("port", "8080");
Expand All @@ -111,8 +113,8 @@ void test_url_post_form() throws Exception {

@Test
@Disabled("new version can't update instance when service and instance is not exist")
void test_url_put_from() throws Exception {
String url = IP + INSTANCE_PATH + "/instance";
void testUrlPutFrom() throws Exception {
String url = ip + INSTANCE_PATH + "/instance";
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test-change");
param.put("port", "8080");
Expand All @@ -123,30 +125,33 @@ void test_url_put_from() throws Exception {
}

@Test
void test_url_get() throws Exception {
String url = IP + INSTANCE_PATH + "/instance/list";
void testUrlGet() throws Exception {
String url = ip + INSTANCE_PATH + "/instance/list";
Query query = Query.newInstance().addParam("serviceName", "app-test");
HttpRestResult<Map> restResult = nacosRestTemplate.get(url, Header.newInstance(), query, Map.class);
HttpRestResult<Map<String, String>> restResult = nacosRestTemplate.get(url, Header.newInstance(), query,
Map.class);
assertTrue(restResult.ok());
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
System.out.println(restResult.getData());
}

@Test
void test_url_get_by_map() throws Exception {
String url = IP + INSTANCE_PATH + "/instance/list";
void testUrlGetByMap() throws Exception {
String url = ip + INSTANCE_PATH + "/instance/list";
Map<String, String> param = new HashMap<>();
param.put("serviceName", "app-test");
HttpRestResult<Map> restResult = nacosRestTemplate.get(url, Header.newInstance(), Query.newInstance().initParams(param), Map.class);
HttpRestResult<Map<String, String>> restResult = nacosRestTemplate.get(url, Header.newInstance(),
Query.newInstance().initParams(param), Map.class);
assertTrue(restResult.ok());
assertEquals("DEFAULT_GROUP@@app-test", restResult.getData().get("name"));
System.out.println(restResult.getData());
}

@Test
void test_url_delete() throws Exception {
String url = IP + INSTANCE_PATH + "/instance";
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080").addParam("serviceName", "app-test");
void testUrlDelete() throws Exception {
String url = ip + INSTANCE_PATH + "/instance";
Query query = Query.newInstance().addParam("ip", "11.11.11.11").addParam("port", "8080")
.addParam("serviceName", "app-test");
HttpRestResult<String> restResult = nacosRestTemplate.delete(url, Header.newInstance(), query, String.class);
assertTrue(restResult.ok());
System.out.println(restResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,45 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* NacosRestTemplate_Interceptors_ITCase
* Integration tests for NacosRestTemplateInterceptorsCoreITCase.These tests verify the functionality of HTTP request
* interceptors in NacosRestTemplate.
*
* @author mai.jh
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = Nacos.class, properties = {
"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestMethodOrder(MethodName.class)
class NacosRestTemplate_Interceptors_ITCase {
class NacosRestTemplateInterceptorsCoreITCase {

private final String CONFIG_PATH = "/nacos/v1/cs";
private static final String CONFIG_PATH = "/nacos/v1/cs";

private final NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate(
LoggerFactory.getLogger(NacosRestTemplateInterceptorsCoreITCase.class));

@SuppressWarnings("deprecation")
@LocalServerPort
private int port;

private NacosRestTemplate nacosRestTemplate = HttpClientBeanHolder.getNacosRestTemplate(
LoggerFactory.getLogger(NacosRestTemplate_Interceptors_ITCase.class));

private String IP = null;
private String ip = null;

@BeforeEach
void init() throws NacosException {
nacosRestTemplate.setInterceptors(Arrays.asList(new TerminationInterceptor()));
IP = String.format("http://localhost:%d", port);
nacosRestTemplate.setInterceptors(Collections.singletonList(new TerminationInterceptor()));
ip = String.format("http://localhost:%d", port);
}

@Test
void test_url_post_config() throws Exception {
String url = IP + CONFIG_PATH + "/configs";
void testUrlPostConfig() throws Exception {
String url = ip + CONFIG_PATH + "/configs";
Map<String, String> param = new HashMap<>();
param.put("dataId", "test-1");
param.put("group", "DEFAULT_GROUP");
Expand All @@ -86,7 +89,7 @@ void test_url_post_config() throws Exception {
System.out.println(restResult.getHeader());
}

private class TerminationInterceptor implements HttpClientRequestInterceptor {
private static class TerminationInterceptor implements HttpClientRequestInterceptor {

@Override
public HttpClientResponse intercept() {
Expand Down
Loading

0 comments on commit 4f827ca

Please sign in to comment.