Search in sources :

Example 1 with SlackDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity 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);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SlackEvent(com.blackducksoftware.integration.hub.alert.channel.slack.SlackEvent) GlobalChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AbstractChannelEvent(com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) DistributionChannelConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity) SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 2 with SlackDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity in project hub-alert by blackducksoftware.

the class MockSlackEntity method createEntity.

@Override
public SlackDistributionConfigEntity createEntity() {
    final SlackDistributionConfigEntity configEntity = new SlackDistributionConfigEntity(webhook, channelUsername, channelName);
    configEntity.setId(id);
    return configEntity;
}
Also used : SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity)

Example 3 with SlackDistributionConfigEntity

use of com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity 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

SlackDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity)3 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)2 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)2 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)2 Test (org.junit.Test)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)1 SlackEvent (com.blackducksoftware.integration.hub.alert.channel.slack.SlackEvent)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 DistributionChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.distribution.DistributionChannelConfigEntity)1 GlobalChannelConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalChannelConfigEntity)1 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)1 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)1 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)1 Category (org.junit.experimental.categories.Category)1