RegistrationTemplate implements RegistrationOperations { public void registerIOSDevice(IOSDeviceConfig deviceConfig) { if (deviceConfig.isEmpty()) { restOperations.put(DEVICE_TOKENS_URL + deviceConfig.getDeviceToken(), ""); } else { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<IOSDeviceConfig> requestEntity = new HttpEntity<IOSDeviceConfig>(deviceConfig, headers); restOperations.exchange(DEVICE_TOKENS_URL + deviceConfig.getDeviceToken(), HttpMethod.PUT, requestEntity, String.class); } } RegistrationTemplate(RestOperations restOperations); void registerIOSDevice(IOSDeviceConfig deviceConfig); void registerAndroidDevice(AndroidDeviceConfig deviceConfig); void registerBlackberryDevice(BlackberryDeviceConfig deviceConfig); IOSDevice getIOSDevice(String deviceToken); AndroidDevice getAndroidDevice(String apid); BlackberryDevice getBlackberryDevice(String devicePin); void removeIOSDevice(String deviceToken); void removeAndroidDevice(String apid); void removeBlackberryDevice(String devicePin);  }
@Test public void registeriOSDevice_tokenOnly() { mockServer.expect(requestTo("https: .andExpect(method(PUT)) .andRespond(withResponse("", responseHeaders, HttpStatus.CREATED, "Created")); urbanAirship.registrationOperations().registerIOSDevice(IOSDeviceConfig.builder(DEVICE_TOKEN).build()); mockServer.verify(); }
@Test public void registeriOSDevice_completeConfig() { mockServer.expect(requestTo("https: .andExpect(method(PUT)) .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/registration-complete")))) .andRespond(withResponse("", responseHeaders, HttpStatus.CREATED, "Created")); urbanAirship.registrationOperations().registerIOSDevice(IOSDeviceConfig.builder(DEVICE_TOKEN).alias("myAlias").tags("tag1", "tag2").badge(2).quietTime("22:00", "8:00", "America/Los_Angeles").build()); mockServer.verify(); }
@Test public void registeriOSDevice_aliasOnly() { mockServer.expect(requestTo("https: .andExpect(method(PUT)) .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/registration-aliasonly")))) .andRespond(withResponse("", responseHeaders, HttpStatus.CREATED, "Created")); urbanAirship.registrationOperations().registerIOSDevice(IOSDeviceConfig.builder(DEVICE_TOKEN).alias("myAlias").build()); mockServer.verify(); }
@Test public void registeriOSDevice_tagsOnly() { mockServer.expect(requestTo("https: .andExpect(method(PUT)) .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/registration-tagsonly")))) .andRespond(withResponse("", responseHeaders, HttpStatus.CREATED, "Created")); urbanAirship.registrationOperations().registerIOSDevice(IOSDeviceConfig.builder(DEVICE_TOKEN).tags("tag1", "tag2").build()); mockServer.verify(); }
@Test public void registeriOSDevice_badgeOnly() { mockServer.expect(requestTo("https: .andExpect(method(PUT)) .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/registration-badgeonly")))) .andRespond(withResponse("", responseHeaders, HttpStatus.CREATED, "Created")); urbanAirship.registrationOperations().registerIOSDevice(IOSDeviceConfig.builder(DEVICE_TOKEN).badge(8).build()); mockServer.verify(); }
@Test public void registeriOSDevice_quietTimeOnly() { mockServer.expect(requestTo("https: .andExpect(method(PUT)) .andExpect(header("Content-Type", "application/json")) .andExpect(body(readCompactedJsonResource(jsonResource("data/registration-qtonly")))) .andRespond(withResponse("", responseHeaders, HttpStatus.CREATED, "Created")); urbanAirship.registrationOperations().registerIOSDevice(IOSDeviceConfig.builder(DEVICE_TOKEN).quietTime("22:00", "8:00", "America/Los_Angeles").build()); mockServer.verify(); }