Search in sources :

Example 1 with ConfigurationModelConfigurationAccessor

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

the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelActionNull.

@Test
public void testGetFieldModelActionNull() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), Map.of());
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    ApiAction apiAction = Mockito.mock(ApiAction.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    Mockito.when(converter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(apiAction.afterGetAction(Mockito.eq(fieldModel))).thenReturn(null);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, apiAction, converter);
    Optional<FieldModel> actualFieldModel = configUtility.getFieldModel();
    assertFalse(actualFieldModel.isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ApiAction(com.synopsys.integration.alert.common.action.ApiAction) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigurationModelConfigurationAccessor

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

the class DefaultDescriptorGlobalConfigUtilityTest method testGetConfiguration.

@Test
public void testGetConfiguration() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, null);
    assertFalse(configUtility.getConfiguration().isPresent());
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(DescriptorKey.class), Mockito.any(ConfigContextEnum.class))).thenReturn(List.of(configurationModel));
    assertTrue(configUtility.getConfiguration().isPresent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 3 with ConfigurationModelConfigurationAccessor

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

the class DefaultDescriptorGlobalConfigUtilityTest method testGetFieldModelEmptyConfiguration.

@Test
public void testGetFieldModelEmptyConfiguration() throws Exception {
    DescriptorKey descriptorKey = createDescriptorKey();
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ConfigurationFieldModelConverter converter = Mockito.mock(ConfigurationFieldModelConverter.class);
    DefaultDescriptorGlobalConfigUtility configUtility = new DefaultDescriptorGlobalConfigUtility(descriptorKey, configurationModelConfigurationAccessor, null, converter);
    assertFalse(configUtility.getFieldModel().isPresent());
}
Also used : DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) Test(org.junit.jupiter.api.Test)

Example 4 with ConfigurationModelConfigurationAccessor

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

the class DefaultRestApiAuditAccessorTest method convertToAuditEntryModelFromNotificationTest.

@Test
public void convertToAuditEntryModelFromNotificationTest() throws Exception {
    Long id = 1L;
    Long providerConfigId = 2L;
    String provider = "provider-test";
    String providerConfigName = "providerConfigName-test";
    String notificationType = "notificationType-test";
    String content = "content-test";
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusSeconds(10);
    Long auditEntryId = 3L;
    String channelName = "test-channel.common.name-value";
    String eventType = "test-channel.common.channel.name-value";
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
    AlertNotificationModel alertNotificationModel = new AlertNotificationModel(id, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryId, alertNotificationModel.getId());
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), timeCreated, timeLastSent, AuditEntryStatus.SUCCESS.name(), null, null);
    Mockito.when(auditNotificationRepository.findByNotificationId(Mockito.any())).thenReturn(List.of(auditNotificationRelation));
    Mockito.when(auditEntryRepository.findAllById(Mockito.any())).thenReturn(List.of(auditEntryEntity));
    DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("test-channel.common.channel.name-value").name("test-channel.common.name-value").distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of(NotificationType.LICENSE_LIMIT.name())).processingType(ProcessingType.DEFAULT).createdAt(DateUtils.createCurrentDateTimestamp()).build();
    Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(distributionJob));
    DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, null, contentConverter);
    AuditEntryModel testAuditEntryModel = auditUtility.convertToAuditEntryModelFromNotification(alertNotificationModel);
    assertEquals(id, Long.valueOf(testAuditEntryModel.getId()));
    assertNotNull(testAuditEntryModel.getNotification());
    assertFalse(testAuditEntryModel.getJobs().isEmpty());
    assertEquals(1, testAuditEntryModel.getJobs().size());
    JobAuditModel testJob = testAuditEntryModel.getJobs().get(0);
    assertEquals(channelName, testJob.getName());
    assertEquals(eventType, testJob.getEventType());
    assertEquals(AuditEntryStatus.SUCCESS.getDisplayName(), testAuditEntryModel.getOverallStatus());
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testAuditEntryModel.getLastSent());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) JobAuditModel(com.synopsys.integration.alert.common.rest.model.JobAuditModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) ContentConverter(com.synopsys.integration.alert.common.ContentConverter) AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) JobAccessor(com.synopsys.integration.alert.common.persistence.accessor.JobAccessor) OffsetDateTime(java.time.OffsetDateTime) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuditEntryModel(com.synopsys.integration.alert.common.persistence.model.AuditEntryModel) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigurationModelConfigurationAccessor

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

the class DefaultNotificationAccessorTest method getPageRequestForNotificationsTest.

@Test
void getPageRequestForNotificationsTest() {
    final int pageNumber = 1;
    final int pageSize = 1;
    final String sortField = "content";
    String sortOrder = Sort.Direction.ASC.name();
    NotificationContentRepository notificationContentRepository = Mockito.mock(NotificationContentRepository.class);
    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    DefaultNotificationAccessor notificationManager = new DefaultNotificationAccessor(notificationContentRepository, auditEntryRepository, configurationModelConfigurationAccessor);
    PageRequest pageRequest = notificationManager.getPageRequestForNotifications(pageNumber, pageSize, sortField, sortOrder);
    assertEquals(pageNumber, pageRequest.getPageNumber());
    assertEquals(pageSize, pageRequest.getPageSize());
}
Also used : AuditEntryRepository(com.synopsys.integration.alert.database.audit.AuditEntryRepository) PageRequest(org.springframework.data.domain.PageRequest) AuditNotificationRepository(com.synopsys.integration.alert.database.audit.AuditNotificationRepository) NotificationContentRepository(com.synopsys.integration.alert.database.notification.NotificationContentRepository) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) Test(org.junit.jupiter.api.Test)

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