@Test public void removeTopicFromEndpointGroup() { Topic first = generateTopic(null, null, "first"); Topic second = generateTopic(first.getApplication(), null, "second"); Topic third = generateTopic(first.getApplication(), null, "third"); Set<Topic> topics = new HashSet<>(); topics.add(first); topics.add(second); topics.add(third); EndpointGroup endpointGroup = generateEndpointGroup(first.getApplication(), topics); Assert.assertEquals(3, endpointGroup.getTopics().size()); endpointGroupDao.removeTopicFromEndpointGroup(endpointGroup.getId().toString(), first.getId().toString()); EndpointGroup group = endpointGroupDao.removeTopicFromEndpointGroup(endpointGroup.getId().toString(), second.getId().toString()); Set<Topic> expected = new HashSet<>(); expected.add(third); Assert.assertEquals(expected, group.getTopics()); }
@Override @Transactional public UpdateNotificationDto<EndpointGroupDto> removeTopicFromEndpointGroup(String id, String topicId) { validateSqlId(id, "Can't remove endpoint group topics " + topicId + ". Incorrect endpoint group id." + id); UpdateNotificationDto<EndpointGroupDto> dto = null; EndpointGroup endpointGroup = endpointGroupDao.removeTopicFromEndpointGroup(id, topicId); if (endpointGroup != null) { dto = new UpdateNotificationDto<>(); HistoryDto history = addHistory(endpointGroup.toDto(), ChangeType.REMOVE_TOPIC, topicId); if (history != null) { dto.setAppId(history.getApplicationId()); dto.setAppSeqNumber(history.getSequenceNumber()); } dto.setChangeType(ChangeType.REMOVE_TOPIC); dto.setTopicId(topicId); dto.setGroupId(endpointGroup.getId().toString()); dto.setPayload(endpointGroup.toDto()); } else { LOG.debug("Can't remove topic [{}] from endpoint group [{}]", topicId, id); } return dto; }