Search in sources :

Example 11 with ObjectTransformer

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

the class GlobalHubConfigActionsTest method testGetConfig.

@Test
@Override
public void testGetConfig() throws Exception {
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    Mockito.when(mockedGlobalRepository.findOne(Mockito.anyLong())).thenReturn(getGlobalEntityMockUtil().createGlobalEntity());
    Mockito.when(mockedGlobalRepository.findAll()).thenReturn(Arrays.asList(getGlobalEntityMockUtil().createGlobalEntity()));
    final GlobalHubConfigEntity databaseEntity = getGlobalEntityMockUtil().createGlobalEntity();
    final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    globalProperties.setHubTrustCertificate(null);
    globalProperties.setHubUrl(null);
    final ObjectTransformer objectTransformer = new ObjectTransformer();
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, objectTransformer);
    final GlobalHubConfigRestModel defaultRestModel = objectTransformer.databaseEntityToConfigRestModel(databaseEntity, GlobalHubConfigRestModel.class);
    final GlobalHubConfigRestModel maskedRestModel = configActions.maskRestModel(defaultRestModel);
    List<GlobalHubConfigRestModel> globalConfigsById = configActions.getConfig(1L);
    List<GlobalHubConfigRestModel> allGlobalConfigs = configActions.getConfig(null);
    assertTrue(globalConfigsById.size() == 1);
    assertTrue(allGlobalConfigs.size() == 1);
    final GlobalHubConfigRestModel globalConfigById = globalConfigsById.get(0);
    final GlobalHubConfigRestModel globalConfig = allGlobalConfigs.get(0);
    System.out.println(maskedRestModel.toString());
    System.out.println(globalConfigById.toString());
    assertEquals(maskedRestModel, globalConfigById);
    assertEquals(maskedRestModel, globalConfig);
    Mockito.when(mockedGlobalRepository.findOne(Mockito.anyLong())).thenReturn(null);
    Mockito.when(mockedGlobalRepository.findAll()).thenReturn(null);
    globalConfigsById = configActions.getConfig(1L);
    allGlobalConfigs = configActions.getConfig(null);
    assertNotNull(globalConfigsById);
    assertNotNull(allGlobalConfigs);
    assertTrue(globalConfigsById.isEmpty());
    assertTrue(allGlobalConfigs.size() == 1);
    final GlobalHubConfigRestModel environmentGlobalConfig = allGlobalConfigs.get(0);
    assertEquals(maskedRestModel.getHubAlwaysTrustCertificate(), environmentGlobalConfig.getHubAlwaysTrustCertificate());
    assertNull(environmentGlobalConfig.getHubApiKey());
    assertEquals(maskedRestModel.getHubProxyHost(), environmentGlobalConfig.getHubProxyHost());
    assertNull(environmentGlobalConfig.getHubProxyPassword());
    assertEquals(maskedRestModel.getHubProxyPort(), environmentGlobalConfig.getHubProxyPort());
    assertEquals(maskedRestModel.getHubProxyUsername(), environmentGlobalConfig.getHubProxyUsername());
    assertNull(environmentGlobalConfig.getHubTimeout());
    assertEquals(maskedRestModel.getHubUrl(), environmentGlobalConfig.getHubUrl());
    assertNull(environmentGlobalConfig.getId());
}
Also used : GlobalHubConfigRestModel(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) 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 12 with ObjectTransformer

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

the class GlobalHubConfigActionsTest method getMockedConfigActions.

@Override
public GlobalHubConfigActions getMockedConfigActions() {
    final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
    final GlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository);
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(mockedGlobalRepository, globalProperties, new ObjectTransformer());
    return configActions;
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties)

Example 13 with ObjectTransformer

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

the class EmailChannelManagerTest method getChannelManager.

@Override
public EmailGroupManager getChannelManager() {
    final EmailGroupChannel mockEmailChannel = Mockito.mock(EmailGroupChannel.class);
    final GlobalEmailRepositoryWrapper mockGlobalRepositoryWrapper = Mockito.mock(GlobalEmailRepositoryWrapper.class);
    final EmailGroupDistributionRepositoryWrapper mockRepositoryWrapper = Mockito.mock(EmailGroupDistributionRepositoryWrapper.class);
    final EmailGroupManager manager = new EmailGroupManager(mockEmailChannel, mockGlobalRepositoryWrapper, mockRepositoryWrapper, new ObjectTransformer());
    return manager;
}
Also used : EmailGroupDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.distribution.EmailGroupDistributionRepositoryWrapper) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) GlobalEmailRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.email.repository.global.GlobalEmailRepositoryWrapper)

Example 14 with ObjectTransformer

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

the class SlackChannelManagerTest method getChannelManager.

@Override
public SlackManager getChannelManager() {
    final SlackChannel mockSlackChannel = Mockito.mock(SlackChannel.class);
    final GlobalSlackRepositoryWrapper mockGlobalRepositoryWrapper = Mockito.mock(GlobalSlackRepositoryWrapper.class);
    final SlackDistributionRepositoryWrapper mockSlackRepositoryWrapper = Mockito.mock(SlackDistributionRepositoryWrapper.class);
    final SlackManager manager = new SlackManager(mockSlackChannel, mockGlobalRepositoryWrapper, mockSlackRepositoryWrapper, new ObjectTransformer());
    return manager;
}
Also used : ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) GlobalSlackRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.slack.repository.global.GlobalSlackRepositoryWrapper) SlackDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionRepositoryWrapper)

Example 15 with ObjectTransformer

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

the class GlobalSchedulingConfigActionsTest method testConfigurationChangeTriggers.

@Override
public void testConfigurationChangeTriggers() {
    final AccumulatorConfig mockedAccumulatorConfig = Mockito.mock(AccumulatorConfig.class);
    final DailyDigestBatchConfig mockedDailyDigestBatchConfig = Mockito.mock(DailyDigestBatchConfig.class);
    final PurgeConfig mockedPurgeConfig = Mockito.mock(PurgeConfig.class);
    final GlobalSchedulingRepositoryWrapper globalSchedulingRepository = Mockito.mock(GlobalSchedulingRepositoryWrapper.class);
    Mockito.when(globalSchedulingRepository.findAll()).thenReturn(Arrays.asList(getGlobalEntityMockUtil().createGlobalEntity()));
    final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
    final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
    final NotificationRepositoryWrapper notificationRepository = Mockito.mock(NotificationRepositoryWrapper.class);
    final VulnerabilityRepositoryWrapper vulnerabilityRepository = Mockito.mock(VulnerabilityRepositoryWrapper.class);
    final GlobalSchedulingConfigActions configActions = new GlobalSchedulingConfigActions(mockedAccumulatorConfig, mockedDailyDigestBatchConfig, mockedPurgeConfig, globalSchedulingRepository, new ObjectTransformer(), globalProperties, channelTemplateManager, new NotificationManager(notificationRepository, vulnerabilityRepository, null, null));
    configActions.configurationChangeTriggers(null);
    Mockito.verify(mockedAccumulatorConfig, Mockito.times(0)).scheduleJobExecution(Mockito.any());
    Mockito.verify(mockedDailyDigestBatchConfig, Mockito.times(0)).scheduleJobExecution(Mockito.any());
    Mockito.verify(mockedPurgeConfig, Mockito.times(0)).scheduleJobExecution(Mockito.any());
    Mockito.reset(mockedAccumulatorConfig);
    Mockito.reset(mockedDailyDigestBatchConfig);
    Mockito.reset(mockedPurgeConfig);
    final GlobalSchedulingConfigRestModel restModel = getGlobalRestModelMockUtil().createGlobalRestModel();
    configActions.configurationChangeTriggers(restModel);
    Mockito.verify(mockedAccumulatorConfig, Mockito.times(0)).scheduleJobExecution(Mockito.any());
    Mockito.verify(mockedDailyDigestBatchConfig, Mockito.times(1)).scheduleJobExecution(Mockito.any());
    Mockito.verify(mockedPurgeConfig, Mockito.times(1)).scheduleJobExecution(Mockito.any());
}
Also used : NotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper) AccumulatorConfig(com.blackducksoftware.integration.hub.alert.config.AccumulatorConfig) GlobalSchedulingRepositoryWrapper(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingRepositoryWrapper) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) ObjectTransformer(com.blackducksoftware.integration.hub.alert.web.ObjectTransformer) PurgeConfig(com.blackducksoftware.integration.hub.alert.config.PurgeConfig) DailyDigestBatchConfig(com.blackducksoftware.integration.hub.alert.config.DailyDigestBatchConfig) VulnerabilityRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)

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