Search in sources :

Example 1 with MarkupEncoderUtil

use of com.synopsys.integration.alert.common.util.MarkupEncoderUtil in project hub-alert by blackducksoftware.

the class SlackDistributionEventHandlerTest method init.

@BeforeEach
public void init() throws IOException {
    MarkupEncoderUtil markupEncoderUtil = new MarkupEncoderUtil();
    SlackChannelMessageFormatter slackChannelMessageFormatter = new SlackChannelMessageFormatter(markupEncoderUtil);
    SlackChannelMessageConverter slackChannelMessageConverter = new SlackChannelMessageConverter(slackChannelMessageFormatter);
    SlackChannelMessageSender slackChannelMessageSender = new SlackChannelMessageSender(ChannelKeys.SLACK, createConnectionFactory());
    SlackChannel slackChannel = new SlackChannel(slackChannelMessageConverter, slackChannelMessageSender);
    mockSlackServer.start();
    String url = mockSlackServer.url("/").toString();
    SlackJobDetailsModel slackJobDetailsModel = new SlackJobDetailsModel(null, url, "channelName", "userName");
    SlackJobDetailsAccessor slackJobDetailsAccessor = jobId -> Optional.of(slackJobDetailsModel);
    distributionEventHandler = new SlackDistributionEventHandler(slackChannel, slackJobDetailsAccessor, processingAuditAccessor);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) DistributionEvent(com.synopsys.integration.alert.processor.api.distribute.DistributionEvent) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) SlackChannelKey(com.synopsys.integration.alert.descriptor.api.SlackChannelKey) Gson(com.google.gson.Gson) MockWebServer(okhttp3.mockwebserver.MockWebServer) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) MockProcessingAuditAccessor(com.synopsys.integration.alert.channel.slack.distribution.mock.MockProcessingAuditAccessor) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) Set(java.util.Set) IOException(java.io.IOException) UUID(java.util.UUID) SlackJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.SlackJobDetailsAccessor) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) Optional(java.util.Optional) MarkupEncoderUtil(com.synopsys.integration.alert.common.util.MarkupEncoderUtil) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) MockResponse(okhttp3.mockwebserver.MockResponse) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) MarkupEncoderUtil(com.synopsys.integration.alert.common.util.MarkupEncoderUtil) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) SlackJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.SlackJobDetailsAccessor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with MarkupEncoderUtil

use of com.synopsys.integration.alert.common.util.MarkupEncoderUtil in project hub-alert by blackducksoftware.

the class SlackChannelTestIT method sendMessageTestIT.

@Test
@Tag(TestTags.DEFAULT_INTEGRATION)
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendMessageTestIT() {
    MarkupEncoderUtil markupEncoderUtil = new MarkupEncoderUtil();
    SlackChannelMessageFormatter slackChannelMessageFormatter = new SlackChannelMessageFormatter(markupEncoderUtil);
    SlackChannelMessageConverter slackChannelMessageConverter = new SlackChannelMessageConverter(slackChannelMessageFormatter);
    ChannelRestConnectionFactory connectionFactory = createConnectionFactory();
    SlackChannelMessageSender slackChannelMessageSender = new SlackChannelMessageSender(ChannelKeys.SLACK, connectionFactory);
    SlackChannel slackChannel = new SlackChannel(slackChannelMessageConverter, slackChannelMessageSender);
    SlackJobDetailsModel distributionDetails = new SlackJobDetailsModel(null, properties.getProperty(TestPropertyKey.TEST_SLACK_WEBHOOK), properties.getProperty(TestPropertyKey.TEST_SLACK_CHANNEL_NAME), properties.getProperty(TestPropertyKey.TEST_SLACK_USERNAME));
    ChannelITTestAssertions.assertSendSimpleMessageSuccess(slackChannel, distributionDetails);
}
Also used : MarkupEncoderUtil(com.synopsys.integration.alert.common.util.MarkupEncoderUtil) ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 3 with MarkupEncoderUtil

use of com.synopsys.integration.alert.common.util.MarkupEncoderUtil 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

ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)3 MarkupEncoderUtil (com.synopsys.integration.alert.common.util.MarkupEncoderUtil)3 Test (org.junit.jupiter.api.Test)3 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)2 Tag (org.junit.jupiter.api.Tag)2 Gson (com.google.gson.Gson)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 MockProcessingAuditAccessor (com.synopsys.integration.alert.channel.slack.distribution.mock.MockProcessingAuditAccessor)1 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)1 SlackJobDetailsAccessor (com.synopsys.integration.alert.common.persistence.accessor.SlackJobDetailsAccessor)1 MSTeamsJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel)1 ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)1 SlackChannelKey (com.synopsys.integration.alert.descriptor.api.SlackChannelKey)1 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)1 DistributionEvent (com.synopsys.integration.alert.processor.api.distribute.DistributionEvent)1 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)1 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)1 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)1 MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)1