aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src')
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java24
1 files changed, 24 insertions, 0 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 6fddba11..b626b0e9 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
@@ -17,7 +17,9 @@
package com.juick.api.tests;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.juick.DeviceRegistration;
import com.juick.Message;
import com.juick.Tag;
import com.juick.User;
@@ -46,6 +48,7 @@ import org.springframework.web.context.WebApplicationContext;
import javax.inject.Inject;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -238,4 +241,25 @@ public class MessagesTests extends AbstractJUnit4SpringContextTests {
assertThat(authHash, equalTo(ugnichHash));
mockMvc.perform(get("/home").param("hash", ugnichHash)).andExpect(status().isOk());
}
+ @Test
+ public void registerForNotificationsTests() throws Exception {
+ String juickName = "juick";
+ String juickPassword = "demo";
+ int juickId = userService.createUser(juickName, juickPassword);
+ String token = "123456";
+ DeviceRegistration registration = new DeviceRegistration("apns", token);
+ mockMvc.perform(put("/notifications").with(httpBasic(ugnichName, ugnichPassword))
+ .contentType(MediaType.APPLICATION_JSON_UTF8)
+ .content(jsonMapper.writeValueAsBytes(Collections.singletonList(registration))))
+ .andExpect(status().isOk());
+ MvcResult result = mockMvc.perform(get("/notifications")
+ .param("uid", String.valueOf(ugnich.getUid()))
+ .with(httpBasic(juickName, juickPassword)))
+ .andExpect(status().isOk())
+ .andReturn();
+ List<User> user = jsonMapper.readValue(result.getResponse().getContentAsString(),
+ new TypeReference<List<User>>() {
+ });
+ assertThat(user.get(0).getDevices().get(0).getToken(), equalTo(token));
+ }
}