Search in sources :

Example 1 with DescriptorConfigEntity

use of com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity in project hub-alert by blackducksoftware.

the class NotificationContentRepositoryTestIT method findByProcessedFalseOrderByProviderCreationTimeAscTestIT.

@Test
@Transactional
public void findByProcessedFalseOrderByProviderCreationTimeAscTestIT() {
    // Create provider config (required for FK constraint)
    DescriptorConfigEntity providerConfig = createProviderConfig();
    Long providerConfigId = providerConfig.getId();
    // Create notifications
    OffsetDateTime now = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime fiveSecondsAgo = now.minusSeconds(5L);
    OffsetDateTime threeHoursAgo = now.minusHours(3L);
    OffsetDateTime twoDaysAgo = now.minusDays(2L);
    NotificationEntity firstAsc = createNotification(providerConfigId, twoDaysAgo);
    NotificationEntity secondAsc = createNotification(providerConfigId, threeHoursAgo);
    NotificationEntity thirdAsc = createNotification(providerConfigId, fiveSecondsAgo);
    NotificationEntity fourthAsc = createNotification(providerConfigId, now);
    // Begin test...
    // Insert notifications out of order
    notificationContentRepository.saveAll(List.of(secondAsc, firstAsc, fourthAsc, thirdAsc));
    int pageSize = 2;
    PageRequest firstPageRequest = PageRequest.of(0, pageSize);
    Page<NotificationEntity> firstPage = notificationContentRepository.findByProcessedFalseOrderByProviderCreationTimeAsc(firstPageRequest);
    assertPage(firstPage, pageSize);
    PageRequest secondPageRequest = PageRequest.of(1, pageSize);
    Page<NotificationEntity> secondPage = notificationContentRepository.findByProcessedFalseOrderByProviderCreationTimeAsc(secondPageRequest);
    assertPage(secondPage, pageSize);
    NotificationEntity firstElement = firstPage.stream().findFirst().orElseThrow();
    NotificationEntity lastElement = secondPage.stream().min(Comparator.comparing(NotificationEntity::getProviderCreationTime)).orElseThrow();
    assertTime(firstElement, lastElement);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) OffsetDateTime(java.time.OffsetDateTime) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DescriptorConfigEntity

use of com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity in project hub-alert by blackducksoftware.

the class ConfigContextTestIT method onDeleteCascade.

@Test
public void onDeleteCascade() {
    String context = ConfigContextEnum.GLOBAL.name();
    ConfigContextEntity configContextEntity = new ConfigContextEntity(context);
    ConfigContextEntity savedConfigContextEntity = configContextRepository.save(configContextEntity);
    assertEquals(1, configContextRepository.findAll().size());
    final String descriptorName = "test descriptor";
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(descriptorName, 1L);
    RegisteredDescriptorEntity savedRegisteredDescriptorEntity = registeredDescriptorRepository.save(registeredDescriptorEntity);
    assertEquals(1, registeredDescriptorRepository.findAll().size());
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(savedRegisteredDescriptorEntity.getId(), savedConfigContextEntity.getId(), currentTime, currentTime);
    descriptorConfigRepository.save(descriptorConfigEntity);
    assertEquals(1, descriptorConfigRepository.findAll().size());
    configContextRepository.deleteById(savedConfigContextEntity.getId());
    configContextRepository.flush();
    assertEquals(0, descriptorConfigRepository.findAll().size());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with DescriptorConfigEntity

use of com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity in project hub-alert by blackducksoftware.

the class DescriptorConfigRepositoryTestIT method onDeleteCascadeTest.

@Test
public void onDeleteCascadeTest() {
    RegisteredDescriptorEntity descriptorEntity1 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME, 1L);
    RegisteredDescriptorEntity descriptorEntity2 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME + "2", 1L);
    RegisteredDescriptorEntity savedDescriptorEntity1 = registeredDescriptorRepository.save(descriptorEntity1);
    RegisteredDescriptorEntity savedDescriptorEntity2 = registeredDescriptorRepository.save(descriptorEntity2);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity savedContextEntity = configContextRepository.save(configContextEntity);
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    DescriptorConfigEntity descriptorFieldEntity1 = new DescriptorConfigEntity(savedDescriptorEntity1.getId(), savedContextEntity.getId(), currentTime, currentTime);
    DescriptorConfigEntity descriptorFieldEntity2 = new DescriptorConfigEntity(savedDescriptorEntity2.getId(), savedContextEntity.getId(), currentTime, currentTime);
    descriptorConfigRepository.save(descriptorFieldEntity1);
    descriptorConfigRepository.save(descriptorFieldEntity2);
    assertEquals(2, descriptorConfigRepository.findAll().size());
    registeredDescriptorRepository.deleteById(savedDescriptorEntity1.getId());
    registeredDescriptorRepository.flush();
    assertEquals(1, descriptorConfigRepository.findAll().size());
    configContextRepository.deleteById(savedContextEntity.getId());
    configContextRepository.flush();
    assertEquals(0, descriptorConfigRepository.findAll().size());
}
Also used : OffsetDateTime(java.time.OffsetDateTime) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with DescriptorConfigEntity

use of com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessorTest method createConfigurationTest.

@Test
public void createConfigurationTest() {
    final Long descriptorId = 3L;
    final Long configurationId = 5L;
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create("channel.common.name");
    configurationFieldModel.setFieldValue(fieldValue);
    List<ConfigurationFieldModel> configuredFields = List.of(configurationFieldModel);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
    registeredDescriptorEntity.setId(descriptorId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    configContextEntity.setId(3L);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(4L);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(5L, 6L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
    Mockito.when(descriptorConfigRepository.save(Mockito.any())).thenReturn(descriptorConfigEntity);
    Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, null);
    ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, configContextEnum, configuredFields);
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Example 5 with DescriptorConfigEntity

use of com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity in project hub-alert by blackducksoftware.

the class DefaultConfigurationModelConfigurationAccessor method createConfigModels.

private List<ConfigurationModel> createConfigModels(Collection<RegisteredDescriptorEntity> descriptors) {
    List<ConfigurationModel> configs = new ArrayList<>();
    for (RegisteredDescriptorEntity descriptorEntity : descriptors) {
        List<DescriptorConfigEntity> descriptorConfigEntities = descriptorConfigsRepository.findByDescriptorId(descriptorEntity.getId());
        for (DescriptorConfigEntity descriptorConfigEntity : descriptorConfigEntities) {
            ConfigurationModel newModel = createConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId());
            configs.add(newModel);
        }
    }
    return configs;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)

Aggregations

DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)19 Test (org.junit.jupiter.api.Test)14 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)13 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)10 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)7 OffsetDateTime (java.time.OffsetDateTime)7 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)5 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 ArrayList (java.util.ArrayList)4 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)2 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)2 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)1 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)1 DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)1 PageRequest (org.springframework.data.domain.PageRequest)1