diff --git a/spring-session/mongodb-session/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java b/spring-session/mongodb-session/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java deleted file mode 100644 index c73335b49b17..000000000000 --- a/spring-session/mongodb-session/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.springsessionmongodb; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -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.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.session.data.mongo.MongoOperationsSessionRepository; -import org.springframework.test.context.junit4.SpringRunner; -import springsessionmongodb.SpringSessionMongoDBApplication; - -import java.util.Base64; - - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = SpringSessionMongoDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class SpringSessionMongoDBIntegrationTest { - - @Autowired - private MongoOperationsSessionRepository repository; - - private TestRestTemplate restTemplate = new TestRestTemplate(); - - @Test - public void givenEndpointIsCalledTwiceAndResponseIsReturned_whenMongoDBIsQueriedForCount_thenCountMustBeSame() { - HttpEntity response = restTemplate. - exchange("http://localhost:" + 8080, HttpMethod.GET, null, String.class); - HttpHeaders headers = response.getHeaders(); - String set_cookie = headers.getFirst(HttpHeaders.SET_COOKIE); - - Assert.assertEquals(response.getBody(), - repository.findById(getSessionId(set_cookie)).getAttribute("count").toString()); - } - - private String getSessionId(String set_cookie) { - return new String(Base64.getDecoder().decode(set_cookie.split(";")[0].split("=")[1])); - } - -} diff --git a/spring-session/spring-session-mongodb/pom.xml b/spring-session/spring-session-mongodb/pom.xml index 714833cf99cf..16fbaccc84a5 100644 --- a/spring-session/spring-session-mongodb/pom.xml +++ b/spring-session/spring-session-mongodb/pom.xml @@ -32,6 +32,7 @@ org.springframework.boot spring-boot-starter-data-mongodb + ${spring-boot-starter-data-mongodb.version} @@ -43,6 +44,7 @@ 2.1.3.RELEASE + 2.1.5.RELEASE diff --git a/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java b/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java index 1c38f419c33e..b5cb4520a032 100644 --- a/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java +++ b/spring-session/spring-session-mongodb/src/main/java/com/baeldung/springsessionmongodb/controller/SpringSessionMongoDBController.java @@ -1,11 +1,11 @@ package com.baeldung.springsessionmongodb.controller; -import javax.servlet.http.HttpSession; - import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import javax.servlet.http.HttpSession; + @RestController public class SpringSessionMongoDBController { @@ -17,7 +17,7 @@ public ResponseEntity count(HttpSession session) { if (counter == null) { counter = 1; } else { - counter += 1; + counter++; } session.setAttribute("count", counter); diff --git a/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java b/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java index eb9f4164a647..9dc45c5b321b 100644 --- a/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java +++ b/spring-session/spring-session-mongodb/src/test/java/com/baeldung/springsessionmongodb/SpringSessionMongoDBIntegrationTest.java @@ -1,7 +1,5 @@ package com.baeldung.springsessionmongodb; -import java.util.Base64; - import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -14,6 +12,8 @@ import org.springframework.session.data.mongo.MongoOperationsSessionRepository; import org.springframework.test.context.junit4.SpringRunner; +import java.util.Base64; + @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringSessionMongoDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @@ -26,8 +26,8 @@ public class SpringSessionMongoDBIntegrationTest { @Test public void givenEndpointIsCalledTwiceAndResponseIsReturned_whenMongoDBIsQueriedForCount_thenCountMustBeSame() { - HttpEntity response = restTemplate. - exchange("http://localhost:" + 8080, HttpMethod.GET, null, String.class); + HttpEntity response = restTemplate + .exchange("http://localhost:" + 8080, HttpMethod.GET, null, String.class); HttpHeaders headers = response.getHeaders(); String set_cookie = headers.getFirst(HttpHeaders.SET_COOKIE); diff --git a/spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextIntegrationTest.java index 3c58b2673f4d..16b7404f5729 100644 --- a/spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextIntegrationTest.java @@ -1,12 +1,11 @@ package org.baeldung; +import com.baeldung.springsessionmongodb.SpringSessionMongoDBApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.springsessionmongodb.SpringSessionMongoDBApplication; - @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringSessionMongoDBApplication.class) public class SpringContextIntegrationTest {