Add MockWebSession for use with MockServerWebExchange

Issue: SPR-16772
This commit is contained in:
Rossen Stoyanchev
2018-05-11 10:53:28 -04:00
parent 7f954ebc32
commit 15182b29a4
4 changed files with 245 additions and 10 deletions

View File

@@ -21,11 +21,11 @@ import java.util.HashSet;
import org.junit.Test;
import org.springframework.mock.web.test.server.MockWebSession;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.server.WebSession;
import org.springframework.web.server.session.InMemoryWebSessionStore;
import static java.util.Arrays.*;
import static org.junit.Assert.*;
@@ -50,9 +50,7 @@ public class SessionAttributesHandlerTests {
@Test
public void retrieveAttributes() {
WebSession session = new InMemoryWebSessionStore().createWebSession().block();
assertNotNull(session);
WebSession session = new MockWebSession();
session.getAttributes().put("attr1", "value1");
session.getAttributes().put("attr2", "value2");
session.getAttributes().put("attr3", new TestBean());
@@ -72,9 +70,7 @@ public class SessionAttributesHandlerTests {
@Test
public void cleanupAttributes() {
WebSession session = new InMemoryWebSessionStore().createWebSession().block();
assertNotNull(session);
WebSession session = new MockWebSession();
session.getAttributes().put("attr1", "value1");
session.getAttributes().put("attr2", "value2");
session.getAttributes().put("attr3", new TestBean());
@@ -94,14 +90,13 @@ public class SessionAttributesHandlerTests {
@Test
public void storeAttributes() {
WebSession session = new InMemoryWebSessionStore().createWebSession().block();
assertNotNull(session);
ModelMap model = new ModelMap();
model.put("attr1", "value1");
model.put("attr2", "value2");
model.put("attr3", new TestBean());
WebSession session = new MockWebSession();
sessionAttributesHandler.storeAttributes(session, model);
assertEquals("value1", session.getAttributes().get("attr1"));