Skip to content

Commit

Permalink
Adjust integration tests for ability, base, and client modules in the…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
stone-98 authored Jul 15, 2024
1 parent 2233e65 commit de5ade7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected Map<AbilityMode, Map<AbilityKey, Boolean>> initCurrentNodeAbilities()
Map<AbilityKey, Boolean> map = new HashMap<>();
map.put(AbilityKey.SERVER_TEST_1, true);
map.put(AbilityKey.SERVER_TEST_2, false);
HashMap res = new HashMap<>();
HashMap<AbilityMode, Map<AbilityKey, Boolean>> res = new HashMap<>();
res.put(AbilityMode.SERVER, map);

Map<AbilityKey, Boolean> map1 = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.net.URL;

/**
* Http client for test module
* Http client for test module.
*
* @author nkorange
* @since 1.2.0
Expand All @@ -46,18 +46,21 @@ protected <T> ResponseEntity<T> request(String path, MultiValueMap<String, Strin

HttpEntity<?> entity = new HttpEntity<T>(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 <T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz, HttpMethod httpMethod) {
protected <T> ResponseEntity<T> request(String path, MultiValueMap<String, String> params, Class<T> clazz,
HttpMethod httpMethod) {

HttpHeaders headers = new HttpHeaders();

HttpEntity<?> entity = new HttpEntity<T>(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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,42 @@
import org.springframework.util.MultiValueMap;

/**
* Utility class for building HTTP request parameters.
*
* @author nkorange
*/
public class Params {

private MultiValueMap<String, String> paramMap;

/**
* Creates a new Params instance.
*
* @return A new Params instance.
*/
public static Params newParams() {
Params params = new Params();
params.paramMap = new LinkedMultiValueMap<String, String>();
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<String, String> done() {
return paramMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@
*
* @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);

Expand All @@ -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
Expand All @@ -73,7 +75,7 @@ static void cleanClientCache() throws Exception {
}

@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();
Expand All @@ -85,7 +87,7 @@ void test_a_TlsServer() throws Exception {
}

@Test
void test_b_ServerTlsTrustAll() throws Exception {
void testServerTlsTrustAll() throws Exception {
RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig();
tlsConfig.setEnableTls(true);
tlsConfig.setTrustAll(true);
Expand All @@ -108,7 +110,7 @@ void test_b_ServerTlsTrustAll() throws Exception {
}

@Test
void test_c_ServerTlsTrustCa() throws Exception {
void testServerTlsTrustCa() throws Exception {

RpcClient.ServerInfo serverInfo = new RpcClient.ServerInfo();
serverInfo.setServerIp("127.0.0.1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/


package com.alibaba.nacos.test.client;

import com.alibaba.nacos.Nacos;
Expand Down Expand Up @@ -48,12 +47,14 @@
*
* @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);

Expand All @@ -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());

}

Expand All @@ -73,7 +74,7 @@ void cleanClientCache() throws Exception {

@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);
Expand Down Expand Up @@ -103,7 +104,7 @@ void test_d_MutualAuth() throws Exception {
}

@Test
void test_e_ServerMutualAuthOnly() throws Exception {
void testServerMutualAuthOnly() throws Exception {

RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig();
tlsConfig.setEnableTls(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/


package com.alibaba.nacos.test.client;

import com.alibaba.nacos.Nacos;
Expand Down Expand Up @@ -44,16 +43,18 @@
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);

Expand All @@ -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
Expand All @@ -72,7 +73,7 @@ static void cleanClientCache() throws Exception {
}

@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();
Expand All @@ -93,7 +94,7 @@ void test_e_TlsServerAndPlainClient() throws Exception {
}

@Test
void test_f_ServerTlsTrustAll() throws Exception {
void testServerTlsTrustAll() throws Exception {
RpcClientTlsConfig tlsConfig = new RpcClientTlsConfig();
tlsConfig.setEnableTls(true);
tlsConfig.setTrustAll(true);
Expand All @@ -116,7 +117,7 @@ void test_f_ServerTlsTrustAll() throws Exception {

@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");
Expand Down

0 comments on commit de5ade7

Please sign in to comment.