From 559ae343aa72db04e12b94acfa0bec30ed9a11f1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 9 Dec 2016 16:14:27 +0300 Subject: juick-spring-www: merge some work from develop branch, port some templates to Thymeleaf --- .../java/com/juick/api/tests/MessagesTests.java | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'juick-api/src/test') diff --git a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java index e0f9b840..9f74c00d 100644 --- a/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java +++ b/juick-api/src/test/java/com/juick/api/tests/MessagesTests.java @@ -38,6 +38,7 @@ import static org.mockito.Mockito.when; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; /** @@ -173,12 +174,10 @@ public class MessagesTests { @Test public void homeTestWithMessagesAndRememberMe() throws Exception { - String ugnichName = "ugnich"; - String uginchPassword = "MyPassw0rd!"; String msgText = "Привет, я - Угнич"; String hash = "12345678"; - User user = getUser(1, ugnichName, uginchPassword); + User user = getUser(1, ugnichName, ugnichPassword); Message msg = getMessage(user, msgText); when(userService.getUIDbyName(ugnichName)) @@ -198,7 +197,7 @@ public class MessagesTests { mockMvc.perform( get("/home") - .with(httpBasic(ugnichName, uginchPassword))) + .with(httpBasic(ugnichName, ugnichPassword))) .andExpect(status().isOk()) .andReturn(); @@ -211,11 +210,8 @@ public class MessagesTests { } @Test - public void homeTestWithMEssagesAndSimpleCors() throws Exception { - String ugnichName = "ugnich"; - String uginchPassword = "MyPassw0rd!"; - - User user = getUser(1, ugnichName, uginchPassword); + public void homeTestWithMessagesAndSimpleCors() throws Exception { + User user = getUser(1, ugnichName, ugnichPassword); Message msg = getMessage(user, null); when(userService.getFullyUserByName(ugnichName)) @@ -229,7 +225,7 @@ public class MessagesTests { mockMvc.perform( get("/home") - .with(httpBasic(ugnichName, uginchPassword)) + .with(httpBasic(ugnichName, ugnichPassword)) .header("Origin", "http://api.example.net")) .andExpect(status().isOk()) .andExpect(header().string("Access-Control-Allow-Origin", "*")); @@ -237,16 +233,13 @@ public class MessagesTests { @Test public void homeTestWithPreflightCors() throws Exception { - String ugnichName = "ugnich"; - String uginchPassword = "MyPassw0rd!"; - - User user = getUser(1, ugnichName, uginchPassword); + User user = getUser(1, ugnichName, ugnichPassword); when(userService.getFullyUserByName(ugnichName)) .thenReturn(user); mockMvc.perform( options("/home") - .with(httpBasic(ugnichName, uginchPassword)) + .with(httpBasic(ugnichName, ugnichPassword)) .header("Origin", "http://api.example.net") .header("Access-Control-Request-Method", "POST") .header("Access-Control-Request-Headers", "X-PINGOTHER, Content-Type")) @@ -291,4 +284,11 @@ public class MessagesTests { .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[0].messages", is(5))); } + @Test + public void postWithReferer() throws Exception { + mockMvc.perform(post("/post") + .param("body", "yo") + .with(httpBasic(ugnichName, ugnichPassword))) + .andExpect(status().isOk()); + } } -- cgit v1.2.3