From 915e804c097ed97e39eebc498f1339cab53109cd Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Mon, 28 Nov 2016 20:04:05 +0700 Subject: WebUtils utilite class ; some inprovements; tests now run successfully --- .../java/com/juick/api/tests/MessagesTests.java | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'juick-api/src/test/java/com/juick/api/tests') 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 66cd6048..9425a819 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 @@ -30,8 +30,7 @@ import org.springframework.web.context.WebApplicationContext; import javax.inject.Inject; import javax.servlet.http.Cookie; -import java.util.Collections; -import java.util.Optional; +import java.util.*; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; @@ -105,15 +104,15 @@ public class MessagesTests { @Test public void testAllUnAuthorized() throws Exception { + when(userService.getUserByName(null)) + .thenReturn(new User()); + mockMvc.perform(get("/")) .andExpect(status().is4xxClientError()); mockMvc.perform(get("/home")) .andExpect(status().is4xxClientError()); - mockMvc.perform(get("/messages")) - .andExpect(status().is4xxClientError()); - mockMvc.perform(get("/thread")) .andExpect(status().is4xxClientError()); @@ -229,22 +228,30 @@ public class MessagesTests { .andExpect(header().string("Access-Control-Allow-Methods", "POST,GET,PUT,OPTIONS,DELETE")) .andExpect(header().string("Access-Control-Allow-Headers", "X-PINGOTHER, Content-Type")); } + @Test public void anonymousApis() throws Exception { String ugnichName = "ugnich"; String uginchPassword = "MyPassw0rd!"; String freefdName = "freefd"; String freefdPassword = "MyPassw0rd!"; + User ugnich = getUser(1, ugnichName, uginchPassword); User freefd = getUser(2, freefdName, freefdPassword); - when(userService.getFullyUserByName(ugnichName)) - .thenReturn(ugnich); - when(userService.getFullyUserByName(freefdName)) - .thenReturn(freefd); + + List users = new ArrayList<>(2); + users.add(ugnichName); + users.add(freefdName); + + when(userService.getUsersByName(users)) + .thenReturn(Arrays.asList(ugnich, freefd)); + mockMvc.perform(get("/messages")) .andExpect(status().isOk()); + mockMvc.perform(get("/users") - .param("uname", "ugnich").param("uname", "freefd")) + .param("uname", "ugnich") + .param("uname", "freefd")) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$", hasSize(2))); -- cgit v1.2.3