Search in sources :

Example 6 with JiraCustomFieldResolver

use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver 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 7 with JiraCustomFieldResolver

use of com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver 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)

Aggregations

JiraCustomFieldResolver (com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver)7 JiraIssueCreationRequestCreator (com.synopsys.integration.alert.api.channel.jira.distribution.JiraIssueCreationRequestCreator)5 JiraErrorMessageUtility (com.synopsys.integration.alert.api.channel.jira.distribution.JiraErrorMessageUtility)4 JiraIssueAlertPropertiesManager (com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueAlertPropertiesManager)4 IssuePropertyService (com.synopsys.integration.jira.common.rest.service.IssuePropertyService)4 ProjectService (com.synopsys.integration.jira.common.cloud.service.ProjectService)3 Gson (com.google.gson.Gson)2 IssueTrackerModelExtractor (com.synopsys.integration.alert.api.channel.issue.IssueTrackerModelExtractor)2 IssueTrackerProcessor (com.synopsys.integration.alert.api.channel.issue.IssueTrackerProcessor)2 JiraIssueStatusCreator (com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraIssueStatusCreator)2 JiraSearcherFactory (com.synopsys.integration.alert.api.channel.jira.distribution.search.JiraSearcherFactory)2 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 JiraCloudProperties (com.synopsys.integration.alert.channel.jira.cloud.JiraCloudProperties)2 JiraServerProperties (com.synopsys.integration.alert.channel.jira.server.JiraServerProperties)2 FieldService (com.synopsys.integration.jira.common.cloud.service.FieldService)2 IssueService (com.synopsys.integration.jira.common.cloud.service.IssueService)2 JiraCloudServiceFactory (com.synopsys.integration.jira.common.cloud.service.JiraCloudServiceFactory)2 FieldService (com.synopsys.integration.jira.common.server.service.FieldService)2 IssueService (com.synopsys.integration.jira.common.server.service.IssueService)2 JiraServerServiceFactory (com.synopsys.integration.jira.common.server.service.JiraServerServiceFactory)2