Search in sources :

Example 1 with ProviderDataAccessor

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

the class BlackDuckDistributionFieldModelTestActionTest method createTestAction.

private BlackDuckDistributionFieldModelTestAction createTestAction() {
    ProviderDataAccessor providerDataAccessor = createProviderDataAccessor();
    ConfigurationModelConfigurationAccessor configurationAccessor = createConfigurationAccessor();
    return new BlackDuckDistributionFieldModelTestAction(providerDataAccessor, null, configurationAccessor);
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)

Example 2 with ProviderDataAccessor

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

the class EmailTestActionHelperTest method verifyProjectsRetrievedWithOnlyVersionPattern.

@Test
public void verifyProjectsRetrievedWithOnlyVersionPattern() throws AlertException {
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    List<ProviderProject> providerProjects = createProviderProjects();
    Mockito.when(providerDataAccessor.getProjectsByProviderConfigId(Mockito.anyLong())).thenReturn(providerProjects);
    Mockito.when(providerDataAccessor.getEmailAddressesForProjectHref(Mockito.anyLong(), Mockito.anyString())).thenAnswer(i -> Set.of(UUID.randomUUID().toString()));
    Mockito.when(providerDataAccessor.getProjectVersionNamesByHref(Mockito.anyLong(), Mockito.anyString(), Mockito.anyInt())).thenReturn(getProjectVersions());
    EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
    DistributionJobModel distributionJobModel = createDistributionJobModel(createDefaultEmailJobDetails(), null, "1.0.*", List.of());
    Set<String> emailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(distributionJobModel);
    assertEquals(providerProjects.size(), emailAddresses.size());
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 3 with ProviderDataAccessor

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

the class JobEmailAddressValidatorTest method validateTest.

@Test
public void validateTest() {
    UUID testJobId = UUID.randomUUID();
    Long testBlackDuckGlobalConfigId = 33L;
    String testValidEmailAddress1 = "valid1";
    String testValidEmailAddress2 = "valid2";
    String testValidEmailAddress3 = "valid3";
    String testInvalidEmailAddress1 = "invalid1";
    String testInvalidEmailAddress2 = "invalid2";
    Set<String> testEmailAddresses = Set.of(testValidEmailAddress1, testInvalidEmailAddress1, testValidEmailAddress2, testInvalidEmailAddress2, testValidEmailAddress3);
    DistributionJobModel distributionJobModel = Mockito.mock(DistributionJobModel.class);
    Mockito.when(distributionJobModel.getBlackDuckGlobalConfigId()).thenReturn(testBlackDuckGlobalConfigId);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    Mockito.when(jobAccessor.getJobById(testJobId)).thenReturn(Optional.of(distributionJobModel));
    ProviderUserModel providerUserModel = Mockito.mock(ProviderUserModel.class);
    Optional<ProviderUserModel> optionalProviderUser = Optional.of(providerUserModel);
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    Mockito.when(providerDataAccessor.findFirstUserByEmailAddress(testBlackDuckGlobalConfigId, testValidEmailAddress1)).thenReturn(optionalProviderUser);
    Mockito.when(providerDataAccessor.findFirstUserByEmailAddress(testBlackDuckGlobalConfigId, testValidEmailAddress2)).thenReturn(optionalProviderUser);
    Mockito.when(providerDataAccessor.findFirstUserByEmailAddress(testBlackDuckGlobalConfigId, testValidEmailAddress3)).thenReturn(optionalProviderUser);
    Mockito.when(providerDataAccessor.findFirstUserByEmailAddress(testBlackDuckGlobalConfigId, testInvalidEmailAddress1)).thenReturn(Optional.empty());
    Mockito.when(providerDataAccessor.findFirstUserByEmailAddress(testBlackDuckGlobalConfigId, testInvalidEmailAddress2)).thenReturn(Optional.empty());
    JobEmailAddressValidator validator = new JobEmailAddressValidator(jobAccessor, providerDataAccessor);
    ValidatedEmailAddresses validatedEmailAddresses = validator.validate(testJobId, testEmailAddresses);
    Set<String> validEmailAddresses = validatedEmailAddresses.getValidEmailAddresses();
    assertEquals(3, validEmailAddresses.size());
    assertValid(validEmailAddresses, testValidEmailAddress1);
    assertValid(validEmailAddresses, testValidEmailAddress2);
    assertValid(validEmailAddresses, testValidEmailAddress3);
    Set<String> invalidEmailAddresses = validatedEmailAddresses.getInvalidEmailAddresses();
    assertEquals(2, invalidEmailAddresses.size());
    assertInvalid(invalidEmailAddresses, testInvalidEmailAddress1);
    assertInvalid(invalidEmailAddresses, testInvalidEmailAddress2);
}
Also used : JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) UUID(java.util.UUID) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 4 with ProviderDataAccessor

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

the class EmailTestActionHelperTest method verifyAllProjectsProperlyRetrieved.

@Test
public void verifyAllProjectsProperlyRetrieved() throws AlertException {
    ProviderDataAccessor providerDataAccessor = Mockito.mock(ProviderDataAccessor.class);
    List<ProviderProject> providerProjects = createProviderProjects();
    Mockito.when(providerDataAccessor.getProjectsByProviderConfigId(Mockito.anyLong())).thenReturn(providerProjects);
    Mockito.when(providerDataAccessor.getEmailAddressesForProjectHref(Mockito.anyLong(), Mockito.anyString())).thenAnswer(i -> Set.of(UUID.randomUUID().toString()));
    EmailTestActionHelper emailTestActionHelper = new EmailTestActionHelper(providerDataAccessor);
    DistributionJobModel distributionJobModel = createDefaultDistributionJobModel();
    Set<String> emailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(distributionJobModel);
    assertEquals(providerProjects.size(), emailAddresses.size());
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 5 with ProviderDataAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor 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)

Aggregations

ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)6 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)3 Test (org.junit.jupiter.api.Test)3 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)2 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)2 ProviderSchedulingManager (com.synopsys.integration.alert.api.provider.lifecycle.ProviderSchedulingManager)1 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)1 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)1 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)1 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)1 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)1 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)1 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)1 BlackDuckCacheHttpClientCache (com.synopsys.integration.alert.provider.blackduck.BlackDuckCacheHttpClientCache)1 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)1 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)1 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)1 BlackDuckDataSyncTask (com.synopsys.integration.alert.provider.blackduck.task.BlackDuckDataSyncTask)1