Search in sources :

Example 41 with ConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class BlackDuckGlobalApiActionTest method runApiActionTest.

private void runApiActionTest(ThrowingBiFunction<BlackDuckGlobalApiAction, FieldModel, FieldModel, AlertException> apiAction) throws AlertException {
    TaskManager taskManager = new TaskManager();
    BlackDuckProperties properties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(properties.isConfigEnabled()).thenReturn(true);
    FieldModel fieldModel = Mockito.mock(FieldModel.class);
    Mockito.when(fieldModel.getId()).thenReturn("1");
    Mockito.when(fieldModel.getFieldValue(Mockito.eq(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED))).thenReturn(Optional.of("true"));
    String providerConfigName = "Test Provider Config";
    Mockito.when(fieldModel.getFieldValue(Mockito.eq(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME))).thenReturn(Optional.of(providerConfigName));
    BlackDuckAccumulator blackDuckAccumulator = Mockito.mock(BlackDuckAccumulator.class);
    Mockito.when(blackDuckAccumulator.getTaskName()).thenReturn("accumulator-task");
    Mockito.when(blackDuckAccumulator.getFormatedNextRunTime()).thenReturn(Optional.of("SOON"));
    BlackDuckDataSyncTask blackDuckDataSyncTask = Mockito.mock(BlackDuckDataSyncTask.class);
    Mockito.when(blackDuckDataSyncTask.getTaskName()).thenReturn("data-sync-task");
    Mockito.when(blackDuckDataSyncTask.getFormatedNextRunTime()).thenReturn(Optional.of("SOON"));
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Long providerConfigId = -1L;
    Mockito.when(configurationModel.getConfigurationId()).thenReturn(providerConfigId);
    Mockito.when(configurationModel.getDescriptorId()).thenReturn(providerConfigId);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
    configurationFieldModel.setFieldValue("true");
    Mockito.when(configurationModel.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED)).thenReturn(Optional.of(configurationFieldModel));
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(configurationModel));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(BlackDuckProviderKey.class), Mockito.eq(ConfigContextEnum.DISTRIBUTION))).thenReturn(List.of());
    BlackDuckProviderKey blackDuckProviderKey = new BlackDuckProviderKey();
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider blackDuckProvider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(blackDuckProvider.validate(configurationModel)).thenReturn(true);
    Mockito.when(blackDuckProvider.createStatefulProvider(configurationModel)).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getKey()).thenReturn(blackDuckProviderKey);
    Mockito.when(statefulProvider.getConfigId()).thenReturn(providerConfigId);
    Mockito.when(statefulProvider.isConfigEnabled()).thenReturn(true);
    Mockito.when(statefulProvider.getConfigName()).thenReturn(providerConfigName);
    Mockito.when(statefulProvider.getProperties()).thenReturn(properties);
    Mockito.when(statefulProvider.getTasks()).thenReturn(List.of(blackDuckAccumulator, blackDuckDataSyncTask));
    BlackDuckPropertiesFactory propertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
    Mockito.when(propertiesFactory.createProperties((ConfigurationModel) Mockito.any())).thenReturn(properties);
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    ConfigurationFieldModelConverter fieldModelConverter = Mockito.mock(ConfigurationFieldModelConverter.class);
    Mockito.when(fieldModelConverter.convertToConfigurationModel(Mockito.any())).thenReturn(configurationModel);
    BlackDuckCacheHttpClientCache blackDuckCacheHttpClientCache = Mockito.mock(BlackDuckCacheHttpClientCache.class);
    ProviderSchedulingManager providerLifecycleManager = new ProviderSchedulingManager(List.of(blackDuckProvider), taskManager, null);
    BlackDuckGlobalApiAction blackDuckGlobalApiAction = new BlackDuckGlobalApiAction(blackDuckProvider, providerLifecycleManager, providerDataAccessor, configurationModelConfigurationAccessor, blackDuckCacheHttpClientCache);
    Optional<String> initialAccumulatorNextRunTime = taskManager.getNextRunTime(blackDuckAccumulator.getTaskName());
    Optional<String> initialSyncNextRunTime = taskManager.getNextRunTime(blackDuckDataSyncTask.getTaskName());
    assertTrue(initialAccumulatorNextRunTime.isEmpty());
    assertTrue(initialSyncNextRunTime.isEmpty());
    apiAction.apply(blackDuckGlobalApiAction, fieldModel);
    Optional<String> accumulatorNextRunTime = taskManager.getNextRunTime(blackDuckAccumulator.getTaskName());
    Optional<String> syncNextRunTime = taskManager.getNextRunTime(blackDuckDataSyncTask.getTaskName());
    assertTrue(accumulatorNextRunTime.isPresent(), "The accumulator task next run time was not present");
    assertTrue(syncNextRunTime.isPresent(), "The sync task next run time was not present");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckCacheHttpClientCache(com.synopsys.integration.alert.provider.blackduck.BlackDuckCacheHttpClientCache) ProviderSchedulingManager(com.synopsys.integration.alert.api.provider.lifecycle.ProviderSchedulingManager) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckDataSyncTask(com.synopsys.integration.alert.provider.blackduck.task.BlackDuckDataSyncTask) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) BlackDuckAccumulator(com.synopsys.integration.alert.provider.blackduck.task.accumulator.BlackDuckAccumulator) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider)

Example 42 with ConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class BlackDuckGlobalConfigurationFieldModelValidatorTest method createDefaultConfigurationAccessor.

private ConfigurationModelConfigurationAccessor createDefaultConfigurationAccessor() {
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of());
    return configurationModelConfigurationAccessor;
}
Also used : ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)

Example 43 with ConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class BlackDuckDistributionFieldModelTestActionTest method createConfigurationAccessor.

private ConfigurationModelConfigurationAccessor createConfigurationAccessor() {
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.anyLong())).thenReturn(Optional.empty());
    return configurationModelConfigurationAccessor;
}
Also used : ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)

Example 44 with ConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class DailyTaskTest method cronExpressionNotDefault.

@Test
void cronExpressionNotDefault() {
    final String notDefaultValue = "44";
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(1L, 1L, null, null, ConfigContextEnum.GLOBAL);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(SchedulingDescriptor.KEY_DAILY_PROCESSOR_HOUR_OF_DAY);
    configurationFieldModel.setFieldValue(notDefaultValue);
    configurationModel.put(configurationFieldModel);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    StaticJobAccessor jobAccessor = Mockito.mock(StaticJobAccessor.class);
    Mockito.when(jobAccessor.hasJobsByFrequency(Mockito.any())).thenReturn(true);
    DailyTask task = new DailyTask(SCHEDULING_DESCRIPTOR_KEY, null, null, null, null, configurationModelConfigurationAccessor, jobAccessor);
    String cronWithNotDefault = task.scheduleCronExpression();
    String expectedCron = String.format(DailyTask.CRON_FORMAT, notDefaultValue);
    assertEquals(expectedCron, cronWithNotDefault);
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DailyTask(com.synopsys.integration.alert.component.scheduling.workflow.DailyTask) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) SchedulingDescriptorKey(com.synopsys.integration.alert.component.scheduling.descriptor.SchedulingDescriptorKey) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

Example 45 with ConfigurationModelConfigurationAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor in project hub-alert by blackducksoftware.

the class UserDetailsServiceTest method initializeAuthoritiesPopulator.

@BeforeEach
public void initializeAuthoritiesPopulator() {
    Set<UserRoleModel> roles = Arrays.stream(VALID_DB_ROLES).map(UserRoleModel::of).collect(Collectors.toSet());
    UserModel userModel = UserModel.newUser(USER_NAME, "password", EMAIL, AuthenticationType.SAML, roles, true);
    AuthenticationDescriptorKey key = new AuthenticationDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationModel configuration = Mockito.mock(ConfigurationModel.class);
    UserAccessor userAccessor = Mockito.mock(UserAccessor.class);
    Mockito.when(configuration.getField(Mockito.anyString())).thenReturn(Optional.empty());
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.eq(key))).thenReturn(List.of(configuration));
    Mockito.when(userAccessor.getUser(Mockito.anyString())).thenReturn(Optional.of(userModel));
    authoritiesPopulator = new UserManagementAuthoritiesPopulator(key, configurationModelConfigurationAccessor, userAccessor);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) UserAccessor(com.synopsys.integration.alert.common.persistence.accessor.UserAccessor) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)47 Test (org.junit.jupiter.api.Test)40 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)25 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)19 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)18 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)15 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)14 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)13 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)11 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)10 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)7 DescriptorProcessor (com.synopsys.integration.alert.common.descriptor.DescriptorProcessor)7 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)7 FieldModelProcessor (com.synopsys.integration.alert.common.rest.FieldModelProcessor)7 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)7 SettingsDescriptorKey (com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey)7 SystemMessageAccessor (com.synopsys.integration.alert.common.persistence.accessor.SystemMessageAccessor)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ApiAction (com.synopsys.integration.alert.common.action.ApiAction)4