Search in sources :

Example 36 with MessageResult

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());
}
Also used : IssueTrackerIssueCommenter(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCommenter) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueTrackerMessageSender(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) IssueTrackerIssueTransitioner(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueTransitioner) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Serializable(java.io.Serializable) Test(org.junit.jupiter.api.Test) Nullable(org.jetbrains.annotations.Nullable) IssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.IssueTrackerMessageFormatter) IssueTrackerIssueCreator(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerIssueCreator) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IssueTrackerResponse(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerResponse) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) Serializable(java.io.Serializable) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) IssueTrackerResponse(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerResponse) Test(org.junit.jupiter.api.Test)

Example 37 with MessageResult

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()));
}
Also used : JsonObject(com.google.gson.JsonObject) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) ChannelMessageSender(com.synopsys.integration.alert.api.channel.ChannelMessageSender) List(java.util.List) Component(org.springframework.stereotype.Component) SlackChannelKey(com.synopsys.integration.alert.descriptor.api.SlackChannelKey) Map(java.util.Map) Optional(java.util.Optional) HashMap(java.util.HashMap) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult)

Example 38 with MessageResult

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");
}
Also used : MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 39 with MessageResult

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");
}
Also used : ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) MarkupEncoderUtil(com.synopsys.integration.alert.common.util.MarkupEncoderUtil) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)39 Test (org.junit.jupiter.api.Test)25 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)22 List (java.util.List)12 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)11 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)10 UUID (java.util.UUID)9 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)8 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)8 OffsetDateTime (java.time.OffsetDateTime)8 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)7 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)7 IssueTrackerMessageSender (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender)6 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)6 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)6 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)6 IssueTrackerMessageSenderFactory (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory)5 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)5 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)5