Upgrade to Spring Boot 2.4.5 and latest Spring Session.
This commit is contained in:
64
pom.xml
64
pom.xml
@@ -15,8 +15,8 @@
|
||||
<developer>
|
||||
<id>gturnquist</id>
|
||||
<name>Greg Turnquist</name>
|
||||
<email>gturnquist@pivotal.io</email>
|
||||
<organization>Pivotal Software, Inc.</organization>
|
||||
<email>gturnquist@vmware.com</email>
|
||||
<organization>VMware</organization>
|
||||
<roles>
|
||||
<role>Project Lead</role>
|
||||
</roles>
|
||||
@@ -31,7 +31,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.0.RC1</version>
|
||||
<version>2.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
@@ -39,25 +39,11 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-session.version>2.0.2.RELEASE</spring-session.version>
|
||||
<spring-session-data-mongodb.version>2.0.2.RELEASE</spring-session-data-mongodb.version>
|
||||
<spring-data-releasetrain.version>Kay-SR4</spring-data-releasetrain.version>
|
||||
<spring-session.version>2.5.0</spring-session.version>
|
||||
<spring-session-data-mongodb.version>2.5.0</spring-session-data-mongodb.version>
|
||||
<spring-data-releasetrain.version>2021.0.0</spring-data-releasetrain.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>spring5-next</id>
|
||||
<properties>
|
||||
<jackson.version>2.9.0</jackson.version>
|
||||
<spring.version>5.0.5.BUILD-SNAPSHOT</spring.version>
|
||||
<spring-session.version>2.0.3.BUILD-SNAPSHOT</spring-session.version>
|
||||
<spring-session-data-mongodb.version>2.0.3.BUILD-SNAPSHOT</spring-session-data-mongodb.version>
|
||||
<spring-data-releasetrain.version>Lovelace-BUILD-SNAPSHOT</spring-data-releasetrain.version>
|
||||
<spring-security.version>5.0.3.BUILD-SNAPSHOT</spring-security.version>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<dependencies>
|
||||
<!-- tag::spring-session-data-mongodb[] -->
|
||||
<dependency>
|
||||
@@ -67,43 +53,5 @@
|
||||
</dependency>
|
||||
<!-- end::spring-session-data-mongodb[] -->
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
<groupId>org.springframework.session.data.mongodb</groupId>
|
||||
<artifactId>spring-session-data-mongodb-reactive-boot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Session MongoDB - Examples - Reactive Spring Boot</name>
|
||||
|
||||
@@ -34,11 +33,7 @@
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -16,16 +16,54 @@
|
||||
|
||||
package org.springframework.session.mongodb.examples;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
* @author Greg Turnquist
|
||||
* @since 5.0
|
||||
*/
|
||||
@Data
|
||||
public class SessionAttributeForm {
|
||||
|
||||
private String attributeName;
|
||||
private String attributeValue;
|
||||
|
||||
public String getAttributeName() {
|
||||
return attributeName;
|
||||
}
|
||||
|
||||
public void setAttributeName(String attributeName) {
|
||||
this.attributeName = attributeName;
|
||||
}
|
||||
|
||||
public String getAttributeValue() {
|
||||
return attributeValue;
|
||||
}
|
||||
|
||||
public void setAttributeValue(String attributeValue) {
|
||||
this.attributeValue = attributeValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof SessionAttributeForm))
|
||||
return false;
|
||||
SessionAttributeForm that = (SessionAttributeForm) o;
|
||||
return Objects.equals(attributeName, that.attributeName) && Objects.equals(attributeValue, that.attributeValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(attributeName, attributeValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return "SessionAttributeForm{" + "attributeName='" + attributeName + '\'' + ", attributeValue='" + attributeValue
|
||||
+ '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SessionController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String index(Model model, WebSession webSession) {
|
||||
|
||||
|
||||
model.addAttribute("webSession", webSession);
|
||||
return "index";
|
||||
}
|
||||
|
||||
@@ -16,73 +16,69 @@
|
||||
|
||||
package org.springframework.session.mongodb.examples;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.session.mongodb.examples.pages.HomePage;
|
||||
import org.springframework.session.mongodb.examples.pages.HomePage.Attribute;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
/**
|
||||
* @author Eddú Meléndez
|
||||
* @author Rob Winch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class AttributeTests {
|
||||
|
||||
@LocalServerPort
|
||||
int port;
|
||||
@LocalServerPort int port;
|
||||
|
||||
private WebDriver driver;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.driver = new HtmlUnitDriver();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.driver.quit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void home() {
|
||||
|
||||
HomePage home = HomePage.go(this.driver, this.port);
|
||||
home.assertAt();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noAttributes() {
|
||||
|
||||
HomePage home = HomePage.go(this.driver, this.port);
|
||||
assertThat(home.attributes()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createAttribute() {
|
||||
|
||||
HomePage home = HomePage.go(this.driver, this.port);
|
||||
// @formatter:off
|
||||
home = home.form()
|
||||
.attributeName("a")
|
||||
.attributeValue("b")
|
||||
.submit(HomePage.class);
|
||||
// @formatter:on
|
||||
home = home.form().attributeName("a").attributeValue("b").submit(HomePage.class);
|
||||
|
||||
List<Attribute> attributes = home.attributes();
|
||||
assertThat(attributes).hasSize(1);
|
||||
|
||||
Attribute row = attributes.get(0);
|
||||
assertThat(row.getAttributeName()).isEqualTo("a");
|
||||
assertThat(row.getAttributeValue()).isEqualTo("b");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.openqa.selenium.SearchContext;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
@@ -45,16 +46,19 @@ public class HomePage {
|
||||
List<Attribute> attributes;
|
||||
|
||||
public HomePage(WebDriver driver) {
|
||||
|
||||
this.driver = driver;
|
||||
this.attributes = new ArrayList<>();
|
||||
}
|
||||
|
||||
private static void get(WebDriver driver, int port, String get) {
|
||||
|
||||
String baseUrl = "http://localhost:" + port;
|
||||
driver.get(baseUrl + get);
|
||||
}
|
||||
|
||||
public static HomePage go(WebDriver driver, int port) {
|
||||
|
||||
get(driver, port, "/");
|
||||
return PageFactory.initElements(driver, HomePage.class);
|
||||
}
|
||||
@@ -64,11 +68,13 @@ public class HomePage {
|
||||
}
|
||||
|
||||
public List<Attribute> attributes() {
|
||||
List<Attribute> rows = new ArrayList<>();
|
||||
for (WebElement tr : this.trs) {
|
||||
rows.add(new Attribute(tr));
|
||||
}
|
||||
|
||||
List<Attribute> rows = this.trs.stream() //
|
||||
.map(Attribute::new) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
this.attributes.addAll(rows);
|
||||
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
@@ -77,6 +83,7 @@ public class HomePage {
|
||||
}
|
||||
|
||||
public class Form {
|
||||
|
||||
@FindBy(name = "attributeName")
|
||||
WebElement attributeName;
|
||||
|
||||
@@ -91,22 +98,26 @@ public class HomePage {
|
||||
}
|
||||
|
||||
public Form attributeName(String text) {
|
||||
|
||||
this.attributeName.sendKeys(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Form attributeValue(String text) {
|
||||
|
||||
this.attributeValue.sendKeys(text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> T submit(Class<T> page) {
|
||||
|
||||
this.submit.click();
|
||||
return PageFactory.initElements(HomePage.this.driver, page);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Attribute {
|
||||
|
||||
@FindBy(xpath = ".//td[1]")
|
||||
WebElement attributeName;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
<groupId>org.springframework.session.data.mongodb</groupId>
|
||||
<artifactId>spring-session-data-mongodb-traditional-boot</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Spring Session MongoDB - Examples - Traditional Spring Boot</name>
|
||||
|
||||
@@ -40,6 +39,10 @@
|
||||
<groupId>nz.net.ultraq.thymeleaf</groupId>
|
||||
<artifactId>thymeleaf-layout-dialect</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thymeleaf.extras</groupId>
|
||||
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
@@ -60,6 +63,11 @@
|
||||
<artifactId>selenium-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -16,56 +16,53 @@
|
||||
|
||||
package org.springframework.session.mongodb.examples;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Cookie;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.springframework.session.mongodb.examples.pages.HomePage;
|
||||
import org.springframework.session.mongodb.examples.pages.LoginPage;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.session.mongodb.examples.pages.HomePage;
|
||||
import org.springframework.session.mongodb.examples.pages.LoginPage;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.htmlunit.webdriver.MockMvcHtmlUnitDriverBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Pool Dolorier
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@AutoConfigureMockMvc
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
|
||||
public class BootTests {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@Autowired private MockMvc mockMvc;
|
||||
|
||||
private WebDriver driver;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.driver = MockMvcHtmlUnitDriverBuilder
|
||||
.mockMvcSetup(this.mockMvc)
|
||||
.build();
|
||||
this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).build();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
this.driver.quit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unauthenticatedUserSentToLogInPage() {
|
||||
|
||||
HomePage homePage = HomePage.go(this.driver);
|
||||
LoginPage loginPage = homePage.unauthenticated();
|
||||
loginPage.assertAt();
|
||||
@@ -73,10 +70,13 @@ public class BootTests {
|
||||
|
||||
@Test
|
||||
public void logInViewsHomePage() {
|
||||
|
||||
LoginPage loginPage = LoginPage.go(this.driver);
|
||||
loginPage.assertAt();
|
||||
|
||||
HomePage homePage = loginPage.login("user", "password");
|
||||
homePage.assertAt();
|
||||
|
||||
WebElement username = homePage.getDriver().findElement(By.id("un"));
|
||||
assertThat(username.getText()).isEqualTo("user");
|
||||
Set<Cookie> cookies = homePage.getDriver().manage().getCookies();
|
||||
@@ -86,19 +86,24 @@ public class BootTests {
|
||||
|
||||
@Test
|
||||
public void logoutSuccess() {
|
||||
|
||||
LoginPage loginPage = LoginPage.go(this.driver);
|
||||
HomePage homePage = loginPage.login("user", "password");
|
||||
LoginPage successLogoutPage = homePage.logout();
|
||||
|
||||
successLogoutPage.assertAt();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loggedOutUserSentToLoginPage() {
|
||||
|
||||
LoginPage loginPage = LoginPage.go(this.driver);
|
||||
HomePage homePage = loginPage.login("user", "password");
|
||||
homePage.logout();
|
||||
|
||||
HomePage backHomePage = HomePage.go(this.driver);
|
||||
LoginPage backLoginPage = backHomePage.unauthenticated();
|
||||
|
||||
backLoginPage.assertAt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public abstract class BasePage {
|
||||
}
|
||||
|
||||
public static void get(WebDriver driver, String get) {
|
||||
|
||||
String baseUrl = "http://localhost";
|
||||
driver.get(baseUrl + get);
|
||||
}
|
||||
|
||||
@@ -16,35 +16,36 @@
|
||||
|
||||
package org.springframework.session.mongodb.examples.pages;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Pool Dolorier
|
||||
*/
|
||||
public class HomePage extends BasePage {
|
||||
|
||||
@FindBy(css = "input[type='submit']")
|
||||
private WebElement submit;
|
||||
@FindBy(css = "input[type='submit']") private WebElement submit;
|
||||
|
||||
public HomePage(WebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public static HomePage go(WebDriver driver) {
|
||||
|
||||
get(driver, "/");
|
||||
return PageFactory.initElements(driver, HomePage.class);
|
||||
}
|
||||
|
||||
public LoginPage unauthenticated() {
|
||||
return LoginPage.go(getDriver());
|
||||
return LoginPage.go(getDriver());
|
||||
}
|
||||
|
||||
public LoginPage logout() {
|
||||
|
||||
this.submit.click();
|
||||
return LoginPage.go(getDriver());
|
||||
}
|
||||
|
||||
@@ -16,44 +16,43 @@
|
||||
|
||||
package org.springframework.session.mongodb.examples.pages;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
import org.openqa.selenium.support.PageFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Pool Dolorier
|
||||
*/
|
||||
public class LoginPage extends BasePage {
|
||||
|
||||
@FindBy(name = "username")
|
||||
private WebElement username;
|
||||
@FindBy(name = "username") private WebElement username;
|
||||
|
||||
@FindBy(name = "password")
|
||||
private WebElement password;
|
||||
@FindBy(name = "password") private WebElement password;
|
||||
|
||||
@FindBy(css = "input[name='submit']")
|
||||
private WebElement submit;
|
||||
@FindBy(css = "button[type='submit']") private WebElement submit;
|
||||
|
||||
public LoginPage(WebDriver driver) {
|
||||
super(driver);
|
||||
}
|
||||
|
||||
public static LoginPage go(WebDriver driver) {
|
||||
|
||||
get(driver, "/login");
|
||||
return PageFactory.initElements(driver, LoginPage.class);
|
||||
}
|
||||
|
||||
public void assertAt() {
|
||||
assertThat(getDriver().getTitle()).isEqualTo("Login Page");
|
||||
assertThat(getDriver().getTitle()).isEqualTo("Please sign in");
|
||||
}
|
||||
|
||||
public HomePage login(String user, String password) {
|
||||
|
||||
this.username.sendKeys(user);
|
||||
this.password.sendKeys(password);
|
||||
this.submit.click();
|
||||
return HomePage.go(getDriver());
|
||||
return HomePage.go(getDriver());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user