use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class ChannelEventFactoryTest method createEventWithChannelManagerTest.
@Test
public void createEventWithChannelManagerTest() {
final DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel> manager = Mockito.mock(DistributionChannelManager.class);
final List<DistributionChannelManager<GlobalChannelConfigEntity, DistributionChannelConfigEntity, AbstractChannelEvent, CommonDistributionConfigRestModel>> managers = Arrays.asList(manager);
final ChannelEventFactory<AbstractChannelEvent, DistributionChannelConfigEntity, GlobalChannelConfigEntity, CommonDistributionConfigRestModel> factory = new ChannelEventFactory<>(managers);
final Long id = 25L;
final ProjectData projectData = new ProjectData(DigestTypeEnum.REAL_TIME, "Project Name", "Project Version", Collections.emptyList(), Collections.emptyMap());
final AbstractChannelEvent mockEvent = new AbstractChannelEvent(projectData, id) {
@Override
public String getTopic() {
return DISTRIBUTION_TYPE;
}
};
Mockito.when(manager.isApplicable(DISTRIBUTION_TYPE)).thenReturn(true);
Mockito.when(manager.createChannelEvent(Mockito.any(), Mockito.anyLong())).thenReturn(mockEvent);
final AbstractChannelEvent event = factory.createEvent(id, "TYPE", projectData);
assertEquals(mockEvent, event);
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class SlackChannelTestIT method testCreateHtmlMessage.
@SuppressWarnings("unchecked")
@Test
public void testCreateHtmlMessage() throws IntegrationException {
final SlackChannel slackChannel = new SlackChannel(gson, null, null, null, null);
final MockSlackEntity mockSlackEntity = new MockSlackEntity();
final ProjectData projectData = createSlackProjectData();
final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(null) {
@Override
public Request createPostMessageRequest(final String url, final Map<String, String> headers, final String body) {
assertTrue(body.contains("Vulnerability Count Added: "));
assertTrue(body.contains("Vulnerability Count Updated: "));
assertTrue(body.contains("Vulnerability Count Deleted: "));
return null;
}
};
final ChannelRequestHelper spyChannelRequestHelper = Mockito.spy(channelRequestHelper);
final Request request = slackChannel.createRequest(spyChannelRequestHelper, mockSlackEntity.createEntity(), projectData);
assertNull(request);
Mockito.verify(spyChannelRequestHelper).createPostMessageRequest(Mockito.anyString(), Mockito.anyMap(), Mockito.anyString());
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class SlackChannelTestIT method createSlackProjectData.
private ProjectData createSlackProjectData() {
final Map<NotificationCategoryEnum, CategoryData> categoryMap = new HashMap<>();
categoryMap.put(NotificationCategoryEnum.HIGH_VULNERABILITY, createCategoryData());
final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "Slack", "1", null, categoryMap);
return projectData;
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class SlackChannelTestIT method testCreateHtmlMessageEmpty.
@Test
@SuppressWarnings("unchecked")
public void testCreateHtmlMessageEmpty() throws IntegrationException {
final SlackChannel slackChannel = new SlackChannel(gson, null, null, null, null);
final MockSlackEntity mockSlackEntity = new MockSlackEntity();
final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "Slack", "1", null, null);
final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(null) {
@Override
public Request createPostMessageRequest(final String url, final Map<String, String> headers, final String body) {
assertTrue(body.contains("A notification was received, but it was empty."));
return null;
}
};
final ChannelRequestHelper spyChannelRequestHelper = Mockito.spy(channelRequestHelper);
final Request request = slackChannel.createRequest(spyChannelRequestHelper, mockSlackEntity.createEntity(), projectData);
assertNull(request);
Mockito.verify(spyChannelRequestHelper).createPostMessageRequest(Mockito.anyString(), Mockito.anyMap(), Mockito.anyString());
}
use of com.blackducksoftware.integration.hub.alert.digest.model.ProjectData in project hub-alert by blackducksoftware.
the class SlackChannelTestIT 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);
final SlackChannel slackChannel = new SlackChannel(gson, auditEntryRepository, null, null, channelRestConnectionFactory);
final String roomName = properties.getProperty(TestPropertyKey.TEST_SLACK_CHANNEL_NAME);
final String username = properties.getProperty(TestPropertyKey.TEST_SLACK_USERNAME);
final String webHook = properties.getProperty(TestPropertyKey.TEST_SLACK_WEBHOOK);
final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity(webHook, username, roomName);
final ProjectData projectData = createProjectData("Slack test project");
final SlackEvent event = new SlackEvent(projectData, new Long(0));
slackChannel.sendAuditedMessage(event, config);
final boolean actual = outputLogger.isLineContainingText("Successfully sent a slack_channel message!");
assertTrue(actual);
}
Aggregations