Skip to content

Commit

Permalink
use TestSocketUtils.findAvailableTcpPort
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLiu1123 committed Dec 1, 2024
1 parent 7161c96 commit b1b5184
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 68 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand All @@ -19,7 +19,7 @@ class BaseUrlTests {

@Test
void testDefaultBaseUrl() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(BaseUrlController.class)
.properties("server.port=" + port)
.properties(HttpExchangeProperties.PREFIX + ".base-url=localhost:" + port)
Expand All @@ -32,7 +32,7 @@ void testDefaultBaseUrl() {

@Test
void testNoBaseUrl() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(BaseUrlController.class)
.properties("server.port=" + port)
.run()) {
Expand All @@ -46,7 +46,7 @@ void testNoBaseUrl() {

@Test
void testBaseUrl_whenClientHasBaseUrl_thenOverrideDefaultBaseUrl() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(BaseUrlController.class)
.properties("server.port=" + port)
.properties(HttpExchangeProperties.PREFIX + ".base-url=localhost:" + port)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import java.net.URI;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -32,7 +32,7 @@ class BeanParamArgumentResolverTests {

@Test
void convertObjectPropertiesToRequestParameters() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(FooController.class)
.properties("server.port=" + port)
.properties(HttpExchangeProperties.PREFIX + ".base-url=http://localhost:" + port)
Expand Down Expand Up @@ -81,7 +81,7 @@ void convertObjectPropertiesToRequestParameters() {

@Test
void convertObjectPropertiesToRequestParameters_whenBeanToQueryDisabled() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(FooController.class)
.properties("server.port=" + port)
.properties(HttpExchangeProperties.PREFIX + ".base-url=http://localhost:" + port)
Expand Down Expand Up @@ -130,7 +130,7 @@ void convertObjectPropertiesToRequestParameters_whenBeanToQueryDisabled() {

@Test
void hasQueryMapArgumentResolverBean_whenDefaultConfig() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(FooController.class)
.web(WebApplicationType.NONE)
.properties("server.port=" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand All @@ -19,7 +19,7 @@ class ClassesConfigTests {

@Test
void clientClassConfig() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(FooController.class)
.profiles("ClassesConfigTests")
.properties("server.port=" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.danielliu1123.httpexchange;

import static io.github.danielliu1123.PortGetter.availablePort;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand All @@ -20,7 +20,7 @@ class ClientTypeTests {
@ParameterizedTest
@ValueSource(strings = {"rest_client", "web_client", "rest_template"})
void testRestClient(String clientType) {
int port = availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
.properties("http-exchange.client-type=" + clientType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.WebApplicationType;
Expand All @@ -28,7 +28,7 @@ class ClientsConfigTests {
"com.**",
})
void notThrow_whenClientMatchesCanonicalClassName(String client) {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.web(WebApplicationType.NONE)
.properties("server.port=" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static io.github.danielliu1123.PortGetter.availablePort;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.httpexchange.shaded.requestfactory.EnhancedJdkClientHttpRequestFactory;
import jakarta.validation.ConstraintViolationException;
Expand Down Expand Up @@ -36,7 +36,7 @@ void reset() {
@ParameterizedTest
@ValueSource(strings = {"REST_CLIENT", "REST_TEMPLATE"})
void testDynamicRefresh(String clientType) {
int port = availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
.properties("http-exchange.base-url=http://localhost:" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand All @@ -20,7 +20,7 @@ class ExtendTests {

@Test
void userApiFirst_whenHaveControllerAndApiBeans() {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(FooController.class)
.profiles("ControllerApiTests")
.properties("server.port=" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
Expand All @@ -25,7 +25,7 @@ class HttpClientCustomizerIT {
@ParameterizedTest
@ValueSource(strings = {"REST_CLIENT", "REST_TEMPLATE", "WEB_CLIENT"})
void testRestClient(String clientType, CapturedOutput output) {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(RestClientCfg.class)
.web(WebApplicationType.SERVLET)
.properties("server.port=" + port)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand All @@ -22,7 +22,7 @@ class RegisterBeanManuallyTests {

@Test
void useAutoRegisteredBean_whenNoManualRegisteredBean() {
var port = PortGetter.availablePort();
var port = findAvailableTcpPort();

try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
Expand All @@ -39,7 +39,7 @@ void useAutoRegisteredBean_whenNoManualRegisteredBean() {

@Test
void useManualRegisteredBean_whenManualRegisteredBeanExists() {
var port = PortGetter.availablePort();
var port = findAvailableTcpPort();

try (var ctx = new SpringApplicationBuilder(Cfg.class, ApiCfg.class)
.properties("server.port=" + port)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import static java.util.concurrent.CompletableFuture.runAsync;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import io.github.danielliu1123.httpexchange.shaded.requestfactory.EnhancedJdkClientHttpRequestFactory;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -35,7 +35,7 @@ class RequestConfiguratorTests {
@ParameterizedTest
@ValueSource(strings = {"REST_CLIENT", "REST_TEMPLATE"})
void testRequestConfigurator(String clientType) {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
.properties(PREFIX + ".read-timeout=100")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.danielliu1123.httpexchange;

import static io.github.danielliu1123.PortGetter.availablePort;
import static io.github.danielliu1123.httpexchange.HttpExchangeClientHttpRequestInterceptor.REQUEST_TIMEOUT_HEADER;
import static io.github.danielliu1123.httpexchange.HttpExchangeProperties.PREFIX;
import static java.util.concurrent.CompletableFuture.runAsync;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.httpexchange.shaded.requestfactory.EnhancedJdkClientHttpRequestFactory;
import java.util.List;
Expand Down Expand Up @@ -35,7 +35,7 @@ class RequesterTests {
@ParameterizedTest
@ValueSource(strings = {"REST_CLIENT", "REST_TEMPLATE"})
void testRequester(String clientType) {
int port = availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
.properties(PREFIX + ".read-timeout=100")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
Expand All @@ -26,7 +26,7 @@ class RestClientConfigurationTests {

@Test
void testRestClientCustomizer(CapturedOutput output) {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Controller.class)
.properties("server.port=" + port)
.properties(HttpExchangeProperties.PREFIX + ".base-url=localhost:" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import io.github.danielliu1123.PortGetter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger;
Expand All @@ -27,7 +27,7 @@ class RestClientCustomizerIT {

@Test
void testAddInterceptor(CapturedOutput output) {
int port = PortGetter.availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
.properties(HttpExchangeProperties.PREFIX + ".base-url=localhost:" + port)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.danielliu1123.httpexchange;

import static io.github.danielliu1123.PortGetter.availablePort;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.springframework.test.util.TestSocketUtils.findAvailableTcpPort;

import java.util.List;
import java.util.Map;
Expand All @@ -27,7 +27,7 @@ class ReturnTypeTests {

@Test
void testReturnType() {
int port = availablePort();
int port = findAvailableTcpPort();
try (var ctx = new SpringApplicationBuilder(Cfg.class)
.properties("server.port=" + port)
.properties("http-exchange.base-url=localhost:" + port)
Expand Down
Loading

0 comments on commit b1b5184

Please sign in to comment.