use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class FreemarkerTemplatingService method resolveTemplate.
public String resolveTemplate(Map<String, Object> dataModel, Template template) throws IntegrationException {
try {
StringWriter stringWriter = new StringWriter();
template.process(dataModel, stringWriter);
return stringWriter.toString();
} catch (IOException | TemplateException e) {
throw new IntegrationException(e.getMessage(), e);
}
}
use of com.synopsys.integration.exception.IntegrationException 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.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorTest method runTest.
/**
* This test should simulate a normal run of the accumulator with notifications present.
*/
@Test
public void runTest() throws Exception {
ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
PageRetriever pageRetriever = Mockito.mock(PageRetriever.class);
StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = createMockNotificationPage(pageRetriever);
BlackDuckNotificationRetriever notificationRetriever = Mockito.mock(BlackDuckNotificationRetriever.class);
Mockito.when(notificationRetriever.retrievePageOfFilteredNotifications(Mockito.any(), Mockito.anyList())).thenReturn(notificationPage);
Mockito.when(pageRetriever.retrieveNextPage(Mockito.anyInt(), Mockito.anyInt())).thenReturn(AlertPagedDetails.emptyPage());
BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, notificationRetriever);
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
Mockito.when(notificationAccessor.saveAllNotifications(Mockito.anyList())).thenAnswer(invocation -> invocation.getArgument(0));
EventManager eventManager = Mockito.mock(EventManager.class);
Mockito.doNothing().when(eventManager).sendEvent(Mockito.any(NotificationReceivedEvent.class));
BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, notificationAccessor, taskPropertiesAccessor, blackDuckProperties, validator, eventManager, notificationRetrieverFactory);
accumulator.run();
Mockito.verify(notificationAccessor, Mockito.times(1)).saveAllNotifications(Mockito.anyList());
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorTest method runNotificationRetrieverThrowsException.
@Test
public void runNotificationRetrieverThrowsException() throws IntegrationException {
ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
BlackDuckNotificationRetriever notificationRetriever = Mockito.mock(BlackDuckNotificationRetriever.class);
Mockito.when(notificationRetriever.retrievePageOfFilteredNotifications(Mockito.any(), Mockito.anyList())).thenThrow(new IntegrationException("Test Exception"));
BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, notificationRetriever);
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, notificationAccessor, taskPropertiesAccessor, blackDuckProperties, validator, null, notificationRetrieverFactory);
accumulator.run();
Mockito.verify(notificationAccessor, Mockito.times(0)).saveAllNotifications(Mockito.anyList());
}
use of com.synopsys.integration.exception.IntegrationException 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