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());
}
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"));
}
}
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());
}
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());
}
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());
}
}
Aggregations