aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/test/java
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-28 20:04:05 +0700
committerGravatar Vitaly Takmazov2016-11-28 16:11:10 +0300
commit915e804c097ed97e39eebc498f1339cab53109cd (patch)
tree875ddc9572df97af55934cce597bd4b0c25f7f90 /juick-api/src/test/java
parent91554cb30eefd48e85ebb744aea0be7efff13e11 (diff)
WebUtils utilite class ; some inprovements; tests now run successfully
Diffstat (limited to 'juick-api/src/test/java')
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java27
1 files changed, 17 insertions, 10 deletions
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<String> 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)));