Search in sources :

Example 16 with IntegrationException

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

the class HipChatChannelTest method testGlobalConfigInvalidApiKeyTest.

@Test
public void testGlobalConfigInvalidApiKeyTest() {
    final TestGlobalProperties globalProperties = new TestGlobalProperties();
    globalProperties.setHubTrustCertificate(Boolean.TRUE);
    final ChannelRestConnectionFactory restFactory = new ChannelRestConnectionFactory(globalProperties);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    hipChatMockUtil.setApiKey("garbage");
    try {
        final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
        hipChatChannel.testGlobalConfig(entity);
    } catch (final IntegrationException ex) {
        assertTrue(ex.getMessage().contains("Invalid API key: "));
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 17 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 18 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 19 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 20 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)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)24 Test (org.junit.Test)12 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)5 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)3 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)3 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 Request (com.blackducksoftware.integration.hub.request.Request)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 HashMap (java.util.HashMap)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)2