Polish "Add smoke tests for Spring Session Redis/Mongo"
See gh-28362
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
management.endpoints.web.exposure.include=*
|
||||
spring.mongodb.embedded.version=3.6.5
|
||||
@@ -1 +0,0 @@
|
||||
management.endpoints.web.exposure.include=*
|
||||
@@ -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"))
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
management.endpoints.web.exposure.include=*
|
||||
spring.security.user.name=user
|
||||
spring.security.user.password=password
|
||||
@@ -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<Map<String, Object>> response = this.getSessions();
|
||||
ResponseEntity<Map<String, Object>> response = getSessions();
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
List<Map<String, Object>> sessions = (List<Map<String, Object>>) 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<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri);
|
||||
this.template.exchange(request, String.class);
|
||||
this.restTemplate.exchange(request, String.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ResponseEntity<Map<String, Object>> getSessions() {
|
||||
return (ResponseEntity<Map<String, Object>>) (ResponseEntity) this.template.withBasicAuth(USERNAME, PASSWORD)
|
||||
.getForEntity("/actuator/sessions?username=" + USERNAME, Map.class);
|
||||
return (ResponseEntity<Map<String, Object>>) (ResponseEntity) this.restTemplate
|
||||
.withBasicAuth(USERNAME, PASSWORD).getForEntity("/actuator/sessions?username=" + USERNAME, Map.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"))
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
management.endpoints.web.exposure.include=*
|
||||
spring.security.user.name=user
|
||||
spring.security.user.password=password
|
||||
@@ -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 {
|
||||
|
||||
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";
|
||||
|
||||
@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<Object> request = new RequestEntity<>(headers, HttpMethod.GET, uri);
|
||||
this.template.exchange(request, String.class);
|
||||
this.restTemplate.exchange(request, String.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ResponseEntity<Map<String, Object>> getSessions() {
|
||||
return (ResponseEntity<Map<String, Object>>) (ResponseEntity) this.template.withBasicAuth(USERNAME, PASSWORD)
|
||||
.getForEntity("/actuator/sessions?username=" + USERNAME, Map.class);
|
||||
return (ResponseEntity<Map<String, Object>>) (ResponseEntity) this.restTemplate
|
||||
.withBasicAuth(USERNAME, PASSWORD).getForEntity("/actuator/sessions?username=" + USERNAME, Map.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user