aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/test/java/com')
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java37
1 files changed, 36 insertions, 1 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 7f238b79..cec2bc7d 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
@@ -19,6 +19,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.http.MediaType;
+import org.springframework.security.crypto.codec.Base64;
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -28,7 +29,9 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import javax.inject.Inject;
+import javax.servlet.http.Cookie;
import java.util.Collections;
+import java.util.Optional;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
@@ -150,7 +153,39 @@ public class MessagesTests {
}
@Test
- public void homeTestWithSimpleCors() throws Exception {
+ public void homeTestWithMessagesAndRememberMe() throws Exception {
+ String ugnichName = "ugnich";
+ String uginchPassword = "MyPassw0rd!";
+ String msgText = "Привет, я - Угнич";
+ String hash = "12345678";
+
+ User user = getUser(1, ugnichName, uginchPassword);
+ Message msg = getMessage(user, msgText);
+
+ when(userService.getUserByName(ugnichName))
+ .thenReturn(user);
+ when(userService.getUserByUID(1))
+ .thenReturn(Optional.of(user));
+ when(userService.getFullyUserByName(ugnichName))
+ .thenReturn(user);
+ when(messagesService.getMyFeed(1, 0))
+ .thenReturn(Collections.singletonList(1));
+ when(messagesService.getMessages(Collections.singletonList(1)))
+ .thenReturn(Collections.singletonList(msg));
+ when(userService.getUIDbyHash(hash))
+ .thenReturn(1);
+
+ Cookie cookie = new Cookie("hash", new String(Base64.encode(hash.getBytes())));
+ cookie.setDomain("juick.com");
+ cookie.setMaxAge(100);
+
+ mockMvc.perform(
+ get("/home").cookie(cookie))
+ .andExpect(status().isOk());
+ }
+
+ @Test
+ public void homeTestWithMEssagesAndSimpleCors() throws Exception {
String ugnichName = "ugnich";
String uginchPassword = "MyPassw0rd!";