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);
}
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());
}
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());
}
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: "));
}
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));
}
Aggregations