Search in sources :

Example 1 with SlackJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel in project hub-alert by blackducksoftware.

the class StaticJobAccessor method convertToDistributionJobModel.

@Deprecated
private DistributionJobModel convertToDistributionJobModel(DistributionJobEntity jobEntity) {
    UUID jobId = jobEntity.getJobId();
    DistributionJobDetailsModel distributionJobDetailsModel = null;
    ChannelKey channelKey = ChannelKeys.getChannelKey(jobEntity.getChannelDescriptorName());
    if (ChannelKeys.AZURE_BOARDS.equals(channelKey)) {
        AzureBoardsJobDetailsEntity jobDetails = jobEntity.getAzureBoardsJobDetails();
        distributionJobDetailsModel = new AzureBoardsJobDetailsModel(jobId, jobDetails.getAddComments(), jobDetails.getProjectNameOrId(), jobDetails.getWorkItemType(), jobDetails.getWorkItemCompletedState(), jobDetails.getWorkItemReopenState());
    } else if (ChannelKeys.JIRA_CLOUD.equals(channelKey)) {
        JiraCloudJobDetailsEntity jobDetails = jobEntity.getJiraCloudJobDetails();
        List<JiraJobCustomFieldModel> customFields = jobDetails.getJobCustomFields().stream().map(entity -> new JiraJobCustomFieldModel(entity.getFieldName(), entity.getFieldValue())).collect(Collectors.toList());
        distributionJobDetailsModel = new JiraCloudJobDetailsModel(jobId, jobDetails.getAddComments(), jobDetails.getIssueCreatorEmail(), jobDetails.getProjectNameOrKey(), jobDetails.getIssueType(), jobDetails.getResolveTransition(), jobDetails.getReopenTransition(), customFields, jobDetails.getIssueSummary());
    } else if (ChannelKeys.MS_TEAMS.equals(channelKey)) {
        MSTeamsJobDetailsEntity jobDetails = jobEntity.getMsTeamsJobDetails();
        distributionJobDetailsModel = new MSTeamsJobDetailsModel(jobId, jobDetails.getWebhook());
    } else if (ChannelKeys.SLACK.equals(channelKey)) {
        SlackJobDetailsEntity slackJobDetails = jobEntity.getSlackJobDetails();
        distributionJobDetailsModel = new SlackJobDetailsModel(jobId, slackJobDetails.getWebhook(), slackJobDetails.getChannelName(), slackJobDetails.getChannelUsername());
    }
    return convertToDistributionJobModel(jobEntity, distributionJobDetailsModel);
}
Also used : MSTeamsJobDetailsEntity(com.synopsys.integration.alert.database.job.msteams.MSTeamsJobDetailsEntity) AzureBoardsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.AzureBoardsJobDetailsModel) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) JiraCloudJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraCloudJobDetailsModel) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraCloudJobDetailsEntity(com.synopsys.integration.alert.database.job.jira.cloud.JiraCloudJobDetailsEntity) AzureBoardsJobDetailsEntity(com.synopsys.integration.alert.database.job.azure.boards.AzureBoardsJobDetailsEntity) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) List(java.util.List) MSTeamsJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.MSTeamsJobDetailsModel) UUID(java.util.UUID) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)

Example 2 with SlackJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel 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 3 with SlackJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel in project hub-alert by blackducksoftware.

the class StaticJobAccessorTestIT method verifySlackSavesTest.

@Test
public void verifySlackSavesTest() {
    SlackJobDetailsModel slackJobDetailsModel = new SlackJobDetailsModel(UUID.randomUUID(), "webhook", "channelName", "channelUsername");
    DistributionJobRequestModel jobRequestModel = createJobRequestModel(slackJobDetailsModel, new SlackChannelKey());
    createAndAssertJob(jobRequestModel);
}
Also used : SlackChannelKey(com.synopsys.integration.alert.descriptor.api.SlackChannelKey) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with SlackJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createJobTest.

@Test
void createJobTest() {
    UUID jobId = UUID.randomUUID();
    SlackJobDetailsModel slackJobDetailsModel = new SlackJobDetailsModel(jobId, null, null, null);
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.SLACK.getUniversalKey(), slackJobDetailsModel);
    SlackJobDetailsEntity slackJobDetailsEntity = new SlackJobDetailsEntity();
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setSlackJobDetails(slackJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(slackJobDetailsAccessor.saveSlackJobDetails(Mockito.any(), Mockito.any())).thenReturn(slackJobDetailsEntity);
    Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
    DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
    assertEquals(jobId, createdJob.getJobId());
    assertEquals(jobName, createdJob.getName());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 5 with SlackJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel 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)

Aggregations

SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)10 Test (org.junit.jupiter.api.Test)7 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)6 UUID (java.util.UUID)4 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)3 SlackJobDetailsEntity (com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity)3 SlackChannelKey (com.synopsys.integration.alert.descriptor.api.SlackChannelKey)3 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)3 List (java.util.List)3 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 MarkupEncoderUtil (com.synopsys.integration.alert.common.util.MarkupEncoderUtil)2 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)2 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 ChannelMessageSender (com.synopsys.integration.alert.api.channel.ChannelMessageSender)1 RestChannelUtility (com.synopsys.integration.alert.api.channel.rest.RestChannelUtility)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 MockProcessingAuditAccessor (com.synopsys.integration.alert.channel.slack.distribution.mock.MockProcessingAuditAccessor)1