@Test public void addTopicToEndpointGroup() { 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); endpointGroupDao.addTopicToEndpointGroup(endpointGroup.getId().toString(), first.getId().toString()); endpointGroupDao.addTopicToEndpointGroup(endpointGroup.getId().toString(), second.getId().toString()); EndpointGroup saved = endpointGroupDao.addTopicToEndpointGroup(endpointGroup.getId().toString(), third.getId().toString()); Assert.assertNotNull(saved); Assert.assertEquals(topics, saved.getTopics()); }
@Override @Transactional public UpdateNotificationDto<EndpointGroupDto> addTopicToEndpointGroup(String id, String topicId) { validateSqlId(id, "Can't add topics " + topicId + " to endpoint group . Incorrect endpoint group id." + id); UpdateNotificationDto<EndpointGroupDto> dto = null; EndpointGroup endpointGroup = endpointGroupDao.addTopicToEndpointGroup(id, topicId); if (endpointGroup != null) { dto = new UpdateNotificationDto<>(); HistoryDto history = addHistory(endpointGroup.toDto(), ChangeType.ADD_TOPIC, topicId); if (history != null) { dto.setAppId(history.getApplicationId()); dto.setAppSeqNumber(history.getSequenceNumber()); } dto.setChangeType(ChangeType.ADD_TOPIC); dto.setTopicId(topicId); dto.setGroupId(endpointGroup.getId().toString()); dto.setPayload(endpointGroup.toDto()); } else { LOG.debug("Can't add topic [{}] to endpoint group [{}]", topicId, id); } return dto; }