@Override public String getValue(EndpointProfileDto item) { return BaseEncoding.base64().encode(item.getEndpointKeyHash()); } }, 160);
@Override protected String getObjectId(EndpointProfileDto value) { return BaseEncoding.base64().encode(value.getEndpointKeyHash()); }
@Test public void testRemoveById() throws Exception { EndpointProfileDto expected = generateEndpointProfile(null, null, null, null); endpointProfileDao.removeById(ByteBuffer.wrap(expected.getEndpointKeyHash())); EndpointProfile found = endpointProfileDao.findByKeyHash(expected.getEndpointKeyHash()); Assert.assertNull(found); }
private EndpointProfileDto registerEndpoint(String endpointId, int requestHash, ClientSyncMetaData metaData, ProfileClientSync request) { LOG.debug("[{}][{}] register endpoint. request: {}", endpointId, requestHash, request); byte[] endpointKey = toByteArray(request.getEndpointPublicKey()); byte[] profileBody = toByteArray(request.getProfileBody()); RegisterProfileRequest registerProfileRequest = new RegisterProfileRequest( metaData.getApplicationToken(), endpointKey, metaData.getSdkToken(), profileBody, request.getEndpointAccessToken()); EndpointProfileDto endpointProfile = profileService.registerProfile(registerProfileRequest); LOG.debug("profile registered. id: {}, endpointKeyHash: {}", endpointProfile.getId(), endpointProfile.getEndpointKeyHash()); return endpointProfile; }
@Test public void removeByIdTest() { EndpointProfileDto epDto = generateEndpointProfileDto(null, null); Assert.assertNotNull(epDto); endpointProfileDao.removeById(ByteBuffer.wrap(epDto.getEndpointKeyHash())); MongoEndpointProfile endpointProfile = endpointProfileDao.findById(ByteBuffer.wrap(epDto.getEndpointKeyHash())); Assert.assertNull(endpointProfile); }
@Test public void testRemoveByKeyHash() throws Exception { EndpointProfileDto expected = generateEndpointProfile(null, null, null, null); endpointProfileDao.removeByKeyHash(expected.getEndpointKeyHash()); EndpointProfile found = endpointProfileDao.findByKeyHash(expected.getEndpointKeyHash()); Assert.assertNull(found); }
@Test public void testFindById() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); MongoEndpointProfile profile = endpointProfileDao.findById(ByteBuffer.wrap(endpointProfile.getEndpointKeyHash())); Assert.assertNotNull(profile); }
@Test public void testRemoveByKeyHash() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); endpointProfileDao.removeByKeyHash(endpointProfile.getEndpointKeyHash()); MongoEndpointProfile profile = endpointProfileDao.findByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertNull(profile); }
@Test public void testFindById() throws Exception { EndpointProfileDto expected = generateEndpointProfile(null, null, null, null); EndpointProfile found = endpointProfileDao.findById(ByteBuffer.wrap(expected.getEndpointKeyHash())); Assert.assertEquals(expected, found.toDto()); }
@Test public void findEndpointProfileByKeyHashTest() { String endpointGroupId = "124"; EndpointProfileDto savedEndpointProfileDto = generateEndpointProfileWithGroupIdDto(endpointGroupId); EndpointProfileDto endpointProfileDto = endpointService.findEndpointProfileByKeyHash(savedEndpointProfileDto.getEndpointKeyHash()); Assert.assertEquals(savedEndpointProfileDto, endpointProfileDto); }
@Test public void testSave() throws Exception { EndpointProfileDto endpointProfile = generateEndpointProfile(null, null, null, null); EndpointProfile found = endpointProfileDao.findByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile, found.toDto()); }
@Test public void testRemoveUnicastNotificationsByKeyHash() { TopicDto topicDto = generateTopicDto(null, null); EndpointProfileDto profile = generateEndpointProfileDto(topicDto.getApplicationId(), Arrays.asList(topicDto.getId())); byte[] keyHash = profile.getEndpointKeyHash(); EndpointNotificationDto notification = generateUnicastNotificationDto(null, topicDto.getId(), keyHash); Assert.assertTrue(isNotBlank(notification.getId())); notificationService.removeUnicastNotificationsByKeyHash(keyHash); List<EndpointNotificationDto> notifications = notificationService.findUnicastNotificationsByKeyHash(keyHash); Assert.assertTrue(notifications.isEmpty()); }
@Test public void testSaveServerProfile() throws IOException { ServerProfileSchemaDto schemaDto = generateServerProfileSchema(null, null); EndpointProfileDto ep = generateEndpointProfileDtoWithSchemaVersion(schemaDto.getApplicationId(), schemaDto.getVersion(), null); EndpointProfileDto updated = serverProfileService.saveServerProfile(ep.getEndpointKeyHash(), schemaDto.getVersion(), readSchemaFileAsString(TEST_PROFILE_BODY_PATH)); Assert.assertArrayEquals(ep.getEndpointKeyHash(), updated.getEndpointKeyHash()); Assert.assertNotEquals(ep.getServerProfileBody(), updated.getServerProfileBody()); Assert.assertEquals(ep.getServerProfileVersion(), updated.getServerProfileVersion()); }
@Test public void testFindUnicastNotificationById() { TopicDto topicDto = generateTopicDto(null, null); EndpointProfileDto profile = generateEndpointProfileDto(topicDto.getApplicationId(), Arrays.asList(topicDto.getId())); byte[] keyHash = profile.getEndpointKeyHash(); EndpointNotificationDto notification = generateUnicastNotificationDto(null, topicDto.getId(), keyHash); Assert.assertTrue(isNotBlank(notification.getId())); EndpointNotificationDto found = notificationService.findUnicastNotificationById(notification.getId()); Assert.assertEquals(notification, found); }
@Test public void removeByAppId() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); byte[] keyHash = endpointProfile.getEndpointKeyHash(); endpointProfileDao.removeByAppId(endpointProfile.getApplicationId()); MongoEndpointProfile found = endpointProfileDao.findByKeyHash(keyHash); Assert.assertNull(found); }
@Test public void testFindByKeyHash() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); MongoEndpointProfile found = endpointProfileDao.findByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertNotNull(found); Assert.assertEquals(endpointProfile, found.toDto()); }
@Test public void findBodyByKeyHashTest() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); EndpointProfileBodyDto found = endpointProfileDao.findBodyByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertNotNull(found); Assert.assertEquals(endpointProfile.getClientProfileBody(), found.getClientSideProfile()); Assert.assertEquals(endpointProfile.getServerProfileBody(), found.getServerSideProfile()); }
@Test @Ignore("generateEndpointProfileDtoWithSchemaVersion() updates profile," + " but it shouldn't have existed by the moment, so save must have have been invoked") public void testFindServerProfileSchemaByKeyHash() { ServerProfileSchemaDto schemaDto = generateServerProfileSchema(null, null); EndpointProfileDto ep = generateEndpointProfileDtoWithSchemaVersion(schemaDto.getApplicationId(), schemaDto.getVersion(), null); EndpointProfileDto found = endpointService.findEndpointProfileByKeyHash(ep.getEndpointKeyHash()); ServerProfileSchemaDto foundSchema = serverProfileService.findServerProfileSchemaByAppIdAndVersion(found.getApplicationId(), found.getServerProfileVersion()); Assert.assertEquals(schemaDto, foundSchema); }
@Test public void testFindEndpointIdByKeyHash() throws Exception { EndpointProfileDto endpointProfile = generateEndpointProfile(null, null, null, null); EndpointProfile ep = endpointProfileDao.findEndpointIdByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile.getId(), ep.getId()); Assert.assertNull(endpointProfile.getEndpointKey()); Assert.assertNull(ep.getEndpointKey()); Assert.assertNull(ep.getEndpointUserId()); Assert.assertNull(ep.getSubscriptions()); }
@Test public void testFindEndpointIdByKeyHash() { EndpointProfileDto endpointProfile = generateEndpointProfileDto(null, null); Assert.assertNotNull(endpointProfile); EndpointProfile ep = endpointProfileDao.findEndpointIdByKeyHash(endpointProfile.getEndpointKeyHash()); Assert.assertEquals(endpointProfile.getId(), ep.getId()); Assert.assertNull(endpointProfile.getEndpointKey()); Assert.assertNull(ep.getEndpointKey()); Assert.assertNull(ep.getEndpointUserId()); Assert.assertNull(ep.getSubscriptions()); }