Search in sources :

Example 11 with GlobalProperties

use of com.blackducksoftware.integration.hub.alert.config.GlobalProperties 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)

Example 12 with GlobalProperties

use of com.blackducksoftware.integration.hub.alert.config.GlobalProperties in project hub-alert by blackducksoftware.

the class LoginActionsTestIT method testIsUserValidFailIT.

@Test
public void testIsUserValidFailIT() throws IntegrationException, IOException {
    final LoginRestModel loginRestModel = mockLoginRestModel.createRestModel();
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setLogger(new Slf4jIntLogger(logger));
    serverConfigBuilder.setHubUrl(globalProperties.getHubUrl());
    serverConfigBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
    serverConfigBuilder.setTimeout(globalProperties.getHubTimeout());
    serverConfigBuilder.setPassword(loginRestModel.getHubPassword());
    serverConfigBuilder.setUsername(loginRestModel.getHubUsername());
    final LoginActions loginActions = new LoginActions(globalProperties);
    final RestConnection restConnection = loginActions.createRestConnection(serverConfigBuilder);
    final boolean roleValid = loginActions.isUserRoleValid("broken", restConnection);
    assertFalse(roleValid);
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) LoginRestModel(com.blackducksoftware.integration.hub.alert.web.model.LoginRestModel) MockLoginRestModel(com.blackducksoftware.integration.hub.alert.mock.model.MockLoginRestModel) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 13 with GlobalProperties

use of com.blackducksoftware.integration.hub.alert.config.GlobalProperties in project hub-alert by blackducksoftware.

the class HubDataActionsTest method testGetHubGroups.

@Test
public void testGetHubGroups() throws Exception {
    final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
    final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
    final HubService hubService = Mockito.mock(HubService.class);
    final List<UserGroupView> userGroups = new ArrayList<>();
    final Boolean active = true;
    final String username = "User";
    final String href = "href";
    final UserGroupView userGroup = new UserGroupView();
    final ResourceMetadata metaView = new ResourceMetadata();
    metaView.href = href;
    userGroup._meta = metaView;
    userGroup.active = active;
    userGroup.name = username;
    userGroups.add(userGroup);
    Mockito.when(hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE)).thenReturn(userGroups);
    Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
    Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
    Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(hubServicesFactory);
    final HubDataActions hubDataActions = new HubDataActions(globalProperties);
    final List<HubGroup> hubGroups = hubDataActions.getHubGroups();
    assertEquals(1, hubGroups.size());
    final HubGroup hubGroup = hubGroups.get(0);
    assertEquals(active, hubGroup.getActive());
    assertEquals(username, hubGroup.getName());
    assertEquals(href, hubGroup.getUrl());
}
Also used : ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Logger(org.slf4j.Logger) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 14 with GlobalProperties

use of com.blackducksoftware.integration.hub.alert.config.GlobalProperties in project hub-alert by blackducksoftware.

the class HubDataActionsTest method testGetHubProjectsNullHubServicesFactory.

@Test
public void testGetHubProjectsNullHubServicesFactory() 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.getHubProjects();
        fail();
    } catch (final AlertException e) {
        assertEquals("Missing global configuration.", e.getMessage());
    }
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) Logger(org.slf4j.Logger) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) Test(org.junit.Test)

Example 15 with GlobalProperties

use of com.blackducksoftware.integration.hub.alert.config.GlobalProperties in project hub-alert by blackducksoftware.

the class HubDataActionsTest method testGetHubProjectsNoProjects.

@Test
public void testGetHubProjectsNoProjects() throws Exception {
    final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
    final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
    final ProjectService projectRequestService = Mockito.mock(ProjectService.class);
    final HubService hubService = Mockito.mock(HubService.class);
    Mockito.when(hubService.getAllResponses(ApiDiscovery.PROJECTS_LINK_RESPONSE)).thenReturn(Collections.emptyList());
    Mockito.when(hubServicesFactory.createProjectService()).thenReturn(projectRequestService);
    Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
    Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(hubServicesFactory);
    final HubDataActions hubDataActions = new HubDataActions(globalProperties);
    final List<HubProject> hubProjects = hubDataActions.getHubProjects();
    assertEquals(0, hubProjects.size());
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) Logger(org.slf4j.Logger) HubService(com.blackducksoftware.integration.hub.service.HubService) HubProject(com.blackducksoftware.integration.hub.alert.hub.model.HubProject) Test(org.junit.Test)

Aggregations

GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)17 Test (org.junit.Test)13 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)8 Logger (org.slf4j.Logger)6 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)5 HubService (com.blackducksoftware.integration.hub.service.HubService)4 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)2 EmailGroupChannel (com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupChannel)2 EmailGroupEvent (com.blackducksoftware.integration.hub.alert.channel.email.EmailGroupEvent)2 AccumulatorConfig (com.blackducksoftware.integration.hub.alert.config.AccumulatorConfig)2 DailyDigestBatchConfig (com.blackducksoftware.integration.hub.alert.config.DailyDigestBatchConfig)2 PurgeConfig (com.blackducksoftware.integration.hub.alert.config.PurgeConfig)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)2 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)2 NotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper)2 VulnerabilityRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)2 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)2 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)2