From 42d21a8336d34caf30d144bc1176e6719d00ce80 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 19 Oct 2021 16:07:33 -0700 Subject: [PATCH] Remove parameterization of session smoke tests There are dedicated smoke tests for Hazelcast, MongoDB and Redis that run on CI. This commit also polishes some of the other smoke tests related to Spring Session --- ...ampleSessionHazelcastApplicationTests.java | 27 +++-- .../build.gradle | 17 +++ .../session/HelloRestController.java | 0 .../SampleSessionJdbcApplication.java} | 4 +- .../src/main/resources/application.properties | 0 .../SampleSessionJdbcApplicationTests.java | 105 ++++++++++++++++++ .../SampleSessionMongoApplicationTests.java | 23 ++-- .../SampleSessionRedisApplicationTests.java | 23 ++-- .../build.gradle | 36 ------ .../src/main/resources/hazelcast.xml | 20 ---- .../SampleSessionApplicationTests.java | 84 -------------- 11 files changed, 161 insertions(+), 178 deletions(-) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/build.gradle rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session => spring-boot-smoke-test-session-jdbc}/src/main/java/smoketest/session/HelloRestController.java (100%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java => spring-boot-smoke-test-session-jdbc/src/main/java/smoketest/session/SampleSessionJdbcApplication.java} (88%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session => spring-boot-smoke-test-session-jdbc}/src/main/resources/application.properties (100%) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/test/java/smoketest/session/SampleSessionJdbcApplicationTests.java delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-hazelcast/src/test/java/smoketest/session/hazelcast/SampleSessionHazelcastApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-hazelcast/src/test/java/smoketest/session/hazelcast/SampleSessionHazelcastApplicationTests.java index 33e7dd68e4..a48093d441 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-hazelcast/src/test/java/smoketest/session/hazelcast/SampleSessionHazelcastApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-hazelcast/src/test/java/smoketest/session/hazelcast/SampleSessionHazelcastApplicationTests.java @@ -26,7 +26,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -36,7 +35,7 @@ import org.springframework.http.ResponseEntity; import static org.assertj.core.api.Assertions.assertThat; /** - * Tests for {@link SampleSessionHazelcastApplication}, + * Tests for {@link SampleSessionHazelcastApplication}. * * @author Susmitha Kandula * @author Madhura Bhave @@ -47,28 +46,24 @@ class SampleSessionHazelcastApplicationTests { @Autowired private TestRestTemplate restTemplate; - @LocalServerPort - private int port; - @Test @SuppressWarnings("unchecked") void sessionsEndpointShouldReturnUserSession() { - URI uri = URI.create("http://localhost:" + this.port + "/"); - ResponseEntity firstResponse = performRequest(this.restTemplate, uri, null); + URI uri = URI.create("/"); + ResponseEntity firstResponse = performRequest(uri, null); String cookie = firstResponse.getHeaders().getFirst("Set-Cookie"); - performRequest(this.restTemplate, uri, cookie).getBody(); - ResponseEntity> entity = (ResponseEntity>) (ResponseEntity) this.restTemplate - .withBasicAuth("user", "password").getForEntity("/actuator/sessions?username=user", Map.class); + performRequest(uri, cookie).getBody(); + ResponseEntity> entity = getSessions(); assertThat(entity).isNotNull(); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); List> sessions = (List>) entity.getBody().get("sessions"); assertThat(sessions.size()).isEqualTo(1); } - private ResponseEntity performRequest(TestRestTemplate restTemplate, URI uri, String cookie) { + private ResponseEntity performRequest(URI uri, String cookie) { HttpHeaders headers = getHeaders(cookie); RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); - return restTemplate.exchange(request, String.class); + return this.restTemplate.exchange(request, String.class); } private HttpHeaders getHeaders(String cookie) { @@ -86,4 +81,12 @@ class SampleSessionHazelcastApplicationTests { return "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes()); } + @SuppressWarnings("unchecked") + private ResponseEntity> getSessions() { + HttpHeaders headers = getHeaders(null); + RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, + URI.create("/actuator/sessions?username=user")); + return (ResponseEntity>) (ResponseEntity) this.restTemplate.exchange(request, Map.class); + } + } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/build.gradle new file mode 100644 index 0000000000..9026d1ec12 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/build.gradle @@ -0,0 +1,17 @@ +plugins { + id "java" + id "org.springframework.boot.conventions" +} + +description = "Spring Boot Session JDBC smoke test" + +dependencies { + implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator")) + implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-security")) + implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) + runtimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jdbc")) + runtimeOnly("org.springframework.session:spring-session-jdbc") + runtimeOnly("com.h2database:h2") + + testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/HelloRestController.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/java/smoketest/session/HelloRestController.java similarity index 100% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/HelloRestController.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/java/smoketest/session/HelloRestController.java diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/java/smoketest/session/SampleSessionJdbcApplication.java similarity index 88% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/java/smoketest/session/SampleSessionJdbcApplication.java index 7a9f9bf9eb..14bce7a2e3 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/java/smoketest/session/SampleSessionApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/java/smoketest/session/SampleSessionJdbcApplication.java @@ -20,10 +20,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class SampleSessionApplication { +public class SampleSessionJdbcApplication { public static void main(String[] args) { - SpringApplication.run(SampleSessionApplication.class); + SpringApplication.run(SampleSessionJdbcApplication.class); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/resources/application.properties similarity index 100% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/application.properties rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/main/resources/application.properties diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/test/java/smoketest/session/SampleSessionJdbcApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/test/java/smoketest/session/SampleSessionJdbcApplicationTests.java new file mode 100644 index 0000000000..035bc52836 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-jdbc/src/test/java/smoketest/session/SampleSessionJdbcApplicationTests.java @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package smoketest.session; + +import java.net.URI; +import java.util.Base64; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleSessionJdbcApplication}. + * + * @author Andy Wilkinson + * @author Vedran Pavic + * @author Madhura Bhave + */ +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + properties = "server.servlet.session.timeout:2") +class SampleSessionJdbcApplicationTests { + + @Autowired + private TestRestTemplate restTemplate; + + private static final URI ROOT_URI = URI.create("/"); + + @Test + void sessionExpiry() throws Exception { + ResponseEntity firstResponse = performRequest(ROOT_URI, null); + String sessionId1 = firstResponse.getBody(); + String cookie = firstResponse.getHeaders().getFirst("Set-Cookie"); + String sessionId2 = performRequest(ROOT_URI, cookie).getBody(); + assertThat(sessionId1).isEqualTo(sessionId2); + Thread.sleep(2100); + String loginPage = performRequest(ROOT_URI, cookie).getBody(); + assertThat(loginPage).containsIgnoringCase("login"); + } + + @Test + @SuppressWarnings("unchecked") + void sessionsEndpointShouldReturnUserSession() { + performRequest(ROOT_URI, null); + ResponseEntity> response = getSessions(); + assertThat(response).isNotNull(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + List> sessions = (List>) response.getBody().get("sessions"); + assertThat(sessions.size()).isEqualTo(1); + } + + private ResponseEntity performRequest(URI uri, String cookie) { + HttpHeaders headers = getHeaders(cookie); + RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); + return this.restTemplate.exchange(request, String.class); + } + + private HttpHeaders getHeaders(String cookie) { + HttpHeaders headers = new HttpHeaders(); + if (cookie != null) { + headers.set("Cookie", cookie); + } + else { + headers.set("Authorization", getBasicAuth()); + } + return headers; + } + + private String getBasicAuth() { + return "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes()); + } + + @SuppressWarnings("unchecked") + private ResponseEntity> getSessions() { + HttpHeaders headers = getHeaders(null); + RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, + URI.create("/actuator/sessions?username=user")); + return (ResponseEntity>) (ResponseEntity) this.restTemplate.exchange(request, Map.class); + } + +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java index c6340a1a33..a99500bd5b 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java @@ -49,10 +49,6 @@ import static org.assertj.core.api.Assertions.assertThat; @Testcontainers(disabledWithoutDocker = true) public class SampleSessionMongoApplicationTests { - private static final String USERNAME = "user"; - - private static final String PASSWORD = "password"; - @Autowired private TestRestTemplate restTemplate; @@ -68,7 +64,7 @@ public class SampleSessionMongoApplicationTests { @Test @SuppressWarnings("unchecked") void sessionsEndpointShouldReturnUserSessions() { - createSession(); + createSession(URI.create("/")); ResponseEntity> response = getSessions(); assertThat(response).isNotNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -76,18 +72,21 @@ public class SampleSessionMongoApplicationTests { assertThat(sessions.size()).isEqualTo(1); } - private void createSession() { - URI uri = URI.create("/"); - HttpHeaders headers = new HttpHeaders(); - headers.setBasicAuth(USERNAME, PASSWORD); - RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); + private void createSession(URI uri) { + RequestEntity request = getRequestEntity(uri); this.restTemplate.exchange(request, String.class); } + private RequestEntity getRequestEntity(URI uri) { + HttpHeaders headers = new HttpHeaders(); + headers.setBasicAuth("user", "password"); + return new RequestEntity<>(headers, HttpMethod.GET, uri); + } + @SuppressWarnings("unchecked") private ResponseEntity> getSessions() { - return (ResponseEntity>) (ResponseEntity) this.restTemplate - .withBasicAuth(USERNAME, PASSWORD).getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); + RequestEntity request = getRequestEntity(URI.create("/actuator/sessions?username=user")); + return (ResponseEntity>) (ResponseEntity) this.restTemplate.exchange(request, Map.class); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java index 8ea78be57d..8863197968 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java @@ -47,10 +47,6 @@ import static org.assertj.core.api.Assertions.assertThat; @Testcontainers(disabledWithoutDocker = true) public class SampleSessionRedisApplicationTests { - private static final String USERNAME = "user"; - - private static final String PASSWORD = "password"; - @Container static RedisContainer redis = new RedisContainer(); @@ -66,7 +62,7 @@ public class SampleSessionRedisApplicationTests { @Test @SuppressWarnings("unchecked") void sessionsEndpointShouldReturnUserSessions() { - createSession(); + createSession(URI.create("/")); ResponseEntity> response = this.getSessions(); assertThat(response).isNotNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); @@ -74,18 +70,21 @@ public class SampleSessionRedisApplicationTests { assertThat(sessions.size()).isEqualTo(1); } - private void createSession() { - URI uri = URI.create("/"); - HttpHeaders headers = new HttpHeaders(); - headers.setBasicAuth(USERNAME, PASSWORD); - RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); + private void createSession(URI uri) { + RequestEntity request = getRequestEntity(uri); this.restTemplate.exchange(request, String.class); } + private RequestEntity getRequestEntity(URI uri) { + HttpHeaders headers = new HttpHeaders(); + headers.setBasicAuth("user", "password"); + return new RequestEntity<>(headers, HttpMethod.GET, uri); + } + @SuppressWarnings("unchecked") private ResponseEntity> getSessions() { - return (ResponseEntity>) (ResponseEntity) this.restTemplate - .withBasicAuth(USERNAME, PASSWORD).getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); + RequestEntity request = getRequestEntity(URI.create("/actuator/sessions?username=user")); + return (ResponseEntity>) (ResponseEntity) this.restTemplate.exchange(request, Map.class); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle deleted file mode 100644 index bd0ef38690..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id "java" - id "org.springframework.boot.conventions" -} - -description = "Spring Boot Session smoke test" - -def sessionStores = [ - "hazelcast": [ - "com.hazelcast:hazelcast", - "org.springframework.session:spring-session-hazelcast" - ], - "jdbc": [ - project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jdbc"), - "org.springframework.session:spring-session-jdbc" , - "com.h2database:h2" - ], - "mongodb": [ - project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-mongodb"), - "org.springframework.session:spring-session-data-mongodb" - ], - "redis": [ - project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-redis"), - "org.springframework.session:spring-session-data-redis" - ] -] - -dependencies { - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator")) - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-security")) - implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) - - sessionStores[project.findProperty("sessionStore") ?: "jdbc"].each { runtimeOnly it } - - testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) -} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml deleted file mode 100644 index 9a988bf978..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/main/resources/hazelcast.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - principalName - - - principalName - - - - - - - - - - diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java deleted file mode 100644 index 5d803a8060..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session/src/test/java/smoketest/session/SampleSessionApplicationTests.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package smoketest.session; - -import java.net.URI; -import java.util.Base64; - -import org.junit.jupiter.api.Test; - -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SampleSessionApplication}. - * - * @author Andy Wilkinson - * @author Vedran Pavic - */ -class SampleSessionApplicationTests { - - @Test - void sessionExpiry() throws Exception { - ConfigurableApplicationContext context = createContext(); - String port = context.getEnvironment().getProperty("local.server.port"); - URI uri = URI.create("http://localhost:" + port + "/"); - RestTemplate restTemplate = new RestTemplate(); - ResponseEntity firstResponse = firstRequest(restTemplate, uri); - String sessionId1 = firstResponse.getBody(); - String cookie = firstResponse.getHeaders().getFirst("Set-Cookie"); - String sessionId2 = nextRequest(restTemplate, uri, cookie).getBody(); - assertThat(sessionId1).isEqualTo(sessionId2); - Thread.sleep(2100); - String loginPage = nextRequest(restTemplate, uri, cookie).getBody(); - assertThat(loginPage).containsIgnoringCase("login"); - } - - private ConfigurableApplicationContext createContext() { - ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(SampleSessionApplication.class) - .properties("server.port:0", "server.servlet.session.timeout:2") - .initializers(new ServerPortInfoApplicationContextInitializer()).run(); - return context; - } - - private ResponseEntity firstRequest(RestTemplate restTemplate, URI uri) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", getBasicAuth()); - RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); - return restTemplate.exchange(request, String.class); - } - - private ResponseEntity nextRequest(RestTemplate restTemplate, URI uri, String cookie) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Cookie", cookie); - RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); - return restTemplate.exchange(request, String.class); - } - - private String getBasicAuth() { - return "Basic " + Base64.getEncoder().encodeToString("user:password".getBytes()); - } - -}