use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class IssueTrackerChannelTest method distributeMessagesTest.
@Test
public void distributeMessagesTest() throws AlertException {
IssueTrackerModelExtractor<String> modelExtractor = new IssueTrackerModelExtractor<>(createFormatter(), null);
IssueTrackerMessageSender<String> messageSender = createMessageSender();
IssueTrackerProcessor<String> processor = new IssueTrackerProcessor<>(modelExtractor, messageSender);
IssueTrackerProcessorFactory<DistributionJobDetailsModel, String> processorFactory = x -> processor;
IssueTrackerResponsePostProcessor postProcessor = new IssueTrackerResponsePostProcessor() {
@Override
public <T extends Serializable> void postProcess(IssueTrackerResponse<T> response) {
}
};
IssueTrackerChannel<DistributionJobDetailsModel, String> issueTrackerChannel = new IssueTrackerChannel<>(processorFactory, postProcessor) {
};
MessageResult testResult = issueTrackerChannel.distributeMessages(null, ProviderMessageHolder.empty(), null);
IssueTrackerResponse<?> processorResponse = processor.processMessages(ProviderMessageHolder.empty(), "jobName");
assertEquals(processorResponse.getStatusMessage(), testResult.getStatusMessage());
}
use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class SlackChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(SlackJobDetailsModel slackJobDetails, List<SlackChannelMessageModel> channelMessages) throws AlertException {
String webhook = slackJobDetails.getWebhook();
String channelName = slackJobDetails.getChannelName();
String channelUsername = Optional.ofNullable(slackJobDetails.getChannelUsername()).orElse(SLACK_DEFAULT_USERNAME);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> requests = channelMessages.stream().map(channelMessage -> createJsonString(channelMessage.getMarkdownContent(), channelName, channelUsername)).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(requests, slackChannelKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d Slack message(s)", requests.size()));
}
use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class ChannelITTestAssertions method assertSendSimpleMessageSuccess.
public static <D extends DistributionJobDetailsModel> void assertSendSimpleMessageSuccess(DistributionChannel<D> channel, D distributionDetails) {
MessageResult messageResult = null;
try {
messageResult = channel.distributeMessages(distributionDetails, TEST_MESSAGE_HOLDER, "jobName");
} catch (AlertException e) {
Assertions.fail("Failed to distribute simple channel message due to an exception", e);
}
assertFalse(messageResult.hasErrors(), "The message result had errors");
assertFalse(messageResult.hasWarnings(), "The message result had warnings");
}
use of com.synopsys.integration.alert.common.message.model.MessageResult in project hub-alert by blackducksoftware.
the class MsTeamsChannelTest method sendMessageTestIT.
@Test
@Tag(TestTags.DEFAULT_INTEGRATION)
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendMessageTestIT() {
ChannelRestConnectionFactory connectionFactory = createConnectionFactory();
MarkupEncoderUtil markupEncoderUtil = new MarkupEncoderUtil();
MSTeamsChannelMessageConverter messageConverter = new MSTeamsChannelMessageConverter(new MSTeamsChannelMessageFormatter(markupEncoderUtil));
MSTeamsChannelMessageSender messageSender = new MSTeamsChannelMessageSender(ChannelKeys.MS_TEAMS, connectionFactory);
MSTeamsChannel msTeamsChannel = new MSTeamsChannel(messageConverter, messageSender);
MSTeamsJobDetailsModel msTeamsJobDetailsModel = new MSTeamsJobDetailsModel(UUID.randomUUID(), properties.getProperty(TestPropertyKey.TEST_MSTEAMS_WEBHOOK));
MessageResult messageResult = null;
try {
messageResult = msTeamsChannel.distributeMessages(msTeamsJobDetailsModel, TEST_MESSAGE_HOLDER, "jobName");
} catch (AlertException e) {
Assertions.fail("Failed to distribute simple channel message due to an exception", e);
}
Assertions.assertFalse(messageResult.hasErrors(), "The message result had errors");
Assertions.assertFalse(messageResult.hasWarnings(), "The message result had warnings");
}
Aggregations