Search in sources :

Example 11 with ProjectData

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);
}
Also used : CommonDistributionConfigRestModel(com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) Test(org.junit.Test)

Example 12 with ProjectData

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());
}
Also used : Request(com.blackducksoftware.integration.hub.request.Request) ChannelRequestHelper(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper) HashMap(java.util.HashMap) Map(java.util.Map) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) MockSlackEntity(com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 13 with ProjectData

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;
}
Also used : CategoryData(com.blackducksoftware.integration.hub.alert.digest.model.CategoryData) HashMap(java.util.HashMap) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)

Example 14 with 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());
}
Also used : Request(com.blackducksoftware.integration.hub.request.Request) ChannelRequestHelper(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper) HashMap(java.util.HashMap) Map(java.util.Map) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) MockSlackEntity(com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 15 with ProjectData

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);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Category(org.junit.experimental.categories.Category) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Aggregations

ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)19 Test (org.junit.Test)14 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)7 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)6 HashMap (java.util.HashMap)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)5 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)4 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)4 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)4 ChannelRequestHelper (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper)3 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)3 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)3 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)3 CategoryData (com.blackducksoftware.integration.hub.alert.digest.model.CategoryData)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)2 HipChatDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity)2 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)2 MockSlackEntity (com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity)2