use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubProjects.
@Test
public void testGetHubProjects() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final Gson gson = new Gson();
final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
Mockito.when(hubDataActions.getHubProjects()).thenReturn(Collections.emptyList());
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubProjects();
assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"[]\"}", responseEntity.getBody());
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubGroupsThrowIntegrationException.
@Test
public void testGetHubGroupsThrowIntegrationException() throws Exception {
final ObjectTransformer objectTransformer = new ObjectTransformer();
final Gson gson = new Gson();
final HubDataActions hubDataActions = Mockito.mock(HubDataActions.class);
Mockito.when(hubDataActions.getHubGroups()).thenThrow(new IntegrationException("ErrorMessage"));
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubGroups();
assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"ErrorMessage\"}", responseEntity.getBody());
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.
the class HubDataHandlerTest method testGetHubProjectsThrowException.
@Test
public void testGetHubProjectsThrowException() 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 IllegalStateException("ErrorMessage"));
final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
final ResponseEntity<String> responseEntity = hubDataHandler.getHubProjects();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
assertEquals("{\"id\":-1,\"message\":\"ErrorMessage\"}", responseEntity.getBody());
}
use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer 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.web.ObjectTransformer 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);
}
Aggregations