diff options
Diffstat (limited to 'juick-api/src/test/java')
-rw-r--r-- | juick-api/src/test/java/com/juick/api/tests/MessagesTests.java | 23 |
1 files changed, 17 insertions, 6 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 63fac6a1..13d399ca 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 @@ -81,8 +81,8 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { @Inject private ImagesService imagesService; - private static User ugnich, freefd; - static String ugnichName, ugnichPassword, freefdName, freefdPassword; + private static User ugnich, freefd, juick; + static String ugnichName, ugnichPassword, freefdName, freefdPassword, juickName, juickPassword; static Message msg; private static boolean isSetUp = false; @@ -99,11 +99,15 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { ugnichPassword = "MyPassw0rd!"; freefdName = "freefd"; freefdPassword = "MyPassw0rd!"; - + juickName = "juick"; + juickPassword = "demo"; int ugnichId = userService.createUser(ugnichName, ugnichPassword); ugnich = userService.getUserByUID(ugnichId).orElseThrow(IllegalStateException::new); int freefdId = userService.createUser(freefdName, freefdPassword); freefd = userService.getUserByUID(freefdId).orElseThrow(IllegalStateException::new); + int juickId = userService.createUser(juickName, juickPassword); + juick = userService.getUserByUID(juickId).orElseThrow(IllegalStateException::new); + String msgText = "Привет, я - Угнич"; int mid = messagesService.createMessage(ugnich.getUid(), msgText, "png", null); @@ -245,9 +249,6 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { } @Test public void registerForNotificationsTests() throws Exception { - String juickName = "juick"; - String juickPassword = "demo"; - int juickId = userService.createUser(juickName, juickPassword); String token = "123456"; ExternalToken registration = new ExternalToken(null, "apns", token, null); mockMvc.perform(put("/notifications").with(httpBasic(ugnichName, ugnichPassword)) @@ -270,4 +271,14 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests { assertThat(uriComponents.getPath().substring(1), is("123456")); assertThat(uriComponents.getFragment(), is("23")); } + @Test + public void notificationsTokensTest() throws Exception { + List<ExternalToken> tokens = Collections.singletonList(new ExternalToken(null, "gcm", "123456", null)); + mockMvc.perform(delete("/notifications").with(httpBasic(ugnichName, ugnichPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isForbidden()); + mockMvc.perform(delete("/notifications").with(httpBasic(juickName, juickPassword)) + .contentType(MediaType.APPLICATION_JSON_UTF8) + .content(jsonMapper.writeValueAsBytes(tokens))).andExpect(status().isOk()); + } } |