Search in sources :

Example 1 with DefinedFieldEntity

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

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

the class DescriptorFieldRepositoryTestIT method findByDescriptorIdTest.

@Test
public void findByDescriptorIdTest() {
    RegisteredDescriptorEntity registeredDescriptorEntity1 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME_1, 1L);
    RegisteredDescriptorEntity registeredDescriptorEntity2 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME_2, 1L);
    RegisteredDescriptorEntity savedRegisteredDescriptorEntity1 = registeredDescriptorRepository.save(registeredDescriptorEntity1);
    RegisteredDescriptorEntity savedRegisteredDescriptorEntity2 = registeredDescriptorRepository.save(registeredDescriptorEntity2);
    assertEquals(2, registeredDescriptorRepository.findAll().size());
    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());
    DescriptorFieldRelation descriptorFieldRelation1 = new DescriptorFieldRelation(savedRegisteredDescriptorEntity1.getId(), savedFieldEntity1.getId());
    DescriptorFieldRelation descriptorFieldRelation2 = new DescriptorFieldRelation(savedRegisteredDescriptorEntity1.getId(), savedFieldEntity2.getId());
    DescriptorFieldRelation descriptorFieldRelation3 = new DescriptorFieldRelation(savedRegisteredDescriptorEntity2.getId(), savedFieldEntity1.getId());
    descriptorFieldRepository.save(descriptorFieldRelation1);
    descriptorFieldRepository.save(descriptorFieldRelation2);
    descriptorFieldRepository.save(descriptorFieldRelation3);
    // Should find a relation to field 1 and 2
    List<DescriptorFieldRelation> foundList1 = descriptorFieldRepository.findByDescriptorId(savedRegisteredDescriptorEntity1.getId());
    assertEquals(2, foundList1.size());
    // Should find a relation to field 1
    List<DescriptorFieldRelation> foundList2 = descriptorFieldRepository.findByDescriptorId(savedRegisteredDescriptorEntity2.getId());
    assertEquals(1, foundList2.size());
}
Also used : DescriptorFieldRelation(com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with DefinedFieldEntity

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

the class DescriptorFieldRepositoryTestIT method findByFieldIdTest.

@Test
public void findByFieldIdTest() {
    RegisteredDescriptorEntity registeredDescriptorEntity1 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME_1, 1L);
    RegisteredDescriptorEntity registeredDescriptorEntity2 = new RegisteredDescriptorEntity(DESCRIPTOR_NAME_2, 1L);
    RegisteredDescriptorEntity savedRegisteredDescriptorEntity1 = registeredDescriptorRepository.save(registeredDescriptorEntity1);
    RegisteredDescriptorEntity savedRegisteredDescriptorEntity2 = registeredDescriptorRepository.save(registeredDescriptorEntity2);
    assertEquals(2, registeredDescriptorRepository.findAll().size());
    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());
    DescriptorFieldRelation descriptorFieldRelation1 = new DescriptorFieldRelation(savedRegisteredDescriptorEntity1.getId(), savedFieldEntity1.getId());
    DescriptorFieldRelation descriptorFieldRelation2 = new DescriptorFieldRelation(savedRegisteredDescriptorEntity1.getId(), savedFieldEntity2.getId());
    DescriptorFieldRelation descriptorFieldRelation3 = new DescriptorFieldRelation(savedRegisteredDescriptorEntity2.getId(), savedFieldEntity1.getId());
    descriptorFieldRepository.save(descriptorFieldRelation1);
    descriptorFieldRepository.save(descriptorFieldRelation2);
    descriptorFieldRepository.save(descriptorFieldRelation3);
    // Should find a relation to descriptor 1 and 2
    List<DescriptorFieldRelation> foundList1 = descriptorFieldRepository.findByFieldId(savedFieldEntity1.getId());
    assertEquals(2, foundList1.size());
    // Should find a relation to descriptor 1
    List<DescriptorFieldRelation> foundList2 = descriptorFieldRepository.findByFieldId(savedFieldEntity2.getId());
    assertEquals(1, foundList2.size());
}
Also used : DescriptorFieldRelation(com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with DefinedFieldEntity

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

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

the class DefaultDescriptorAccessorTest method getFieldsForDescriptorByIdTest.

@Test
public void getFieldsForDescriptorByIdTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL;
    final String definedFieldsKey = "defined-field-key-test";
    Boolean isSensitive = Boolean.TRUE;
    final Long descriptorId = 1L;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    configContextEntity.setId(3L);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(definedFieldsKey, isSensitive);
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DefinedFieldRepository definedFieldRepository = Mockito.mock(DefinedFieldRepository.class);
    ConfigContextRepository configContextRepository = Mockito.mock(ConfigContextRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findById(descriptorId)).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity));
    Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, definedFieldRepository, configContextRepository, descriptorTypeRepository);
    List<DefinedFieldModel> definedFieldModelList = descriptorAccessor.getFieldsForDescriptorById(descriptorId, configContextEnum);
    assertEquals(1, definedFieldModelList.size());
    DefinedFieldModel definedFieldModel = definedFieldModelList.get(0);
    assertEquals(definedFieldsKey, definedFieldModel.getKey());
    assertEquals(isSensitive, definedFieldModel.getSensitive());
    List<ConfigContextEnum> configContextList = new ArrayList<>(definedFieldModel.getContexts());
    assertEquals(configContextEnum, configContextList.get(0));
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) ArrayList(java.util.ArrayList) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) DefinedFieldRepository(com.synopsys.integration.alert.database.configuration.repository.DefinedFieldRepository) ConfigContextRepository(com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository) DescriptorTypeRepository(com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) RegisteredDescriptorRepository(com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) Test(org.junit.jupiter.api.Test)

Aggregations

DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)20 Test (org.junit.jupiter.api.Test)17 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)14 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)10 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)8 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)7 DescriptorFieldRelation (com.synopsys.integration.alert.database.configuration.DescriptorFieldRelation)6 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)3 FieldContextRelation (com.synopsys.integration.alert.database.configuration.FieldContextRelation)3 OffsetDateTime (java.time.OffsetDateTime)3 ArrayList (java.util.ArrayList)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)2 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)2 ConfigContextRepository (com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository)2