Search in sources :

Example 46 with IntegrationException

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);
    }
}
Also used : StringWriter(java.io.StringWriter) IntegrationException(com.synopsys.integration.exception.IntegrationException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Example 47 with IntegrationException

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());
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 48 with IntegrationException

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());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) IntegrationException(com.synopsys.integration.exception.IntegrationException) EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) Test(org.junit.jupiter.api.Test)

Example 49 with IntegrationException

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());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) IntegrationException(com.synopsys.integration.exception.IntegrationException) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) Test(org.junit.jupiter.api.Test)

Example 50 with IntegrationException

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);
    }
}
Also used : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) IntegrationException(com.synopsys.integration.exception.IntegrationException) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) HttpUrl(com.synopsys.integration.rest.HttpUrl) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException)

Aggregations

IntegrationException (com.synopsys.integration.exception.IntegrationException)53 HttpUrl (com.synopsys.integration.rest.HttpUrl)19 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)9 ArrayList (java.util.ArrayList)9 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)8 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 Set (java.util.Set)8 Test (org.junit.jupiter.api.Test)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 List (java.util.List)7 Optional (java.util.Optional)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6