Search in sources :

Example 31 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class HubDataHandlerTest method testGetHubProjectsThrowIntegrationException.

@Test
public void testGetHubProjectsThrowIntegrationException() throws Exception {
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final Gson gson = new Gson();
    final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
    Mockito.when(hubDataActions.getHubProjects()).thenThrow(new IntegrationException("ErrorMessage"));
    final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
    final ResponseEntity<String> responseEntity = hubDataHandler.getHubProjects();
    assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
    assertEquals("{\"id\":-1,\"message\":\"ErrorMessage\"}", responseEntity.getBody());
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 32 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class UserNotificationCacheTest method testAddUserInformationException.

@Test
public void testAddUserInformationException() throws Exception {
    try (OutputLogger outputLogger = new OutputLogger()) {
        final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
        final UserNotificationCache userNotificationCache = new UserNotificationCache(mockedProjectService);
        Mockito.doThrow(new IntegrationException()).when(mockedProjectService).getAssignedUsersToProject(Mockito.anyString());
        final Date createdAt = new Date();
        final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
        projectVersionModel.setProjectLink("New project link");
        final String componentName = "notification test";
        final ComponentVersionView componentVersionView = new ComponentVersionView();
        final String componentVersionUrl = "sss";
        final String componentIssueUrl = "ddd";
        final Map<String, Object> dataSet = new HashMap<>();
        dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
        final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
        final List<NotificationEvent> notificationEvents = Arrays.asList(notificationEvent);
        Collection<NotificationEvent> emptyEventList = Arrays.asList();
        assertEquals(0, emptyEventList.size());
        emptyEventList = userNotificationCache.addUserInformation(notificationEvents);
        assertEquals(0, emptyEventList.size());
        assertTrue(outputLogger.isLineContainingText("Error getting the users for project"));
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HashMap(java.util.HashMap) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) OutputLogger(com.blackducksoftware.integration.hub.alert.OutputLogger) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) Test(org.junit.Test)

Example 33 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class GlobalSchedulingHandlerTest method testRunAccumulatorWithException.

@Test
public void testRunAccumulatorWithException() throws Exception {
    final GlobalSchedulingConfigActions actions = Mockito.mock(GlobalSchedulingConfigActions.class);
    Mockito.doThrow(new IntegrationException("Test Exception")).when(actions).runAccumulator();
    final GlobalSchedulingHandler handler = new GlobalSchedulingHandler(GlobalSchedulingConfigEntity.class, GlobalSchedulingConfigRestModel.class, actions, null);
    final ResponseEntity<String> response = handler.runAccumulator();
    assertNotNull(response);
    assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Test(org.junit.Test)

Example 34 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class EmailGroupChannel method getEmailAddressesForGroup.

private List<String> getEmailAddressesForGroup(final HubServicesFactory hubServicesFactory, final String hubGroup) throws IntegrationException {
    final UserGroupService groupService = hubServicesFactory.createUserGroupService();
    final UserGroupView userGroupView = groupService.getGroupByName(hubGroup);
    if (userGroupView == null) {
        throw new IntegrationException("Could not find the Hub group: " + hubGroup);
    }
    logger.info(userGroupView.toString());
    logger.info(userGroupView.json);
    final List<UserView> users = hubServicesFactory.createHubService().getAllResponses(userGroupView, UserGroupView.USERS_LINK_RESPONSE);
    return users.stream().map(user -> user.email).collect(Collectors.toList());
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) TemplateException(freemarker.template.TemplateException) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) GlobalEmailConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailConfigEntity) StringUtils(org.apache.commons.lang3.StringUtils) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) Gson(com.google.gson.Gson) TemplateNotFoundException(freemarker.template.TemplateNotFoundException) JmsListener(org.springframework.jms.annotation.JmsListener) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) EmailTarget(com.blackducksoftware.integration.hub.alert.channel.email.template.EmailTarget) Logger(org.slf4j.Logger) EmailGroupDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionConfigEntity) IOException(java.io.IOException) EmailGroupDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper) Collectors(java.util.stream.Collectors) UserView(com.blackducksoftware.integration.hub.api.generated.view.UserView) MalformedTemplateNameException(freemarker.template.MalformedTemplateNameException) List(java.util.List) Component(org.springframework.stereotype.Component) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) DistributionChannel(com.blackducksoftware.integration.hub.alert.channel.DistributionChannel) ParseException(freemarker.core.ParseException) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) SupportedChannels(com.blackducksoftware.integration.hub.alert.channel.SupportedChannels) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) UserView(com.blackducksoftware.integration.hub.api.generated.view.UserView)

Example 35 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class ChannelRequestHelper method sendGenericRequest.

public Response sendGenericRequest(final Request request) throws IntegrationException {
    Response response = null;
    try {
        final HubService service = hubServicesFactory.createHubService();
        response = service.executeRequest(request);
        logger.trace("Response: " + response.toString());
        return response;
    } catch (final Exception generalException) {
        logger.error("Error sending request", generalException);
        throw new AlertException(generalException.getMessage());
    }
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) HubService(com.blackducksoftware.integration.hub.service.HubService) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)49 Test (org.junit.Test)21 IOException (java.io.IOException)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)8 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)8 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)5 ArrayList (java.util.ArrayList)5 Request (com.blackducksoftware.integration.hub.request.Request)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 UpdateFortifyApplicationAttributesRequest (com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest)3 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 File (java.io.File)3 Date (java.util.Date)3