Search in sources :

Example 16 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.

the class BomEditNotificationMessageExtractor method createBomComponentDetails.

@Override
protected List<BomComponentDetails> createBomComponentDetails(BomEditWithProjectNameNotificationContent notificationContent, BlackDuckServicesFactory blackDuckServicesFactory) throws IntegrationException {
    BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
    BlackDuckMessageBomComponentDetailsCreator bomComponentDetailsCreator = detailsCreatorFactory.createBomComponentDetailsCreator(blackDuckServicesFactory);
    BomComponentDetails bomComponentDetails;
    try {
        ProjectVersionComponentVersionView bomComponent = blackDuckApiClient.getResponse(new HttpUrl(notificationContent.getBomComponent()), ProjectVersionComponentVersionView.class);
        bomComponentDetails = bomComponentDetailsCreator.createBomComponentDetails(bomComponent, List.of(), ComponentUpgradeGuidance.none(), List.of());
    } catch (IntegrationRestException e) {
        bomComponent404Handler.logIf404OrThrow(e, notificationContent.getComponentName(), notificationContent.getComponentVersionName());
        bomComponentDetails = bomComponentDetailsCreator.createMissingBomComponentDetails(notificationContent.getComponentName(), notificationContent.getBomComponent(), notificationContent.getComponentVersionName(), notificationContent.getBomComponent(), List.of(), ComponentUpgradeGuidance.none(), List.of());
    }
    return List.of(bomComponentDetails);
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckMessageBomComponentDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator) HttpUrl(com.synopsys.integration.rest.HttpUrl) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 17 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.

the class RuleViolationClearedNotificationMessageExtractorTest method createBomComponentDetailsMissingBomComponentTest.

@Test
public void createBomComponentDetailsMissingBomComponentTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.any(), Mockito.any());
    RuleViolationClearedUniquePolicyNotificationContent notificationContent = new RuleViolationClearedUniquePolicyNotificationContent(PROJECT, PROJECT_VERSION, PROJECT_VERSION_URL, COMPONENT_VERSIONS_CLEARED, List.of(componentVersionStatus), policyInfo);
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    assertEquals(COMPONENT, testBomComponentDetails.getComponent());
    assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
    assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_LICENSE, testBomComponentDetails.getLicense().getValue());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_USAGE, testBomComponentDetails.getUsage());
    assertEquals(1, testBomComponentDetails.getComponentConcerns().size());
    assertEquals(ItemOperation.DELETE, testBomComponentDetails.getComponentConcerns().get(0).getOperation());
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) RuleViolationClearedUniquePolicyNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.RuleViolationClearedUniquePolicyNotificationContent) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 18 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException in project hub-alert by blackducksoftware.

the class PolicyOverrideNotificationMessageExtractorTest method createBomComponentDetailsMissingBomComponentTest.

@Test
public void createBomComponentDetailsMissingBomComponentTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.any(), Mockito.any());
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(policyOverrideUniquePolicyNotificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    assertEquals(COMPONENT, testBomComponentDetails.getComponent());
    assertEquals(1, testBomComponentDetails.getComponentConcerns().size());
    assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
    assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_LICENSE, testBomComponentDetails.getLicense().getValue());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_USAGE, testBomComponentDetails.getUsage());
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 19 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException 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 20 with IntegrationRestException

use of com.synopsys.integration.rest.exception.IntegrationRestException 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

IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)22 HttpUrl (com.synopsys.integration.rest.HttpUrl)15 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)12 Test (org.junit.jupiter.api.Test)10 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)8 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)8 IntegrationException (com.synopsys.integration.exception.IntegrationException)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)5 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)4 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)4 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)3 VulnerabilityUniqueProjectNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)3 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)3 Gson (com.google.gson.Gson)2 JiraCustomFieldResolver (com.synopsys.integration.alert.api.channel.jira.distribution.custom.JiraCustomFieldResolver)2 JiraServerProperties (com.synopsys.integration.alert.channel.jira.server.JiraServerProperties)2