Search in sources :

Example 76 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method saveAllNotificationsTest.

@Test
void saveAllNotificationsTest() {
    OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime providerCreationTime = createdAt.minusSeconds(10);
    AlertNotificationModel alertNotificationModel = new AlertNotificationModel(null, providerConfigId, provider, providerConfigName, notificationType, content, createdAt, providerCreationTime, false);
    NotificationEntity notificationEntity = new NotificationEntity(id, createdAt, provider, providerConfigId, providerCreationTime, notificationType, content, false);
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.saveAll(Mockito.any())).thenReturn(List.of(notificationEntity));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    List<AlertNotificationModel> alertNotificationModelList = notificationManager.saveAllNotifications(List.of(alertNotificationModel));
    assertEquals(1, alertNotificationModelList.size());
    AlertNotificationModel testAlertNotificationModel = alertNotificationModelList.get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, testAlertNotificationModel);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) OffsetDateTime(java.time.OffsetDateTime) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Example 77 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method findByCreatedAtBetweenTest.

@Test
void findByCreatedAtBetweenTest() {
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    ConfigurationModel configurationModel = createConfigurationModel();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.findByCreatedAtBetween(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(new PageImpl<>(List.of(notificationEntity)));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    List<AlertNotificationModel> alertNotificationModelList = notificationManager.findByCreatedAtBetween(DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
    assertEquals(1, alertNotificationModelList.size());
    AlertNotificationModel alertNotificationModel = alertNotificationModelList.get(0);
    testExpectedAlertNotificationModel(expectedAlertNotificationModel, alertNotificationModel);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Example 78 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class DefaultNotificationAccessorTest method setNotificationsProcessedByIdTest.

@Test
void setNotificationsProcessedByIdTest() {
    NotificationEntity notificationEntity = new NotificationEntity(id, DateUtils.createCurrentDateTimestamp(), provider, providerConfigId, DateUtils.createCurrentDateTimestamp(), notificationType, content, false);
    ConfigurationModel configurationModel = createConfigurationModel();
    Set<Long> notificationIds = Set.of(1L);
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(notificationContentRepository.findAllById(Mockito.any())).thenReturn(List.of(notificationEntity));
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.any())).thenReturn(Optional.of(configurationModel));
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, null, configurationModelConfigurationAccessor);
    notificationManager.setNotificationsProcessedById(notificationIds);
    Mockito.verify(notificationContentRepository).setProcessedByIds(Mockito.any());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) Test(org.junit.jupiter.api.Test)

Example 79 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method getProviderConfigurationByNameTest.

@Test
public void getProviderConfigurationByNameTest() {
    final String providerConfigName = "provider-config-name-test";
    final String emptyProviderConfigName = "bad-config-name";
    final Long fieldId = 1L;
    final Long descriptorId = 4L;
    final Long configurationId = 6L;
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(fieldId);
    FieldValueEntity fieldValueEntity = new FieldValueEntity(2L, 3L, fieldValue);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 5L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, providerConfigName)).thenReturn(List.of(fieldValueEntity));
    Mockito.when(fieldValueRepository.findAllByFieldIdAndValue(fieldId, emptyProviderConfigName)).thenReturn(List.of());
    setupGetJobMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(null, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    Optional<ConfigurationModel> configurationModelOptional = configurationModelConfigurationAccessor.getProviderConfigurationByName(providerConfigName);
    Optional<ConfigurationModel> configurationModelProviderConfigsEmpty = configurationModelConfigurationAccessor.getProviderConfigurationByName(emptyProviderConfigName);
    assertTrue(configurationModelOptional.isPresent());
    assertFalse(configurationModelProviderConfigsEmpty.isPresent());
    ConfigurationModel configurationModel = configurationModelOptional.get();
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Example 80 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JiraCloudProcessorFactory method createJiraCloudProperties.

private JiraCloudProperties createJiraCloudProperties() throws AlertConfigurationException {
    ConfigurationModel jiraCloudGlobalConfig = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(jiraCloudChannelKey, ConfigContextEnum.GLOBAL).stream().findAny().orElseThrow(() -> new AlertConfigurationException("Missing Jira Cloud global configuration"));
    String jiraUrl = jiraCloudGlobalConfig.getField(JiraCloudDescriptor.KEY_JIRA_URL).flatMap(ConfigurationFieldModel::getFieldValue).orElse("");
    return JiraCloudProperties.fromConfig(jiraCloudGlobalConfig, proxyManager.createProxyInfoForHost(jiraUrl));
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Aggregations

ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)140 Test (org.junit.jupiter.api.Test)89 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)49 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)33 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)31 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)22 List (java.util.List)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)13 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)13 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)13 HashMap (java.util.HashMap)13 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)11 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)11 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)10 ArrayList (java.util.ArrayList)10 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9