use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class HipChatChannelTest method sendMessageTestIT.
@Test
@Category(ExternalConnectionTest.class)
public void sendMessageTestIT() throws IOException, IntegrationException {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository, null);
final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
HipChatChannel hipChatChannel = new HipChatChannel(gson, auditEntryRepository, null, null, null, channelRestConnectionFactory);
final ProjectData data = createProjectData("Integration test project");
final HipChatEvent event = new HipChatEvent(data, null);
final int roomId = Integer.parseInt(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_ROOM_ID));
final boolean notify = false;
final String color = "random";
final HipChatDistributionConfigEntity config = new HipChatDistributionConfigEntity(roomId, notify, color);
hipChatChannel = Mockito.spy(hipChatChannel);
Mockito.doReturn(new GlobalHipChatConfigEntity(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_API_KEY))).when(hipChatChannel).getGlobalConfigEntity();
hipChatChannel.sendAuditedMessage(event, config);
final boolean responseLine = outputLogger.isLineContainingText("Successfully sent a hipchat_channel message!");
assertTrue(responseLine);
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class RestDistributionChannelTest method sendMessageFailureTest.
@Test
public void sendMessageFailureTest() {
final GlobalProperties globalProperties = new TestGlobalProperties();
final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
final RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity> restChannel = new RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity>(null, null, null, null, null, null, channelRestConnectionFactory) {
@Override
public String getApiUrl() {
return null;
}
@Override
public Request createRequest(final ChannelRequestHelper channelRequestHelper, final DistributionChannelConfigEntity config, final ProjectData projectData) throws AlertException {
return new Request.Builder().uri("http://google.com").build();
}
};
final SlackEvent event = new SlackEvent(createProjectData("Rest channel test"), 1L);
final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity("more garbage", "garbage", "garbage");
Exception thrownException = null;
try {
restChannel.sendAuditedMessage(event, config);
} catch (final IntegrationException ex) {
thrownException = ex;
}
assertNotNull(thrownException);
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class NotificationPostProcessorTestIT method getApplicableConfigurationsTest.
@Test
public void getApplicableConfigurationsTest() {
final NotificationPostProcessor postProcessor = new NotificationPostProcessor(distributionProjectRepository, configuredProjectsRepository, distributionNotificationTypeRepository, notificationTypeRepository);
final DigestTypeEnum digestType = DigestTypeEnum.REAL_TIME;
final String projectName = "Project Name";
final String projectVersion = "Project Version";
final List<Long> notificationIds = Collections.emptyList();
final Map<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
for (final NotificationCategoryEnum categoryEnum : NotificationCategoryEnum.values()) {
categoryMap.put(categoryEnum, new CategoryData(null, null, 0));
notificationTypeRepository.save(new NotificationTypeEntity(categoryEnum));
}
final ProjectData projectData = new ProjectData(digestType, projectName, projectVersion, notificationIds, categoryMap);
final Long config1Id = 13L;
final CommonDistributionConfigEntity config1 = new CommonDistributionConfigEntity(config1Id, SupportedChannels.EMAIL_GROUP, "Config 1", digestType, true);
config1.setId(config1Id);
final Long config2Id = 17L;
final CommonDistributionConfigEntity config2 = new CommonDistributionConfigEntity(config2Id, SupportedChannels.EMAIL_GROUP, "Config 2", digestType, false);
config2.setId(config2Id);
final Long notificationTypeId = notificationTypeRepository.findAll().get(0).getId();
distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config1.getId(), notificationTypeId));
distributionNotificationTypeRepository.save(new DistributionNotificationTypeRelation(config2.getId(), notificationTypeId));
final ConfiguredProjectEntity configuredProjectEntity = configuredProjectsRepository.save(new ConfiguredProjectEntity(projectName));
distributionProjectRepository.save(new DistributionProjectRelation(config1.getId(), configuredProjectEntity.getId()));
final Set<CommonDistributionConfigEntity> applicableConfigs = postProcessor.getApplicableConfigurations(Arrays.asList(config1, config2), projectData);
assertTrue(applicableConfigs.contains(config1));
assertTrue(applicableConfigs.contains(config2));
assertEquals(2, applicableConfigs.size());
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class NotificationPostProcessorTestIT method isApplicableTest.
@Test
public void isApplicableTest() {
final DistributionNotificationTypeRepositoryWrapper distributionNotificationTypeRepository = Mockito.mock(DistributionNotificationTypeRepositoryWrapper.class);
final NotificationPostProcessor postProcessor = new NotificationPostProcessor(distributionProjectRepository, configuredProjectsRepository, distributionNotificationTypeRepository, notificationTypeRepository);
Mockito.when(distributionNotificationTypeRepository.findByCommonDistributionConfigId(Mockito.anyLong())).thenReturn(Collections.emptyList());
final ProjectData projectData = new ProjectData(null, null, null, null, null);
final CommonDistributionConfigEntity config = new CommonDistributionConfigEntity(13L, SupportedChannels.EMAIL_GROUP, "Config 1", DigestTypeEnum.DAILY, true);
config.setId(13L);
assertFalse(postProcessor.isApplicable(config, projectData));
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class NotificationPostProcessorTestIT method doFrequenciesMatchTest.
@Test
public void doFrequenciesMatchTest() {
final NotificationPostProcessor postProcessor = new NotificationPostProcessor(distributionProjectRepository, configuredProjectsRepository, distributionNotificationTypeRepository, notificationTypeRepository);
final DigestTypeEnum digestType = DigestTypeEnum.DAILY;
final CommonDistributionConfigEntity config = new CommonDistributionConfigEntity(13L, SupportedChannels.EMAIL_GROUP, "Config 1", digestType, true);
final CommonDistributionConfigEntity configOther = new CommonDistributionConfigEntity(13L, SupportedChannels.EMAIL_GROUP, "Config 2", null, false);
final ProjectData projectDataMatching = new ProjectData(digestType, null, null, null, null);
final ProjectData projectDataOther = new ProjectData(DigestTypeEnum.REAL_TIME, null, null, null, null);
assertTrue(postProcessor.doFrequenciesMatch(config, projectDataMatching));
assertFalse(postProcessor.doFrequenciesMatch(config, projectDataOther));
assertFalse(postProcessor.doFrequenciesMatch(configOther, projectDataOther));
}
Aggregations