@Override public EndpointNotificationDto findUnicastNotificationById(String id) { validateId(id, "Can't find unicast notification. Invalid id " + id); return getDto(unicastNotificationDao.findById(id)); }
@Override public List<EndpointNotificationDto> findUnicastNotificationsByKeyHash(final byte[] keyHash) { validateHash(keyHash, "Can't find unicast notification. Invalid key hash " + keyHash); return convertDtoList(unicastNotificationDao.findNotificationsByKeyHash(keyHash)); }
@Override public void removeNotificationSchemasByAppId(String appId) { validateId(appId, "Can't remove notification schemas. Invalid application id: " + appId); LOG.debug("Cascade remove corresponding notification to application id [{}]", appId); unicastNotificationDao.removeNotificationsByAppId(appId); notificationSchemaDao.removeNotificationSchemasByAppId(appId); }
@Test public void testRemoveNotificationsByKeyHash() throws Exception { ByteBuffer epKeyHash = ByteBuffer.wrap(generateBytes()); generateEndpointNotification(epKeyHash, 3); unicastNotificationDao.removeNotificationsByKeyHash(epKeyHash.array()); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(epKeyHash.array()); Assert.assertTrue(found.isEmpty()); }
@Test public void testRemoveNotificationsByAppId() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 3).get(0); String appId = notification.getApplicationId(); unicastNotificationDao.removeNotificationsByAppId(appId); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertTrue(found.isEmpty()); }
@Test public void testFindById() { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); CassandraEndpointNotification saved = unicastNotificationDao.save(notification.toDto()); Assert.assertNotNull(saved.getId()); CassandraEndpointNotification found = unicastNotificationDao.findById(saved.getId()); Assert.assertEquals(saved, found); } }
protected List<CassandraEndpointNotification> generateEndpointNotification(ByteBuffer endpointKeyHash, int count) { List<CassandraEndpointNotification> savedNotifications = new ArrayList<>(); String appId = generateStringId(); if (endpointKeyHash == null) { endpointKeyHash = ByteBuffer.wrap(generateEndpointProfile(appId, null, null, null).getEndpointKeyHash()); } String schemaId = generateStringId(); for (int i = 0; i < count; i++) { CassandraEndpointNotification endpointNotification = new CassandraEndpointNotification(); endpointNotification.setEndpointKeyHash(endpointKeyHash); endpointNotification.setApplicationId(appId); endpointNotification.setSchemaId(schemaId); endpointNotification.setType(NotificationTypeDto.USER); endpointNotification.setSeqNum(100 + i); endpointNotification.setLastModifyTime(new Date(System.currentTimeMillis())); savedNotifications.add(unicastNotificationDao.save(endpointNotification)); } return savedNotifications; }
@Override public void removeUnicastNotificationsByKeyHash(final byte[] keyHash) { validateHash(keyHash, "Can't remove unicast notification. Invalid key hash " + keyHash); unicastNotificationDao.removeNotificationsByKeyHash(keyHash); }
@Override public void removeUnicastNotificationById(String id) { validateId(id, "Can't remove unicast notification. Invalid id " + id); unicastNotificationDao.removeById(id); }
notificationDto.setLastTimeModify(new Date(currentTime)); EndpointNotificationDto unicast = getDto(unicastNotificationDao.save(dto)); if (unicast != null && unicast.getNotificationDto() != null) { LOG.trace("Saved unicast notifications {}", unicast);
@Test public void testSave() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertEquals(1, found.size()); }
@Test public void testFindNotificationsByKeyHash() throws Exception { List<CassandraEndpointNotification> notifications = generateEndpointNotification(null, 1); generateEndpointNotification(null, 2); CassandraEndpointNotification notification = notifications.get(0); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertEquals(notifications.size(), found.size()); }