Search in sources :

Example 1 with ConfigContextEntity

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

the class ConfigContextTestIT method findFirstByContextTest.

@Test
public void findFirstByContextTest() {
    String context = ConfigContextEnum.GLOBAL.name();
    ConfigContextEntity configContextEntity = new ConfigContextEntity(context);
    configContextRepository.save(configContextEntity);
    assertEquals(1, configContextRepository.findAll().size());
    Optional<ConfigContextEntity> optionalConfigContextEntity = configContextRepository.findFirstByContext(context);
    assertTrue(optionalConfigContextEntity.isPresent());
    assertEquals(context, optionalConfigContextEntity.get().getContext());
}
Also used : ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ConfigContextEntity

use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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 ConfigContextEntity

use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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 ConfigContextEntity

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

the class FieldContextRepositoryTestIT method findByContextId.

@Test
public void findByContextId() {
    DefinedFieldEntity definedFieldEntity1 = new DefinedFieldEntity(FIELD_KEY_1, Boolean.FALSE);
    DefinedFieldEntity definedFieldEntity2 = new DefinedFieldEntity(FIELD_KEY_2, Boolean.FALSE);
    DefinedFieldEntity savedFieldEntity1 = definedFieldRepository.save(definedFieldEntity1);
    DefinedFieldEntity savedFieldEntity2 = definedFieldRepository.save(definedFieldEntity2);
    assertEquals(2, definedFieldRepository.findAll().size());
    ConfigContextEntity configContextEntity1 = new ConfigContextEntity(CONTEXT_NAME);
    ConfigContextEntity configContextEntity2 = new ConfigContextEntity(CONTEXT_NAME + "2");
    ConfigContextEntity savedContextEntity1 = configContextRepository.save(configContextEntity1);
    ConfigContextEntity savedContextEntity2 = configContextRepository.save(configContextEntity2);
    assertEquals(2, configContextRepository.findAll().size());
    FieldContextRelation fieldContextRelation1 = new FieldContextRelation(savedFieldEntity1.getId(), savedContextEntity1.getId());
    FieldContextRelation fieldContextRelation2 = new FieldContextRelation(savedFieldEntity1.getId(), savedContextEntity2.getId());
    FieldContextRelation fieldContextRelation3 = new FieldContextRelation(savedFieldEntity2.getId(), savedContextEntity1.getId());
    fieldContextRepository.save(fieldContextRelation1);
    fieldContextRepository.save(fieldContextRelation2);
    fieldContextRepository.save(fieldContextRelation3);
    assertEquals(3, fieldContextRepository.findAll().size());
    List<FieldContextRelation> foundList1 = fieldContextRepository.findByContextId(savedContextEntity1.getId());
    assertEquals(2, foundList1.size());
    List<FieldContextRelation> foundList2 = fieldContextRepository.findByContextId(savedContextEntity2.getId());
    assertEquals(1, foundList2.size());
}
Also used : FieldContextRelation(com.synopsys.integration.alert.database.configuration.FieldContextRelation) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with ConfigContextEntity

use of com.synopsys.integration.alert.database.configuration.ConfigContextEntity 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)

Aggregations

ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)25 Test (org.junit.jupiter.api.Test)20 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)17 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)14 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)13 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)8 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)8 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)7 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)5 PermissionMatrixRelation (com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation)5 OffsetDateTime (java.time.OffsetDateTime)5 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)3 FieldContextRelation (com.synopsys.integration.alert.database.configuration.FieldContextRelation)3 ConfigContextRepository (com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository)3 RegisteredDescriptorRepository (com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository)3 RoleEntity (com.synopsys.integration.alert.database.user.RoleEntity)3 ArrayList (java.util.ArrayList)3