Search in sources :

Example 6 with ObjectTransformer

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());
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 7 with ObjectTransformer

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());
}
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 8 with ObjectTransformer

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());
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 9 with ObjectTransformer

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);
}
Also used : CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 10 with ObjectTransformer

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);
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Aggregations

ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)26 Test (org.junit.Test)19 Gson (com.google.gson.Gson)8 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)5 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)4 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)4 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)4 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 GlobalEmailRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper)2 GlobalHipChatRepositoryWrapper (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatRepositoryWrapper)2 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)2 NotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper)2 VulnerabilityRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)2 AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)2 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2