Skip to content

Commit

Permalink
[IT]Adjust config module base and auth ITs for Checkstyle compliance. (
Browse files Browse the repository at this point in the history
…#12376)

* [IT]Adjust core module auth integration tests to meet checkstyle requirements.

* [IT]Adjust config module base integration tests to meet checkstyle requirements.
  • Loading branch information
stone-98 authored Jul 24, 2024
1 parent c00d863 commit 631babe
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public class BaseClusterTest extends HttpClient4Test {

protected static final String CONFIG_INFO_ID = "config-info-id";

protected static final AtomicBoolean[] FINISHED = new AtomicBoolean[] {new AtomicBoolean(false), new AtomicBoolean(false),
new AtomicBoolean(false)};
protected static final AtomicBoolean[] FINISHED = new AtomicBoolean[] {new AtomicBoolean(false),
new AtomicBoolean(false), new AtomicBoolean(false)};

private static final Logger LOGGER = LoggerFactory.getLogger(BaseClusterTest.class);

Expand Down Expand Up @@ -180,14 +180,15 @@ private static void run(final int index, final CountDownLatch latch, final Class
Map<String, Object> properties = new HashMap<>();
properties.put("server.port", "884" + (7 + index));
properties.put("nacos.home", path);
properties.put("nacos.logs.path", Paths.get(System.getProperty("user.home"), "nacos-" + index, "/logs/").toString());
properties.put("nacos.logs.path",
Paths.get(System.getProperty("user.home"), "nacos-" + index, "/logs/").toString());
properties.put("spring.jmx.enabled", false);
properties.put("nacos.core.snowflake.worker-id", index + 1);
MapPropertySource propertySource = new MapPropertySource("nacos_cluster_test", properties);
ConfigurableEnvironment environment = new StandardServletEnvironment();
environment.getPropertySources().addFirst(propertySource);
SpringApplication cluster = new SpringApplicationBuilder(cls).web(WebApplicationType.SERVLET).environment(environment)
.properties(clusterInfo).properties("embeddedStorage=true").build();
SpringApplication cluster = new SpringApplicationBuilder(cls).web(WebApplicationType.SERVLET)
.environment(environment).properties(clusterInfo).properties("embeddedStorage=true").build();

ConfigurableApplicationContext context = cluster.run();

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,24 +20,48 @@
import org.springframework.util.MultiValueMap;

/**
* @author nkorange
* Helper class for building HTTP request parameters using Spring's MultiValueMap. Provides methods to construct and
* append parameters.
*/
public class Params {

private MultiValueMap<String, String> paramMap;

/**
* Private constructor to enforce usage of static factory method `newParams()`.
*/
private Params() {
this.paramMap = new LinkedMultiValueMap<>();
}

/**
* Static factory method to create a new instance of Params.
*
* @return A new Params instance.
*/
public static Params newParams() {
Params params = new Params();
params.paramMap = new LinkedMultiValueMap<String, String>();
return params;
return new Params();
}

/**
* Appends a parameter with the specified name and value to the parameter map.
*
* @param name The parameter name.
* @param value The parameter value.
* @return This Params instance for method chaining.
*/
public Params appendParam(String name, String value) {
this.paramMap.add(name, value);
return this;
}

/**
* Retrieves the constructed parameter map.
*
* @return The MultiValueMap containing the appended parameters.
*/
public MultiValueMap<String, String> done() {
return paramMap;
}
}

0 comments on commit 631babe

Please sign in to comment.