Merge pull request #7062 from pkoli/master
BAEL-2886- post incremented counter variable and deleted integration test which was repeated
This commit is contained in:
commit
e4a0f9235d
|
@ -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<String> 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]));
|
||||
}
|
||||
|
||||
}
|
|
@ -32,6 +32,7 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
<version>${spring-boot-starter-data-mongodb.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -43,6 +44,7 @@
|
|||
|
||||
<properties>
|
||||
<spring-session-data-mongodb.version>2.1.3.RELEASE</spring-session-data-mongodb.version>
|
||||
<spring-boot-starter-data-mongodb.version>2.1.5.RELEASE</spring-boot-starter-data-mongodb.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -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 class SpringSessionMongoDBController {
|
|||
if (counter == null) {
|
||||
counter = 1;
|
||||
} else {
|
||||
counter += 1;
|
||||
counter++;
|
||||
}
|
||||
|
||||
session.setAttribute("count", counter);
|
||||
|
|
|
@ -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.http.HttpMethod;
|
|||
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<String> response = restTemplate.
|
||||
exchange("http://localhost:" + 8080, HttpMethod.GET, null, String.class);
|
||||
HttpEntity<String> response = restTemplate
|
||||
.exchange("http://localhost:" + 8080, HttpMethod.GET, null, String.class);
|
||||
HttpHeaders headers = response.getHeaders();
|
||||
String set_cookie = headers.getFirst(HttpHeaders.SET_COOKIE);
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue