aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-11-01 12:55:21 +0300
committerGravatar Vitaly Takmazov2017-11-01 12:55:21 +0300
commite2c2cf416db9637ebd41c489cf5a533824d17d4c (patch)
tree6f421d432b54a1a694af946438a5e6e4c1c53af5
parent0dcabe039a51a3a1aebd9a656a8dde2895b5e03a (diff)
notifications: fix tokens deletion
-rw-r--r--juick-api/src/test/java/com/juick/api/tests/MessagesTests.java23
-rw-r--r--juick-core/src/main/java/com/juick/ExternalToken.java6
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java2
3 files changed, 24 insertions, 7 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());
+ }
}
diff --git a/juick-core/src/main/java/com/juick/ExternalToken.java b/juick-core/src/main/java/com/juick/ExternalToken.java
index 933ecf82..f6094478 100644
--- a/juick-core/src/main/java/com/juick/ExternalToken.java
+++ b/juick-core/src/main/java/com/juick/ExternalToken.java
@@ -38,6 +38,12 @@ public class ExternalToken {
this.type = type;
this.token = token;
this.secret = secret;
+ if (this.type == null) {
+ throw new IllegalStateException("Token must have type");
+ }
+ if (this.token == null) {
+ throw new IllegalStateException("Token must have value");
+ }
}
public String getType() {
diff --git a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
index fce52987..6e6c8632 100644
--- a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
+++ b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
@@ -29,7 +29,7 @@ public class NotificationsTokenService extends BaseRestService implements TokenS
public void deleteTokens(String type, List<String> devices) {
if (devices.size() > 0) {
List<ExternalToken> list = devices.stream()
- .map(d -> new ExternalToken(null, null, type, d)).collect(Collectors.toList());
+ .map(d -> new ExternalToken(null, type, d, null)).collect(Collectors.toList());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
getRest().exchange("http://api.juick.com/notifications",