Search in sources :

Example 1 with MockSlackEntity

use of com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity in project hub-alert by blackducksoftware.

the class SlackChannelTestIT method testCreateRequestExceptions.

@Test
public void testCreateRequestExceptions() {
    final SlackChannel slackChannel = new SlackChannel(gson, null, null, null, null);
    final MockSlackEntity mockSlackEntity = new MockSlackEntity();
    Request request = null;
    try {
        request = slackChannel.createRequest(null, mockSlackEntity.createEmptyEntity(), null);
        fail();
    } catch (final IntegrationException e) {
        assertNull(request);
    }
    mockSlackEntity.setChannelName("");
    try {
        request = slackChannel.createRequest(null, mockSlackEntity.createEntity(), null);
        fail();
    } catch (final IntegrationException e) {
        assertNull(request);
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Request(com.blackducksoftware.integration.hub.request.Request) 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 2 with MockSlackEntity

use of com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity 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 3 with MockSlackEntity

use of com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity 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)

Aggregations

ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)3 MockSlackEntity (com.blackducksoftware.integration.hub.alert.channel.slack.mock.MockSlackEntity)3 Request (com.blackducksoftware.integration.hub.request.Request)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 Test (org.junit.Test)3 ChannelRequestHelper (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRequestHelper)2 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1