Search in sources :

Example 81 with AlertException

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

the class IssueTrackerFieldModelTestActionTest method testConfigSendMessagesThrowsException.

@Test
public void testConfigSendMessagesThrowsException() throws AlertException {
    String testExceptionMessage = "test exception message";
    IssueTrackerMessageSender<String> messageSender = Mockito.mock(IssueTrackerMessageSender.class);
    Mockito.when(messageSender.sendMessages(Mockito.any())).thenThrow(new AlertException(testExceptionMessage));
    IssueTrackerMessageSenderFactory<TestJobDetails, String> messageSenderFactory = distributionDetails -> messageSender;
    TestIssueTrackerTestAction issueTrackerTestAction = new TestIssueTrackerTestAction(messageSenderFactory);
    MessageResult messageResult = issueTrackerTestAction.testConfig(TEST_JOB_MODEL, "jobName", null, null);
    assertTrue(messageResult.getStatusMessage().contains(testExceptionMessage), "Expected the message result to contain the expected exception message");
}
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) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 82 with AlertException

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

the class JiraErrorMessageUtilityTest method verifyReporterRestExceptionTest.

@Test
void verifyReporterRestExceptionTest() throws IntegrationException, IOException {
    JiraCustomFieldResolver jiraCustomFieldResolver = new JiraCustomFieldResolver(() -> List.of());
    JiraErrorMessageUtility jiraErrorMessageUtility = new JiraErrorMessageUtility(new Gson(), jiraCustomFieldResolver);
    IntegrationRestException integrationRestException = createRestException(JsonTestResource.REPORTER_ERROR);
    String issueCreatorKey = "issueCreatorFieldKey";
    String issueCreatorEmail = "issueCreatorEmail";
    AlertException alertException = jiraErrorMessageUtility.improveRestException(integrationRestException, issueCreatorKey, issueCreatorEmail);
    assertTrue(alertException instanceof AlertFieldException);
    AlertFieldException alertFieldException = (AlertFieldException) alertException;
    List<AlertFieldStatus> fieldErrors = alertFieldException.getFieldErrors();
    assertEquals(1, fieldErrors.size());
    AlertFieldStatus alertFieldStatus = fieldErrors.get(0);
    assertEquals(issueCreatorKey, alertFieldStatus.getFieldName());
    assertEquals(FieldStatusSeverity.ERROR, alertFieldStatus.getSeverity());
    String fieldMessage = alertFieldStatus.getFieldMessage();
    assertTrue(fieldMessage.contains(issueCreatorEmail));
    assertTrue(fieldMessage.contains("It'sa me, Mario"));
    assertFalse(fieldMessage.contains(" | Details: "));
}
Also used : JiraCustomFieldResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Gson(com.google.gson.Gson) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 83 with AlertException

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

the class JiraErrorMessageUtilityTest method verifyFieldErrorsRestExceptionTest.

@Test
void verifyFieldErrorsRestExceptionTest() throws IntegrationException, IOException {
    String customFieldKey = "customfield_1";
    String customFieldName = "Custom Field 1 Name";
    String nonExistentCustomName = "Field 33 Name";
    Map<String, String> fieldIdsToNames = Map.of("customfield_6", "lol", "customfield_33", nonExistentCustomName, customFieldKey, customFieldName);
    JiraCustomFieldResolver jiraCustomFieldResolver = new JiraCustomFieldResolver(() -> createCustomFieldResponseModels(fieldIdsToNames));
    JiraErrorMessageUtility jiraErrorMessageUtility = new JiraErrorMessageUtility(new Gson(), jiraCustomFieldResolver);
    IntegrationRestException integrationRestException = createRestException(JsonTestResource.ERROR_MESSAGES_ERROR);
    String issueCreatorKey = "issueCreatorFieldKey";
    String issueCreatorEmail = "issueCreatorEmail";
    AlertException alertException = jiraErrorMessageUtility.improveRestException(integrationRestException, issueCreatorKey, issueCreatorEmail);
    String message = alertException.getMessage();
    assertTrue(message.contains(customFieldName));
    assertTrue(message.contains("This field should have had another value"));
    assertTrue(message.contains(customFieldKey));
    assertFalse(message.contains(nonExistentCustomName));
}
Also used : JiraCustomFieldResolver(com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Gson(com.google.gson.Gson) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 84 with AlertException

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

the class IssueTrackerSearcher method findIssueByProjectIssueModel.

private ActionableIssueSearchResult<T> findIssueByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    ExistingIssueDetails<T> existingIssue = null;
    ItemOperation searchResultOperation = ItemOperation.UPDATE;
    List<ExistingIssueDetails<T>> existingIssues = exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    int foundIssuesCount = existingIssues.size();
    if (foundIssuesCount == 1) {
        existingIssue = existingIssues.get(0);
        Optional<ItemOperation> policyOperation = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation);
        Optional<IssueVulnerabilityDetails> optionalVulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
        Optional<ItemOperation> componentUnknownOperation = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation);
        if (policyOperation.isPresent()) {
            searchResultOperation = policyOperation.get();
        } else if (optionalVulnerabilityDetails.isPresent()) {
            IssueVulnerabilityDetails issueVulnerabilityDetails = optionalVulnerabilityDetails.get();
            searchResultOperation = findVulnerabilitySearchResultOperation(existingIssue, issueVulnerabilityDetails);
        } else if (componentUnknownOperation.isPresent()) {
            searchResultOperation = componentUnknownOperation.get();
        }
    } else if (foundIssuesCount > 1) {
        Set<String> issueKeys = existingIssues.stream().map(ExistingIssueDetails::getIssueKey).collect(Collectors.toSet());
        String issueKeyString = StringUtils.join(issueKeys, ", ");
        throw new AlertException("Expected to find a unique issue, but more than one was found. " + issueKeyString);
    } else {
        searchResultOperation = ItemOperation.ADD;
    }
    return new ActionableIssueSearchResult<>(existingIssue, projectIssueModel, searchResultOperation);
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) Set(java.util.Set) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 85 with AlertException

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

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