use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class ProxyTestService method pingHost.
public ConfigurationTestResult pingHost(String testUrl, SettingsProxyModel settingsProxyModel) {
ProxyInfo proxyInfo = proxyManager.createProxyInfo(settingsProxyModel);
IntHttpClient client = createIntHttpClient(proxyInfo);
try {
HttpUrl httpUrl = new HttpUrl(testUrl);
Request testRequest = new Request.Builder(httpUrl).build();
Response response = client.execute(testRequest);
if (RestConstants.OK_200 >= response.getStatusCode() && response.getStatusCode() < RestConstants.MULT_CHOICE_300) {
logger.info("Successfully pinged {}!", testUrl);
return ConfigurationTestResult.success();
} else {
return ConfigurationTestResult.failure(String.format("Could not ping: %s. Status Message: %s. Status code: %s", testUrl, response.getStatusMessage(), response.getStatusCode()));
}
} catch (IntegrationException e) {
logger.error(e.getMessage(), e);
return ConfigurationTestResult.failure(e.getMessage());
}
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class NotificationContentProcessorTest method createRuleViolationNotificationMessageExtractor.
private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
// Mocks for AbstractRuleViolationNotificationMessageExtractor
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class JobNotificationProcessorTest method createRuleViolationNotificationMessageExtractor.
private RuleViolationNotificationMessageExtractor createRuleViolationNotificationMessageExtractor() throws IntegrationException {
BlackDuckProviderKey providerKey = new BlackDuckProviderKey();
NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
// Mocks for AbstractRuleViolationNotificationMessageExtractor
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.any())).thenReturn(blackDuckServicesFactory);
Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl(PROVIDER_DETAILS.getProvider().getUrl().get()));
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
ProjectVersionComponentVersionView projectVersionComponentVersionView = blackDuckResponseTestUtility.createProjectVersionComponentVersionView();
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
return new RuleViolationNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class NotificationGeneratorUtils method createVulnerabilityList.
public static List<VulnerabilityView> createVulnerabilityList() throws IntegrationException {
VulnerabilityView vuln_1 = new VulnerabilityView();
vuln_1.setName("1");
vuln_1.setSeverity(VulnerabilitySeverityType.LOW);
vuln_1.setMeta(new ResourceMetadata());
vuln_1.getMeta().setHref(new HttpUrl("href_1"));
VulnerabilityView vuln_2 = new VulnerabilityView();
vuln_2.setName("2");
vuln_2.setSeverity(VulnerabilitySeverityType.LOW);
vuln_2.setMeta(new ResourceMetadata());
vuln_2.getMeta().setHref(new HttpUrl("href_2"));
VulnerabilityView vuln_3 = new VulnerabilityView();
vuln_3.setName("3");
vuln_3.setSeverity(VulnerabilitySeverityType.LOW);
vuln_3.setMeta(new ResourceMetadata());
vuln_3.getMeta().setHref(new HttpUrl("href_3"));
VulnerabilityView vuln_4 = new VulnerabilityView();
vuln_4.setName("4");
vuln_4.setSeverity(VulnerabilitySeverityType.MEDIUM);
vuln_4.setMeta(new ResourceMetadata());
vuln_4.getMeta().setHref(new HttpUrl("href_4"));
VulnerabilityView vuln_5 = new VulnerabilityView();
vuln_5.setName("5");
vuln_5.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_5.setMeta(new ResourceMetadata());
vuln_5.getMeta().setHref(new HttpUrl("href_5"));
VulnerabilityView vuln_6 = new VulnerabilityView();
vuln_6.setName("6");
vuln_6.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_6.setMeta(new ResourceMetadata());
vuln_6.getMeta().setHref(new HttpUrl("href_6"));
VulnerabilityView vuln_7 = new VulnerabilityView();
vuln_7.setName("7");
vuln_7.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_7.setMeta(new ResourceMetadata());
vuln_7.getMeta().setHref(new HttpUrl("href_7"));
VulnerabilityView vuln_8 = new VulnerabilityView();
vuln_8.setName("8");
vuln_8.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_8.setMeta(new ResourceMetadata());
vuln_8.getMeta().setHref(new HttpUrl("href_8"));
VulnerabilityView vuln_9 = new VulnerabilityView();
vuln_9.setName("9");
vuln_9.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_9.setMeta(new ResourceMetadata());
vuln_9.getMeta().setHref(new HttpUrl("href_9"));
VulnerabilityView vuln_10 = new VulnerabilityView();
vuln_10.setName("10");
vuln_10.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_10.setMeta(new ResourceMetadata());
vuln_10.getMeta().setHref(new HttpUrl("href_10"));
VulnerabilityView vuln_11 = new VulnerabilityView();
vuln_11.setName("11");
vuln_11.setSeverity(VulnerabilitySeverityType.HIGH);
vuln_11.setMeta(new ResourceMetadata());
vuln_11.getMeta().setHref(new HttpUrl("href_11"));
return Arrays.asList(vuln_1, vuln_2, vuln_3, vuln_4, vuln_5, vuln_6, vuln_7, vuln_8, vuln_9, vuln_10, vuln_11);
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class IntegrationAlertRequestUtility method executeRequest.
private String executeRequest(HttpMethod httpMethod, MockHttpServletRequestBuilder requestBuilder, String error) throws IntegrationException {
MockHttpServletRequestBuilder request = requestBuilder.with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
try {
MvcResult mvcResult = mockMvc.perform(request).andReturn();
String responseContent = mvcResult.getResponse().getContentAsString();
int status = mvcResult.getResponse().getStatus();
if (status >= RestConstants.BAD_REQUEST_400) {
intLogger.error(String.format("Error code: %s", status));
intLogger.error(String.format("Response: %s", responseContent));
intLogger.error(error);
throw new IntegrationRestException(httpMethod, new HttpUrl("https://google.com"), status, "Bad Request", responseContent, error);
}
return responseContent;
} catch (IntegrationRestException e) {
throw e;
} catch (Exception e) {
throw new IntegrationException(e.getMessage(), e);
}
}
Aggregations