From 9a16c246ecbb5af252b1975f41914cc8629a6a9b Mon Sep 17 00:00:00 2001 From: "Angel L. Villalain Garcia" Date: Wed, 13 Oct 2021 23:58:52 -0500 Subject: [PATCH 1/2] Add smoke tests for Spring Session Redis/Mongo Add smoke tests that verify the correct behavior of the sessions endpoint when using Spring Session with MongoDB and Redis. See gh-28362 --- .../build.gradle | 19 ++++ .../SampleHttpSessionMongoApplication.java | 31 +++++++ .../src/main/resources/application.properties | 2 + ...ampleHttpSessionMongoApplicationTests.java | 90 +++++++++++++++++++ .../build.gradle | 18 ++++ .../SampleHttpSessionRedisApplication.java | 31 +++++++ .../src/main/resources/application.properties | 1 + ...ampleHttpSessionRedisApplicationTests.java | 88 ++++++++++++++++++ 8 files changed, 280 insertions(+) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle new file mode 100644 index 0000000000..2e14a54ddc --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle @@ -0,0 +1,19 @@ +plugins { + id "java" + id "org.springframework.boot.conventions" +} + +description = "Spring Boot Http Session Mongodb 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-data-mongodb")) + implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) + implementation("org.springframework.session:spring-session-data-mongodb") + testImplementation("org.testcontainers:mongodb") + testImplementation("org.testcontainers:testcontainers") + testImplementation("org.testcontainers:junit-jupiter") + testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) + 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-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java new file mode 100644 index 0000000000..2d98a3a579 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2019 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.mongodb; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.session.data.mongo.config.annotation.web.http.EnableMongoHttpSession; + +@SpringBootApplication +@EnableMongoHttpSession +public class SampleHttpSessionMongoApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleHttpSessionMongoApplication.class); + } + +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties new file mode 100644 index 0000000000..ca5b9bafe2 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties @@ -0,0 +1,2 @@ +management.endpoints.web.exposure.include=* +spring.mongodb.embedded.version=3.6.5 \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java new file mode 100644 index 0000000000..aab4385d6f --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2019 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.mongodb; + +import java.net.URI; +import java.time.Duration; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +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.testsupport.testcontainers.DockerImageNames; +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 org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Testcontainers(disabledWithoutDocker = true) +public class SampleHttpSessionMongoApplicationTests { + + static final String USERNAME = "user"; + static final String PASSWORD = "password"; + static final String ROOT = "/"; + + @Container + static MongoDBContainer mongo = new MongoDBContainer(DockerImageNames.mongo()).withStartupAttempts(3) + .withStartupTimeout(Duration.ofMinutes(2)); + + @Autowired + private TestRestTemplate template; + + @DynamicPropertySource + static void applicationProperties(DynamicPropertyRegistry registry) { + registry.add("spring.security.user.name", () -> USERNAME); + registry.add("spring.security.user.password", () -> PASSWORD); + registry.add("spring.data.mongodb.uri", mongo::getReplicaSetUrl); + } + + @Test + @SuppressWarnings("unchecked") + void sessionsEndpointShouldReturnUserSessions() { + createSession(); + ResponseEntity> response = this.getSessions(); + assertThat(response).isNotNull(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + List> sessions = (List>) response.getBody().get("sessions"); + assertThat(sessions.size()).isEqualTo(1); + } + + private void createSession() { + URI uri = URI.create(ROOT); + HttpHeaders headers = new HttpHeaders(); + headers.setBasicAuth(USERNAME, PASSWORD); + RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); + this.template.exchange(request, String.class); + } + + @SuppressWarnings("unchecked") + private ResponseEntity> getSessions() { + return (ResponseEntity>) (ResponseEntity) this.template.withBasicAuth(USERNAME, PASSWORD) + .getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); + } + +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle new file mode 100644 index 0000000000..715c15c489 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle @@ -0,0 +1,18 @@ +plugins { + id "java" + id "org.springframework.boot.conventions" +} + +description = "Spring Boot Http Session Mongodb 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-data-redis")) + implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) + implementation("org.springframework.session:spring-session-data-redis") + testImplementation("org.testcontainers:testcontainers") + testImplementation("org.testcontainers:junit-jupiter") + testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) + 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-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java new file mode 100644 index 0000000000..a3f4aa080c --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2019 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.redis; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; + +@SpringBootApplication +@EnableRedisHttpSession +public class SampleHttpSessionRedisApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleHttpSessionRedisApplication.class); + } + +} diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties new file mode 100644 index 0000000000..705d36ce69 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties @@ -0,0 +1 @@ +management.endpoints.web.exposure.include=* \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java new file mode 100644 index 0000000000..dcc36c7e1d --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java @@ -0,0 +1,88 @@ +/* + * Copyright 2012-2019 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.redis; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +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.testsupport.testcontainers.RedisContainer; +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 org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Testcontainers(disabledWithoutDocker = true) +public class SampleHttpSessionRedisApplicationTests { + + static final String USERNAME = "user"; + static final String PASSWORD = "password"; + static final String ROOT = "/"; + + @Container + static RedisContainer redis = new RedisContainer(); + + @Autowired + private TestRestTemplate template; + + @DynamicPropertySource + static void applicationProperties(DynamicPropertyRegistry registry) { + registry.add("spring.security.user.name", () -> USERNAME); + registry.add("spring.security.user.password", () -> PASSWORD); + registry.add("spring.redis.host", redis::getHost); + registry.add("spring.redis.port", redis::getFirstMappedPort); + } + + @Test + @SuppressWarnings("unchecked") + void sessionsEndpointShouldReturnUserSessions() { + createSession(); + ResponseEntity> response = this.getSessions(); + assertThat(response).isNotNull(); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + List> sessions = (List>) response.getBody().get("sessions"); + assertThat(sessions.size()).isEqualTo(1); + } + + private void createSession() { + URI uri = URI.create(ROOT); + HttpHeaders headers = new HttpHeaders(); + headers.setBasicAuth(USERNAME, PASSWORD); + RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); + this.template.exchange(request, String.class); + } + + @SuppressWarnings("unchecked") + private ResponseEntity> getSessions() { + return (ResponseEntity>) (ResponseEntity) this.template.withBasicAuth(USERNAME, PASSWORD) + .getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); + } + +} From 2caa6cb227bea18be90aadf940b49768202d4bc3 Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 19 Oct 2021 15:53:22 -0700 Subject: [PATCH 2/2] Polish "Add smoke tests for Spring Session Redis/Mongo" See gh-28362 --- .../src/main/resources/application.properties | 2 -- .../src/main/resources/application.properties | 1 - .../build.gradle | 2 +- .../SampleSessionMongoApplication.java} | 6 ++-- .../src/main/resources/application.properties | 3 ++ .../SampleSessionMongoApplicationTests.java} | 33 ++++++++++--------- .../build.gradle | 2 +- .../redis/SampleSessionRedisApplication.java} | 6 ++-- .../src/main/resources/application.properties | 3 ++ .../SampleSessionRedisApplicationTests.java} | 27 ++++++++------- 10 files changed, 47 insertions(+), 38 deletions(-) delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties delete mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session-http-mongo => spring-boot-smoke-test-session-mongo}/build.gradle (94%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java => spring-boot-smoke-test-session-mongo/src/main/java/smoketest/session/mongodb/SampleSessionMongoApplication.java} (84%) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/resources/application.properties rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java => spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java} (80%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session-http-redis => spring-boot-smoke-test-session-redis}/build.gradle (93%) rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java => spring-boot-smoke-test-session-redis/src/main/java/smoketest/session/redis/SampleSessionRedisApplication.java} (84%) create mode 100644 spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/resources/application.properties rename spring-boot-tests/spring-boot-smoke-tests/{spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java => spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java} (82%) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties deleted file mode 100644 index ca5b9bafe2..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -management.endpoints.web.exposure.include=* -spring.mongodb.embedded.version=3.6.5 \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties deleted file mode 100644 index 705d36ce69..0000000000 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -management.endpoints.web.exposure.include=* \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/build.gradle similarity index 94% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/build.gradle index 2e14a54ddc..ce1acf78d1 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/build.gradle @@ -3,7 +3,7 @@ plugins { id "org.springframework.boot.conventions" } -description = "Spring Boot Http Session Mongodb smoke test" +description = "Spring Boot Session Mongodb smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator")) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/java/smoketest/session/mongodb/SampleSessionMongoApplication.java similarity index 84% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/java/smoketest/session/mongodb/SampleSessionMongoApplication.java index 2d98a3a579..5689b727aa 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/main/java/smoketest/session/mongodb/SampleHttpSessionMongoApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/java/smoketest/session/mongodb/SampleSessionMongoApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. @@ -22,10 +22,10 @@ import org.springframework.session.data.mongo.config.annotation.web.http.EnableM @SpringBootApplication @EnableMongoHttpSession -public class SampleHttpSessionMongoApplication { +public class SampleSessionMongoApplication { public static void main(String[] args) { - SpringApplication.run(SampleHttpSessionMongoApplication.class); + SpringApplication.run(SampleSessionMongoApplication.class); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/resources/application.properties new file mode 100644 index 0000000000..98058a93e6 --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/main/resources/application.properties @@ -0,0 +1,3 @@ +management.endpoints.web.exposure.include=* +spring.security.user.name=user +spring.security.user.password=password \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java similarity index 80% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java index aab4385d6f..c6340a1a33 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-mongo/src/test/java/smoketest/session/mongodb/SampleHttpSessionMongoApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-mongo/src/test/java/smoketest/session/mongodb/SampleSessionMongoApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. @@ -40,25 +40,28 @@ import org.springframework.test.context.DynamicPropertySource; import static org.assertj.core.api.Assertions.assertThat; +/** + * Tests for {@link SampleSessionMongoApplication}. + * + * @author Angel L. Villalain + */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Testcontainers(disabledWithoutDocker = true) -public class SampleHttpSessionMongoApplicationTests { +public class SampleSessionMongoApplicationTests { - static final String USERNAME = "user"; - static final String PASSWORD = "password"; - static final String ROOT = "/"; + private static final String USERNAME = "user"; + + private static final String PASSWORD = "password"; + + @Autowired + private TestRestTemplate restTemplate; @Container static MongoDBContainer mongo = new MongoDBContainer(DockerImageNames.mongo()).withStartupAttempts(3) .withStartupTimeout(Duration.ofMinutes(2)); - @Autowired - private TestRestTemplate template; - @DynamicPropertySource static void applicationProperties(DynamicPropertyRegistry registry) { - registry.add("spring.security.user.name", () -> USERNAME); - registry.add("spring.security.user.password", () -> PASSWORD); registry.add("spring.data.mongodb.uri", mongo::getReplicaSetUrl); } @@ -66,7 +69,7 @@ public class SampleHttpSessionMongoApplicationTests { @SuppressWarnings("unchecked") void sessionsEndpointShouldReturnUserSessions() { createSession(); - ResponseEntity> response = this.getSessions(); + ResponseEntity> response = getSessions(); assertThat(response).isNotNull(); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); List> sessions = (List>) response.getBody().get("sessions"); @@ -74,17 +77,17 @@ public class SampleHttpSessionMongoApplicationTests { } private void createSession() { - URI uri = URI.create(ROOT); + URI uri = URI.create("/"); HttpHeaders headers = new HttpHeaders(); headers.setBasicAuth(USERNAME, PASSWORD); RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); - this.template.exchange(request, String.class); + this.restTemplate.exchange(request, String.class); } @SuppressWarnings("unchecked") private ResponseEntity> getSessions() { - return (ResponseEntity>) (ResponseEntity) this.template.withBasicAuth(USERNAME, PASSWORD) - .getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); + return (ResponseEntity>) (ResponseEntity) this.restTemplate + .withBasicAuth(USERNAME, PASSWORD).getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/build.gradle similarity index 93% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/build.gradle index 715c15c489..e137ac6460 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/build.gradle +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/build.gradle @@ -3,7 +3,7 @@ plugins { id "org.springframework.boot.conventions" } -description = "Spring Boot Http Session Mongodb smoke test" +description = "Spring Boot Session Mongodb smoke test" dependencies { implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator")) diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/java/smoketest/session/redis/SampleSessionRedisApplication.java similarity index 84% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/java/smoketest/session/redis/SampleSessionRedisApplication.java index a3f4aa080c..bbc639ea9f 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/main/java/smoketest/session/redis/SampleHttpSessionRedisApplication.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/java/smoketest/session/redis/SampleSessionRedisApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. @@ -22,10 +22,10 @@ import org.springframework.session.data.redis.config.annotation.web.http.EnableR @SpringBootApplication @EnableRedisHttpSession -public class SampleHttpSessionRedisApplication { +public class SampleSessionRedisApplication { public static void main(String[] args) { - SpringApplication.run(SampleHttpSessionRedisApplication.class); + SpringApplication.run(SampleSessionRedisApplication.class); } } diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/resources/application.properties b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/resources/application.properties new file mode 100644 index 0000000000..52ebf796de --- /dev/null +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/main/resources/application.properties @@ -0,0 +1,3 @@ +management.endpoints.web.exposure.include=* +spring.security.user.name=user +spring.security.user.password=password diff --git a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java similarity index 82% rename from spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java rename to spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java index dcc36c7e1d..8ea78be57d 100644 --- a/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-http-redis/src/test/java/smoketest/session/redis/SampleHttpSessionRedisApplicationTests.java +++ b/spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-session-redis/src/test/java/smoketest/session/redis/SampleSessionRedisApplicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. @@ -38,24 +38,27 @@ import org.springframework.test.context.DynamicPropertySource; import static org.assertj.core.api.Assertions.assertThat; +/** + * Tests for {@link SampleSessionRedisApplication}. + * + * @author Angel L. Villalain + */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @Testcontainers(disabledWithoutDocker = true) -public class SampleHttpSessionRedisApplicationTests { +public class SampleSessionRedisApplicationTests { + + private static final String USERNAME = "user"; - static final String USERNAME = "user"; - static final String PASSWORD = "password"; - static final String ROOT = "/"; + private static final String PASSWORD = "password"; @Container static RedisContainer redis = new RedisContainer(); @Autowired - private TestRestTemplate template; + private TestRestTemplate restTemplate; @DynamicPropertySource static void applicationProperties(DynamicPropertyRegistry registry) { - registry.add("spring.security.user.name", () -> USERNAME); - registry.add("spring.security.user.password", () -> PASSWORD); registry.add("spring.redis.host", redis::getHost); registry.add("spring.redis.port", redis::getFirstMappedPort); } @@ -72,17 +75,17 @@ public class SampleHttpSessionRedisApplicationTests { } private void createSession() { - URI uri = URI.create(ROOT); + URI uri = URI.create("/"); HttpHeaders headers = new HttpHeaders(); headers.setBasicAuth(USERNAME, PASSWORD); RequestEntity request = new RequestEntity<>(headers, HttpMethod.GET, uri); - this.template.exchange(request, String.class); + this.restTemplate.exchange(request, String.class); } @SuppressWarnings("unchecked") private ResponseEntity> getSessions() { - return (ResponseEntity>) (ResponseEntity) this.template.withBasicAuth(USERNAME, PASSWORD) - .getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); + return (ResponseEntity>) (ResponseEntity) this.restTemplate + .withBasicAuth(USERNAME, PASSWORD).getForEntity("/actuator/sessions?username=" + USERNAME, Map.class); } }