use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.
the class CommonConfigHandlerTest method getConfigHandleExceptionTest.
@Test
public void getConfigHandleExceptionTest() throws AlertException {
final CommonDistributionConfigActions configActions = Mockito.mock(CommonDistributionConfigActions.class);
final CommonConfigHandler<CommonDistributionConfigEntity, CommonDistributionConfigRestModel, CommonDistributionRepositoryWrapper> handler = new CommonConfigHandler<>(CommonDistributionConfigEntity.class, CommonDistributionConfigRestModel.class, configActions, objectTransformer);
Mockito.when(configActions.getConfig(Mockito.anyLong())).thenThrow(new AlertException());
Exception thrownException = null;
List<CommonDistributionConfigRestModel> list = null;
try {
list = handler.getConfig(1L);
} catch (final Exception e) {
thrownException = e;
}
assertNull(thrownException);
assertEquals(Collections.emptyList(), list);
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.
the class HubDataActionsTest method testGetHubGroupsNullHubServicesFactory.
@Test
public void testGetHubGroupsNullHubServicesFactory() throws Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(null);
final HubDataActions hubDataActions = new HubDataActions(globalProperties);
try {
hubDataActions.getHubGroups();
fail();
} catch (final AlertException e) {
assertEquals("Missing global configuration.", e.getMessage());
}
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.
the class ActionsTest method testSaveConfig.
@Test
public void testSaveConfig() throws Exception {
final E expectedConfigEntity = getEntityMockUtil().createEntity();
Mockito.when(configActions.getRepository().save(Mockito.any(getConfigEntityClass()))).thenReturn(expectedConfigEntity);
Mockito.when(configActions.getCommonDistributionRepository().save(Mockito.any(CommonDistributionConfigEntity.class))).thenReturn(distributionMockUtils.createEntity());
Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectOne())).thenReturn(projectMockUtils.getProjectOneEntity());
Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectTwo())).thenReturn(projectMockUtils.getProjectTwoEntity());
Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectThree())).thenReturn(projectMockUtils.getProjectThreeEntity());
Mockito.when(configActions.getConfiguredProjectsActions().getConfiguredProjectsRepository().findByProjectName(projectMockUtils.getProjectFour())).thenReturn(projectMockUtils.getProjectFourEntity());
Mockito.when(configActions.getNotificationTypesActions().getNotificationTypeRepository().findByType(notificationMockUtil.getType())).thenReturn(notificationMockUtil.createEntity());
E actualConfigEntity = configActions.saveConfig(getRestMockUtil().createRestModel());
assertNotNull(actualConfigEntity);
assertEquals(expectedConfigEntity, actualConfigEntity);
actualConfigEntity = configActions.saveConfig(null);
assertNull(actualConfigEntity);
Mockito.when(configActions.getRepository().save(Mockito.any(getConfigEntityClass()))).thenThrow(new RuntimeException("test"));
try {
actualConfigEntity = configActions.saveConfig(getRestMockUtil().createRestModel());
fail();
} catch (final AlertException e) {
assertEquals("test", e.getMessage());
}
final ObjectTransformer transformer = Mockito.mock(ObjectTransformer.class);
Mockito.when(transformer.configRestModelToDatabaseEntity(Mockito.any(), Mockito.any())).thenReturn(null);
configActions = createMockedConfigActionsUsingObjectTransformer(transformer);
actualConfigEntity = configActions.saveConfig(getRestMockUtil().createRestModel());
assertNull(actualConfigEntity);
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.
the class GlobalActionsTest method testSaveConfig.
@Test
public void testSaveConfig() throws Exception {
final GE expectedHipChatConfigEntity = getGlobalEntityMockUtil().createGlobalEntity();
Mockito.when(configActions.getRepository().save(Mockito.any(getGlobalEntityClass()))).thenReturn(expectedHipChatConfigEntity);
GE emailConfigEntity = configActions.saveConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
assertNotNull(emailConfigEntity);
assertEquals(expectedHipChatConfigEntity, emailConfigEntity);
emailConfigEntity = configActions.saveConfig(null);
assertNull(emailConfigEntity);
Mockito.when(configActions.getRepository().save(Mockito.any(getGlobalEntityClass()))).thenThrow(new RuntimeException("test"));
try {
emailConfigEntity = configActions.saveConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
fail();
} catch (final AlertException e) {
assertEquals("test", e.getMessage());
}
final ObjectTransformer transformer = Mockito.mock(ObjectTransformer.class);
Mockito.when(transformer.configRestModelToDatabaseEntity(Mockito.any(), Mockito.any())).thenReturn(null);
configActions = createMockedConfigActionsUsingObjectTransformer(transformer);
emailConfigEntity = configActions.saveConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
assertNull(emailConfigEntity);
}
use of com.blackducksoftware.integration.hub.alert.exception.AlertException in project hub-alert by blackducksoftware.
the class HubDataActions method getHubProjects.
public List<HubProject> getHubProjects() throws IntegrationException {
final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactory(logger);
if (hubServicesFactory != null) {
final List<ProjectView> rawProjects = hubServicesFactory.createHubService().getAllResponses(ApiDiscovery.PROJECTS_LINK_RESPONSE);
final List<HubProject> projects = new ArrayList<>();
for (final ProjectView projectView : rawProjects) {
final HubProject project = new HubProject(projectView.name);
projects.add(project);
}
return projects;
} else {
throw new AlertException("Missing global configuration.");
}
}
Aggregations