@Override public TopicDto editTopic(TopicDto topic) throws ControlServiceException { return topicService.saveTopic(topic); }
@Override public TopicDto getTopic(String topicId) throws ControlServiceException { return topicService.findTopicById(topicId); }
@Override public List<TopicDto> getTopicByAppId(String appId) throws ControlServiceException { return topicService.findTopicsByAppId(appId); }
@Test public void removeTopicByIdTest() { TopicDto topic = generateTopicDto(null, null); topicService.removeTopicById(topic.getId()); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertNull(found); List<EndpointGroupDto> groups = endpointService.findEndpointGroupsByAppId(topic.getApplicationId()); Assert.assertFalse(groups.isEmpty()); }
@Test public void removeTopicsByAppIdTest() { TopicDto topic = generateTopicDto(null, null); topicService.removeTopicsByAppId(topic.getApplicationId()); List<TopicDto> found = topicService.findTopicsByAppId(topic.getApplicationId()); Assert.assertNotNull(found); Assert.assertTrue(found.isEmpty()); }
@Override public List<TopicDto> getTopicByEndpointGroupId(String endpointGroupId) throws ControlServiceException { return topicService.findTopicsByEndpointGroupId(endpointGroupId); }
@Override public List<TopicDto> getVacantTopicByEndpointGroupId(String endpointGroupId) throws ControlServiceException { return topicService.findVacantTopicsByEndpointGroupId(endpointGroupId); }
@Override public void deleteTopicById(String topicId) throws ControlServiceException { for (UpdateNotificationDto<EndpointGroupDto> dto : topicService.removeTopicById(topicId)) { notifyAndGetPayload(dto); } }
@Test public void findTopicsByAppIdAndTypeTest() { TopicDto topic = generateTopicDto(null, TopicTypeDto.OPTIONAL); List<TopicDto> found = topicService.findTopicsByAppIdAndType(topic.getApplicationId(), TopicTypeDto.OPTIONAL); Assert.assertEquals(1, found.size()); Assert.assertEquals(topic, found.get(0)); }
@Test public void removeTopicByIdAddedToGroupTest() { TopicDto topic = generateTopicDto(null, null); EndpointGroupDto groupDto = generateEndpointGroupDto(topic.getApplicationId()); endpointService.addTopicToEndpointGroup(groupDto.getId(), topic.getId()); topicService.removeTopicById(topic.getId()); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertNull(found); }
@Test public void testFindTopicsByEndpointGroupId() { ApplicationDto app = generateApplicationDto(); EndpointGroupDto group = generateEndpointGroupDto(app.getId()); TopicDto topic = generateTopicDto(app.getId(), null); endpointService.addTopicToEndpointGroup(group.getId(), topic.getId()); List<TopicDto> found = topicService.findTopicsByEndpointGroupId(group.getId()); Assert.assertEquals(topic, found.get(0)); } }
@Test public void testFindVacantTopicsByEndpointGroupId() { ApplicationDto app = generateApplicationDto(); EndpointGroupDto group = generateEndpointGroupDto(app.getId()); TopicDto topic = generateTopicDto(app.getId(), null); List<TopicDto> found = topicService.findVacantTopicsByEndpointGroupId(group.getId()); Assert.assertEquals(topic, found.get(0)); }
@Test(expected = IllegalArgumentException.class) public void saveTopicTest() { ApplicationDto app = generateApplicationDto(); TopicDto topic1 = generateTopicDto(app.getId(), TopicTypeDto.MANDATORY); topicService.saveTopic(topic1); TopicDto topic2 = generateTopicDto(app.getId(), TopicTypeDto.OPTIONAL); topicService.saveTopic(topic2); }
@Override public TopicDto compute(String key) { LOG.debug("Fetching result for token id"); TopicDto topicDto = topicService.findTopicById(key); return topicDto; } });
@Test public void findTopicsByAppIdTest() { TopicDto topic = generateTopicDto(null, null); List<TopicDto> found = topicService.findTopicsByAppId(topic.getApplicationId()); Assert.assertEquals(1, found.size()); Assert.assertEquals(topic, found.get(0)); }
protected TopicDto generateTopicDto(String appId, TopicTypeDto type) { TopicDto topic = new TopicDto(); topic.setName(TOPIC_NAME); if (isBlank(appId)) { appId = generateApplicationDto().getId(); } topic.setApplicationId(appId); if (type == null) { type = TopicTypeDto.MANDATORY; } topic.setType(type); return topicService.saveTopic(topic); }
@Test public void findTopicByIdTest() { TopicDto topic = generateTopicDto(null, null); TopicDto found = topicService.findTopicById(topic.getId()); Assert.assertEquals(topic, found); }
topicDto.setType(TopicTypeDto.MANDATORY); topicDto = topicService.saveTopic(topicDto);