From de5ade75c830d3bc59df6f270ea2fd8d9ec24075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E9=AD=81?= <670569467@qq.com> Date: Mon, 15 Jul 2024 11:17:48 +0800 Subject: [PATCH] Adjust integration tests for ability, base, and client modules in the core module to comply with checkstyle. (#12335) * 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. --- .../TestServerAbilityControlManager.java | 2 +- .../nacos/test/base/HttpClient4Test.java | 11 ++++++---- .../com/alibaba/nacos/test/base/Params.java | 19 +++++++++++++++++ ...onV1ServerNonCompatibilityCoreITCase.java} | 16 +++++++------- ...figIntegrationV2MutualAuthCoreITCase.java} | 13 ++++++------ ...ava => ConfigIntegrationV3CoreITCase.java} | 21 ++++++++++--------- 6 files changed, 54 insertions(+), 28 deletions(-) rename test/core-test/src/test/java/com/alibaba/nacos/test/client/{ConfigIntegrationV1ServerNonCompatibility_CITCase.java => ConfigIntegrationV1ServerNonCompatibilityCoreITCase.java} (90%) rename test/core-test/src/test/java/com/alibaba/nacos/test/client/{ConfigIntegrationV2MutualAuth_CITCase.java => ConfigIntegrationV2MutualAuthCoreITCase.java} (93%) rename test/core-test/src/test/java/com/alibaba/nacos/test/client/{ConfigIntegrationV3_CITCase.java => ConfigIntegrationV3CoreITCase.java} (90%) diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/ability/component/TestServerAbilityControlManager.java b/test/core-test/src/test/java/com/alibaba/nacos/test/ability/component/TestServerAbilityControlManager.java index 2fc4a27ed..5a7a1a5c0 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/ability/component/TestServerAbilityControlManager.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/ability/component/TestServerAbilityControlManager.java @@ -30,7 +30,7 @@ public class TestServerAbilityControlManager extends ServerAbilityControlManager Map map = new HashMap<>(); map.put(AbilityKey.SERVER_TEST_1, true); map.put(AbilityKey.SERVER_TEST_2, false); - HashMap res = new HashMap<>(); + HashMap> res = new HashMap<>(); res.put(AbilityMode.SERVER, map); Map map1 = new HashMap<>(); diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/base/HttpClient4Test.java b/test/core-test/src/test/java/com/alibaba/nacos/test/base/HttpClient4Test.java index 31fb3c6fc..fae9362f8 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/base/HttpClient4Test.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/base/HttpClient4Test.java @@ -28,7 +28,7 @@ import org.springframework.web.util.UriComponentsBuilder; import java.net.URL; /** - * Http client for test module + * Http client for test module. * * @author nkorange * @since 1.2.0 @@ -46,18 +46,21 @@ public class HttpClient4Test { HttpEntity entity = new HttpEntity(headers); - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.base.toString() + path).queryParams(params); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.base.toString() + path) + .queryParams(params); return this.restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, clazz); } - protected ResponseEntity request(String path, MultiValueMap params, Class clazz, HttpMethod httpMethod) { + protected ResponseEntity request(String path, MultiValueMap params, Class clazz, + HttpMethod httpMethod) { HttpHeaders headers = new HttpHeaders(); HttpEntity entity = new HttpEntity(headers); - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.base.toString() + path).queryParams(params); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(this.base.toString() + path) + .queryParams(params); return this.restTemplate.exchange(builder.toUriString(), httpMethod, entity, clazz); } diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/base/Params.java b/test/core-test/src/test/java/com/alibaba/nacos/test/base/Params.java index 442fd50fc..ea8583d4e 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/base/Params.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/base/Params.java @@ -20,23 +20,42 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; /** + * Utility class for building HTTP request parameters. + * * @author nkorange */ public class Params { private MultiValueMap paramMap; + /** + * Creates a new Params instance. + * + * @return A new Params instance. + */ public static Params newParams() { Params params = new Params(); params.paramMap = new LinkedMultiValueMap(); return params; } + /** + * Appends a parameter to the parameter map. + * + * @param name The name of the parameter. + * @param value The value of the parameter. + * @return This Params instance for method chaining. + */ public Params appendParam(String name, String value) { this.paramMap.add(name, value); return this; } + /** + * Retrieves the built parameter map. + * + * @return The built MultiValueMap containing all appended parameters. + */ public MultiValueMap done() { return paramMap; } diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV1ServerNonCompatibility_CITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV1ServerNonCompatibilityCoreITCase.java similarity index 90% rename from test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV1ServerNonCompatibility_CITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV1ServerNonCompatibilityCoreITCase.java index 1bd43ddc6..ff966b3e8 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV1ServerNonCompatibility_CITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV1ServerNonCompatibilityCoreITCase.java @@ -48,13 +48,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * * @author githubcheng2978 */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") @TestConfiguration @SpringBootTest(classes = {Nacos.class}, properties = {"server.servlet.context-path=/nacos", RpcConstants.NACOS_SERVER_RPC + ".compatibility=false", RpcConstants.NACOS_SERVER_RPC + ".enableTls=true", - RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem", - RpcConstants.NACOS_SERVER_RPC + ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) + RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem", RpcConstants.NACOS_SERVER_RPC + + ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @Disabled("TODO, Fix cert expired problem") -public class ConfigIntegrationV1ServerNonCompatibility_CITCase { +public class ConfigIntegrationV1ServerNonCompatibilityCoreITCase { public static AtomicInteger increment = new AtomicInteger(100); @@ -63,7 +64,8 @@ public class ConfigIntegrationV1ServerNonCompatibility_CITCase { @BeforeAll static void beforeClass() throws IOException { - ConfigCleanUtils.changeToNewTestNacosHome(ConfigIntegrationV1ServerNonCompatibility_CITCase.class.getSimpleName()); + ConfigCleanUtils.changeToNewTestNacosHome( + ConfigIntegrationV1ServerNonCompatibilityCoreITCase.class.getSimpleName()); } @BeforeAll @@ -73,7 +75,7 @@ public class ConfigIntegrationV1ServerNonCompatibility_CITCase { } @Test - void test_a_TlsServer() throws Exception { + void testTlsServer() throws Exception { RpcClient client = RpcClientFactory.createClient("testTlsServer", ConnectionType.GRPC, Collections.singletonMap("labelKey", "labelValue"), null); RpcClient.ServerInfo serverInfo = new RpcClient.ServerInfo(); @@ -85,7 +87,7 @@ public class ConfigIntegrationV1ServerNonCompatibility_CITCase { } @Test - void test_b_ServerTlsTrustAll() throws Exception { + void testServerTlsTrustAll() throws Exception { RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig(); tlsConfig.setEnableTls(true); tlsConfig.setTrustAll(true); @@ -108,7 +110,7 @@ public class ConfigIntegrationV1ServerNonCompatibility_CITCase { } @Test - void test_c_ServerTlsTrustCa() throws Exception { + void testServerTlsTrustCa() throws Exception { RpcClient.ServerInfo serverInfo = new RpcClient.ServerInfo(); serverInfo.setServerIp("127.0.0.1"); diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV2MutualAuth_CITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV2MutualAuthCoreITCase.java similarity index 93% rename from test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV2MutualAuth_CITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV2MutualAuthCoreITCase.java index e2ee99e97..02ffef48d 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV2MutualAuth_CITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV2MutualAuthCoreITCase.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package com.alibaba.nacos.test.client; import com.alibaba.nacos.Nacos; @@ -48,12 +47,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * * @author githubcheng2978 */ -@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", RpcConstants.NACOS_SERVER_RPC + ".mutualAuthEnable=true", +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") +@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", + RpcConstants.NACOS_SERVER_RPC + ".mutualAuthEnable=true", RpcConstants.NACOS_SERVER_RPC + ".compatibility=false", RpcConstants.NACOS_SERVER_RPC + ".enableTls=true", RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem", RpcConstants.NACOS_SERVER_RPC + ".certPrivateKey=test-server-key.pem", RpcConstants.NACOS_SERVER_RPC + ".trustCollectionCertFile=test-ca-cert.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class ConfigIntegrationV2MutualAuth_CITCase { +public class ConfigIntegrationV2MutualAuthCoreITCase { public static AtomicInteger increment = new AtomicInteger(100); @@ -62,7 +63,7 @@ public class ConfigIntegrationV2MutualAuth_CITCase { @BeforeAll static void beforeClass() throws IOException { - ConfigCleanUtils.changeToNewTestNacosHome(ConfigIntegrationV2MutualAuth_CITCase.class.getSimpleName()); + ConfigCleanUtils.changeToNewTestNacosHome(ConfigIntegrationV2MutualAuthCoreITCase.class.getSimpleName()); } @@ -73,7 +74,7 @@ public class ConfigIntegrationV2MutualAuth_CITCase { @Test @Disabled("TODO, fix the cert expired problem") - void test_d_MutualAuth() throws Exception { + void testMutualAuth() throws Exception { RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig(); tlsConfig.setEnableTls(true); @@ -103,7 +104,7 @@ public class ConfigIntegrationV2MutualAuth_CITCase { } @Test - void test_e_ServerMutualAuthOnly() throws Exception { + void testServerMutualAuthOnly() throws Exception { RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig(); tlsConfig.setEnableTls(true); diff --git a/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV3_CITCase.java b/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV3CoreITCase.java similarity index 90% rename from test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV3_CITCase.java rename to test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV3CoreITCase.java index d950da906..1461a3501 100644 --- a/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV3_CITCase.java +++ b/test/core-test/src/test/java/com/alibaba/nacos/test/client/ConfigIntegrationV3CoreITCase.java @@ -14,7 +14,6 @@ * limitations under the License. */ - package com.alibaba.nacos.test.client; import com.alibaba.nacos.Nacos; @@ -44,16 +43,18 @@ import java.util.concurrent.atomic.AtomicInteger; import static org.junit.jupiter.api.Assertions.assertTrue; /** - * use configPublishRequest for communication verification between client and server + * Use configPublishRequest for communication verification between client and server. * * @author githubcheng2978 */ //todo fix this test case //ConfigIntegrationV3_CITCase and ConfigIntegrationV2MutualAuth_CITCase will fail when run together -@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", RpcConstants.NACOS_SERVER_RPC + ".enableTls=true", - RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem", - RpcConstants.NACOS_SERVER_RPC + ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class ConfigIntegrationV3_CITCase { +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") +@SpringBootTest(classes = {Nacos.class}, properties = {"nacos.standalone=true", + RpcConstants.NACOS_SERVER_RPC + ".enableTls=true", + RpcConstants.NACOS_SERVER_RPC + ".certChainFile=test-server-cert.pem", RpcConstants.NACOS_SERVER_RPC + + ".certPrivateKey=test-server-key.pem"}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class ConfigIntegrationV3CoreITCase { public static AtomicInteger increment = new AtomicInteger(100); @@ -62,7 +63,7 @@ public class ConfigIntegrationV3_CITCase { @BeforeAll static void beforeClass() throws IOException { - ConfigCleanUtils.changeToNewTestNacosHome(ConfigIntegrationV3_CITCase.class.getSimpleName()); + ConfigCleanUtils.changeToNewTestNacosHome(ConfigIntegrationV3CoreITCase.class.getSimpleName()); } @BeforeAll @@ -72,7 +73,7 @@ public class ConfigIntegrationV3_CITCase { } @Test - void test_e_TlsServerAndPlainClient() throws Exception { + void testTlsServerAndPlainClient() throws Exception { RpcClient client = RpcClientFactory.createClient("testTlsServerAndPlainClient", ConnectionType.GRPC, Collections.singletonMap("labelKey", "labelValue"), null); RpcClient.ServerInfo serverInfo = new RpcClient.ServerInfo(); @@ -93,7 +94,7 @@ public class ConfigIntegrationV3_CITCase { } @Test - void test_f_ServerTlsTrustAll() throws Exception { + void testServerTlsTrustAll() throws Exception { RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig(); tlsConfig.setEnableTls(true); tlsConfig.setTrustAll(true); @@ -116,7 +117,7 @@ public class ConfigIntegrationV3_CITCase { @Disabled("TODO, Fix cert expired problem") @Test - void test_g_ServerTlsTrustCa() throws Exception { + void testServerTlsTrustCa() throws Exception { RpcClient.ServerInfo serverInfo = new RpcClient.ServerInfo(); serverInfo.setServerIp("127.0.0.1");