Search in sources :

Example 6 with IssueTrackerModelHolder

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder in project hub-alert by blackducksoftware.

the class JiraCloudSummaryFieldLengthTestIT method summaryLength256FailsTest.

@Test
public void summaryLength256FailsTest() {
    IssueCreationModel issueCreationModel = createIssueCreationModel(256);
    IssueTrackerModelHolder<String> messages = new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
    try {
        jiraCloudMessageSender.sendMessages(messages);
        fail("Successfully sent a message with a 256 character summary which is greater than the expected maximum");
    } catch (AlertException e) {
        // Pass
        e.printStackTrace();
    }
}
Also used : IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 7 with IssueTrackerModelHolder

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder in project hub-alert by blackducksoftware.

the class JiraServerSummaryFieldLengthTestIT method summaryLength256FailsTest.

@Test
public void summaryLength256FailsTest() {
    IssueCreationModel issueCreationModel = createIssueCreationModel(256);
    IssueTrackerModelHolder<String> messages = new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
    try {
        jiraServerMessageSender.sendMessages(messages);
        fail("Successfully sent a message with a 256 character summary which is greater than the expected maximum");
    } catch (AlertException e) {
        // Pass
        e.printStackTrace();
    }
}
Also used : IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 8 with IssueTrackerModelHolder

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder in project hub-alert by blackducksoftware.

the class IssueTrackerTestAction method testConfig.

@Override
public MessageResult testConfig(DistributionJobModel testJobModel, String jobName, @Nullable String customTopic, @Nullable String customMessage) throws AlertException {
    D distributionDetails = (D) testJobModel.getDistributionJobDetails();
    IssueTrackerMessageSender<T> messageSender = messageSenderFactory.createMessageSender(distributionDetails);
    String topicString = Optional.ofNullable(customTopic).orElse("Alert Test Topic");
    String messageString = Optional.ofNullable(customMessage).orElse("Alert Test Message");
    // TODO determine if source should be required everywhere
    ProjectIssueModel testProjectIssueModel = createPlaceholderProjectIssueModel(testJobModel.getBlackDuckGlobalConfigId());
    String postCreateComment = String.format("Created by [ Test Configuration ] in the Alert Distribution Job: %s", testJobModel.getName());
    IssueCreationModel creationRequest = IssueCreationModel.simple(topicString, messageString, List.of(postCreateComment), testProjectIssueModel.getProvider());
    IssueTrackerModelHolder<T> creationRequestModelHolder = new IssueTrackerModelHolder<>(List.of(creationRequest), List.of(), List.of());
    IssueTrackerTestActionFieldStatusCreator fieldStatusCreator = new IssueTrackerTestActionFieldStatusCreator();
    List<IssueTrackerIssueResponseModel<T>> createdIssues;
    try {
        createdIssues = messageSender.sendMessages(creationRequestModelHolder);
    } catch (AlertFieldException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), e.getFieldErrors());
    } catch (AlertException e) {
        logger.error("Failed to create test issue", e);
        return new MessageResult("Failed to create issue: " + e.getMessage(), fieldStatusCreator.createWithoutField(e.getMessage()));
    }
    int createdIssuesSize = createdIssues.size();
    if (createdIssuesSize != 1) {
        String errorMessage = String.format("Expected [1] issue to be created, but there were actually [%d]", createdIssuesSize);
        return new MessageResult(errorMessage, fieldStatusCreator.createWithoutField(errorMessage));
    }
    IssueTrackerIssueResponseModel<T> createdIssue = createdIssues.get(0);
    ExistingIssueDetails<T> existingIssueDetails = new ExistingIssueDetails<>(createdIssue.getIssueId(), createdIssue.getIssueKey(), createdIssue.getIssueTitle(), createdIssue.getIssueLink(), IssueStatus.RESOLVABLE, IssueCategory.BOM);
    if (!hasResolveTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    IssueTrackerTransitionTestAction<T> transitionTestAction = new IssueTrackerTransitionTestAction<>(messageSender, fieldStatusCreator);
    Optional<MessageResult> optionalResolveFailure = transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel);
    if (optionalResolveFailure.isPresent()) {
        return optionalResolveFailure.get();
    }
    if (!hasReopenTransition(distributionDetails)) {
        return createSuccessMessageResult(existingIssueDetails);
    }
    return transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.OPEN, existingIssueDetails, testProjectIssueModel).orElseGet(() -> transitionTestAction.transitionTestIssueOrReturnFailureResult(IssueOperation.RESOLVE, existingIssueDetails, testProjectIssueModel).orElse(createSuccessMessageResult(existingIssueDetails)));
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 9 with IssueTrackerModelHolder

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder in project hub-alert by blackducksoftware.

the class IssueTrackerFieldModelTestActionTest method testConfigResolveFailure.

@Test
public void testConfigResolveFailure() throws AlertException {
    IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(messageSender.sendMessages(Mockito.any())).thenAnswer(invocation -> {
        IssueTrackerModelHolder<String> argument = invocation.getArgument(0);
        if (!argument.getIssueCreationModels().isEmpty()) {
            return List.of(TEST_ISSUE_RESPONSE_MODEL);
        }
        return List.of();
    });
    IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
    TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory, true, false);
    MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
    assertTrue(messageResult.hasErrors(), EXPECTED_ERRORS);
}
Also used : DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IssueTrackerMessageSenderFactory(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueTrackerMessageSender(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) Test(org.junit.jupiter.api.Test)

Example 10 with IssueTrackerModelHolder

use of com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder in project hub-alert by blackducksoftware.

the class IssueTrackerFieldModelTestActionTest method testConfigReopenFailure.

@Test
public void testConfigReopenFailure() throws AlertException {
    IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(messageSender.sendMessages(Mockito.any())).thenAnswer(invocation -> {
        IssueTrackerModelHolder<String> argument = invocation.getArgument(0);
        List<IssueTransitionModel<String>> transitionModels = argument.getIssueTransitionModels();
        if (!transitionModels.isEmpty()) {
            if (transitionModels.stream().anyMatch(model -> IssueOperation.RESOLVE.equals(model.getIssueOperation()))) {
                return List.of(TEST_ISSUE_RESPONSE_MODEL);
            } else {
                return List.of();
            }
        }
        return List.of(TEST_ISSUE_RESPONSE_MODEL);
    });
    IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
    TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory, true, true);
    MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
    assertTrue(messageResult.hasErrors(), EXPECTED_ERRORS);
}
Also used : DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) IssueTrackerMessageSenderFactory(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IssueTrackerMessageSender(com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender) IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ProcessingType(com.synopsys.integration.alert.common.enumeration.ProcessingType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IssueTrackerChannelKey(com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) Test(org.junit.jupiter.api.Test)

Aggregations

IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)8 Test (org.junit.jupiter.api.Test)7 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)5 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)4 IssueTransitionModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel)3 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)2 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)2 IssueTrackerMessageSender (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSender)2 IssueTrackerMessageSenderFactory (com.synopsys.integration.alert.api.channel.issue.send.IssueTrackerMessageSenderFactory)2 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)2 FrequencyType (com.synopsys.integration.alert.common.enumeration.FrequencyType)2 ProcessingType (com.synopsys.integration.alert.common.enumeration.ProcessingType)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)2 IssueTrackerChannelKey (com.synopsys.integration.alert.descriptor.api.model.IssueTrackerChannelKey)2 OffsetDateTime (java.time.OffsetDateTime)2 List (java.util.List)2 UUID (java.util.UUID)2