Search in sources :

Example 76 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class IssueTrackerIssueTransitionerTest method transitionIssueThrowsExceptionTest.

@Test
public void transitionIssueThrowsExceptionTest() throws AlertException {
    IssueOperation testOperation = IssueOperation.RESOLVE;
    IssueTransitionModel<String> issueTransitionModel = new IssueTransitionModel<>(null, testOperation, List.of("comment 1"), null);
    IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
    IssueTrackerIssueResponseCreator issueResponseCreator = new IssueTrackerIssueResponseCreator(callbackInfoCreator);
    IssueTrackerIssueCommenter<String> exceptionThrowingCommenter = Mockito.mock(IssueTrackerIssueCommenter.class);
    Mockito.when(exceptionThrowingCommenter.commentOnIssue(Mockito.any())).thenThrow(new AlertException("Test exception"));
    IssueTrackerIssueTransitioner<String> transitioner = new TestTransitioner(exceptionThrowingCommenter, issueResponseCreator, "TODO", true, true);
    try {
        transitioner.transitionIssue(issueTransitionModel);
        fail("Expected an exception to be thrown");
    } catch (IssueMissingTransitionException e) {
        assertEquals(TEST_EXCEPTION, e);
    }
}
Also used : IssueTrackerCallbackInfoCreator(com.synopsys.integration.alert.api.channel.issue.callback.IssueTrackerCallbackInfoCreator) IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) IssueMissingTransitionException(com.synopsys.integration.alert.common.channel.issuetracker.exception.IssueMissingTransitionException) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 77 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException 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 78 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class IssueTrackerFieldModelTestActionTest method testConfigSendMessagesReturnsNoIssues.

@Test
public void testConfigSendMessagesReturnsNoIssues() throws AlertException {
    IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(messageSender.sendMessages(Mockito.any())).thenReturn(List.of());
    IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
    TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
    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 79 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.

the class IssueTrackerFieldModelTestActionTest method testConfigNoResolveTransition.

@Test
public void testConfigNoResolveTransition() throws AlertException {
    IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(messageSender.sendMessages(Mockito.any())).thenReturn(List.of(TEST_ISSUE_RESPONSE_MODEL));
    IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
    TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
    MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
    assertFalse(messageResult.hasErrors(), EXPECTED_NO_ERRORS);
    assertFalse(messageResult.hasWarnings(), EXPECTED_NO_WARNINGS);
}
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 80 with AlertException

use of com.synopsys.integration.alert.api.common.model.exception.AlertException 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

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)101 Test (org.junit.jupiter.api.Test)35 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)22 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 List (java.util.List)18 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)17 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)16 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)16 Optional (java.util.Optional)13 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)12 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)12 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)11 HashMap (java.util.HashMap)11 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ArrayList (java.util.ArrayList)9 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)8 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)8 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)8 UUID (java.util.UUID)8 IssueOperation (com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation)7