Search in sources :

Example 1 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class GlobalEmailConfigActionsTest method getMockedConfigActions.

@Override
public GlobalEmailConfigActions getMockedConfigActions() {
    final GlobalEmailRepositoryWrapper repository = Mockito.mock(GlobalEmailRepositoryWrapper.class);
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    return new GlobalEmailConfigActions(repository, objectTransformer);
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper)

Example 2 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class GlobalHipChatConfigActionsTest method getMockedConfigActions.

@Override
public GlobalHipChatConfigActions getMockedConfigActions() {
    final GlobalHipChatRepositoryWrapper hipChatRepo = Mockito.mock(GlobalHipChatRepositoryWrapper.class);
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final HipChatManager hipChatManager = Mockito.mock(HipChatManager.class);
    return new GlobalHipChatConfigActions(hipChatRepo, objectTransformer, hipChatManager);
}
Also used : GlobalHipChatRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatRepositoryWrapper) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) HipChatManager(com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatManager)

Example 3 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testGetException.

@Test
public void testGetException() throws AlertException, IOException {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final NotificationRepositoryWrapper notificationRepository = Mockito.mock(NotificationRepositoryWrapper.class);
    final VulnerabilityRepositoryWrapper vulnerabilityRepository = Mockito.mock(VulnerabilityRepositoryWrapper.class);
    final AuditNotificationRepositoryWrapper auditNotificationRepository = Mockito.mock(AuditNotificationRepositoryWrapper.class);
    final CommonDistributionRepositoryWrapper commonDistributionRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final ObjectTransformer spyObjectTransformer = Mockito.spy(objectTransformer);
    final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    final MockNotificationEntity mockNotificationEntity = new MockNotificationEntity();
    final MockCommonDistributionEntity mockCommonDistributionEntity = new MockCommonDistributionEntity();
    Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEmptyEntity());
    Mockito.when(commonDistributionRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(mockCommonDistributionEntity.createEntity());
    Mockito.doThrow(new AlertException()).when(spyObjectTransformer).databaseEntityToConfigRestModel(Mockito.any(), Mockito.any());
    Mockito.when(notificationRepository.findAll(Mockito.any())).thenReturn(Arrays.asList(mockNotificationEntity.createEntity()));
    final AuditEntryActions auditEntryActions = new AuditEntryActions(auditEntryRepository, new NotificationManager(notificationRepository, vulnerabilityRepository, auditEntryRepository, auditNotificationRepository), auditNotificationRepository, commonDistributionRepositoryWrapper, spyObjectTransformer, null, null, null);
    auditEntryActions.get(1L);
    assertTrue(outputLogger.isLineContainingText("Problem converting audit entry"));
}
Also used : AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) NotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) VulnerabilityRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 4 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testTestConfig.

@Test
public void testTestConfig() throws Exception {
    final RestConnection mockedRestConnection = Mockito.mock(RestConnection.class);
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, new ObjectTransformer());
    configActions = Mockito.spy(configActions);
    Mockito.doAnswer(new Answer<RestConnection>() {

        @Override
        public RestConnection answer(final InvocationOnMock invocation) throws Throwable {
            return mockedRestConnection;
        }
    }).when(configActions).createRestConnection(Mockito.any(HubServerConfigBuilder.class));
    Mockito.doNothing().when(configActions).validateHubConfiguration(Mockito.any(HubServerConfigBuilder.class));
    configActions.testConfig(getGlobalRestModelMockUtil().createGlobalRestModel());
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel fullRestModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    configActions.testConfig(fullRestModel);
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
    Mockito.reset(mockedRestConnection);
    final GlobalHubConfigRestModel restModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    final GlobalHubConfigRestModel partialRestModel = configActions.maskRestModel(restModel);
    Mockito.doAnswer(new Answer<GlobalHubConfigEntity>() {

        @Override
        public GlobalHubConfigEntity answer(final InvocationOnMock invocation) throws Throwable {
            return getGlobalEntityMockUtil().createGlobalEntity();
        }
    }).when(mockedGlobalRepository).findOne(Mockito.anyLong());
    final String result = configActions.testConfig(partialRestModel);
    assertEquals("Successfully connected to the Hub.", result);
    Mockito.verify(mockedRestConnection, Mockito.times(1)).connect();
}
Also used : GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Example 5 with ObjectTransformer

use of com.blackducksoftware.integration.hub.alert.web.ObjectTransformer in project hub-alert by blackducksoftware.

the class HubDataHandlerTest method testGetHubGroupsThrowException.

@Test
public void testGetHubGroupsThrowException() 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 IllegalStateException("ErrorMessage"));
    final HubDataHandler hubDataHandler = new HubDataHandler(objectTransformer, gson, hubDataActions);
    final ResponseEntity<String> responseEntity = hubDataHandler.getHubGroups();
    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)

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