PushTemplate implements PushOperations { public PushResponse pushNotification(Notification notification) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<Notification> requestEntity = new HttpEntity<Notification>(notification, headers); if (notification.getScheduleFor() != null && !notification.getScheduleFor().isEmpty()) { return masterKeyRestOperations.exchange(PUSH_URL, HttpMethod.POST, requestEntity, PushResponse.class).getBody(); } masterKeyRestOperations.exchange(PUSH_URL, HttpMethod.POST, requestEntity, String.class); return null; } PushTemplate(RestOperations masterKeyRestOperations); PushResponse pushNotification(Notification notification); void pushNotifications(List<Notification> notifications); void sendBroadcast(Broadcast broadcast); List<PushStatistics> getStatistics(Date start, Date end);  }
@Test public void pushNotification_withOneDeviceToken() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-onetoken")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens(DEVICE_TOKEN).build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withManyDeviceTokens() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-manytokens")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens("token1","token2","token3").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withOneApid() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-oneapid")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").apids("apid1").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withManyApids() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-manyapids")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").apids("apid1","apid2","apid3").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withOneDevicePin() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-onedevicepin")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").devicePins("pin1").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withManyDevicePins() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-manydevicepins")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").devicePins("pin1","pin2","pin3").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withAliases() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withaliases")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").aliases("alias1","alias2","alias3").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withTags() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withtags")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").tags("tag1","tag2","tag3").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withExcludeTokens() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withexcludes")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").tags("tag1").excludeTokens("token1","token2","token3").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withSound() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withsound")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens(DEVICE_TOKEN).sound("cat.caf").build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withBadgeCount() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withbadgecount")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens(DEVICE_TOKEN).badge(10).build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withBadgeAuto() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withbadgeauto")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens(DEVICE_TOKEN).autoBadge().build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withBadgeIncrement() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withbadgeincrement")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens(DEVICE_TOKEN).badgeIncrement(5).build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withBadgeDecrement() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withbadgedecrement")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens(DEVICE_TOKEN).badgeDecrement(3).build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withExtraForAndroid() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withextra")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); Map<String, String> extra = new LinkedHashMap<String, String>(); extra.put("key1", "value1"); extra.put("key2", "value2"); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").apids("apid1").extra(extra).build()); assertNull(response); masterKeyMockServer.verify(); }
@Test public void pushNotification_withScheduleFor() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-withschedulefor")))) .andExpect(method(POST)) .andRespond(withResponse(jsonResource("data/schedulefor-response"), responseHeaders, HttpStatus.OK, "Okay")); PushResponse pushResponse = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").tags("tag1").scheduleFor("2010-07-27 22:48:00","2010-07-28 22:48:00").build()); assertEquals(2, pushResponse.getScheduledNotifications().size()); assertEquals("https: assertEquals("https: masterKeyMockServer.verify(); }
@Test public void pushNotification_withMixedDeviceTypes() { masterKeyMockServer.expect(requestTo("https: .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/push-mixeddevices")))) .andExpect(method(POST)) .andRespond(withResponse("", responseHeaders, HttpStatus.OK, "Okay")); PushResponse response = urbanAirship.pushOperations().pushNotification(Notification.builder("Hey!").deviceTokens("token1","token2","token3").apids("apid1", "apid2", "apid3").devicePins("pin1", "pin2", "pin3").build()); assertNull(response); masterKeyMockServer.verify(); }