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());
}
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());
}
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());
}
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());
}
Aggregations