Search in sources :

Example 6 with Request

use of com.blackducksoftware.integration.hub.request.Request 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 7 with Request

use of com.blackducksoftware.integration.hub.request.Request 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 8 with Request

use of com.blackducksoftware.integration.hub.request.Request in project hub-alert by blackducksoftware.

the class ChannelRequestHelperTest method testCreateMessageRequest.

@Test
public void testCreateMessageRequest() throws Exception {
    final Request request = createRequest();
    final RestConnection restConnection = Mockito.mock(RestConnection.class);
    final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(restConnection);
    final Request returnedRequest = channelRequestHelper.createPostMessageRequest("https://google.com", null, "{}");
    assertEquals(request.getUri(), returnedRequest.getUri());
    assertEquals(request.getMethod(), returnedRequest.getMethod());
    assertEquals(request.getMimeType(), returnedRequest.getMimeType());
    assertEquals(request.getQueryParameters(), returnedRequest.getQueryParameters());
    assertEquals(request.getAdditionalHeaders(), returnedRequest.getAdditionalHeaders());
    assertEquals(request.getBodyEncoding(), returnedRequest.getBodyEncoding());
    assertEquals(request.getBodyContent().getBodyContent(), returnedRequest.getBodyContent().getBodyContent());
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) Request(com.blackducksoftware.integration.hub.request.Request) Test(org.junit.Test)

Example 9 with Request

use of com.blackducksoftware.integration.hub.request.Request in project hub-alert by blackducksoftware.

the class RestDistributionChannel method sendMessage.

@Override
public void sendMessage(final E event, final C config) throws Exception {
    final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection(getApiUrl());
    final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(restConnection);
    final Request request = createRequest(channelRequestHelper, config, event.getProjectData());
    channelRequestHelper.sendMessageRequest(request, event.getTopic());
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) Request(com.blackducksoftware.integration.hub.request.Request)

Aggregations

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