Search in sources :

Example 6 with DescriptorTypeRepository

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

the class DefaultDescriptorAccessorTest method getFieldsForDescriptorTest.

@Test
public void getFieldsForDescriptorTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final ConfigContextEnum configContextEnum = ConfigContextEnum.GLOBAL;
    final ConfigContextEnum invalidConfigContextEnum = ConfigContextEnum.DISTRIBUTION;
    final String definedFieldsKey = "defined-field-key-test";
    Boolean isSensitive = Boolean.TRUE;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKey-test");
    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.findFirstByName(descriptorKey.getUniversalKey())).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(configContextRepository.findFirstByContext(configContextEnum.name())).thenReturn(Optional.of(configContextEntity));
    // Used to test the optional expression
    Mockito.when(configContextRepository.findFirstByContext(invalidConfigContextEnum.name())).thenReturn(Optional.empty());
    Mockito.when(configContextRepository.save(Mockito.any())).thenReturn(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.getFieldsForDescriptor(descriptorKey, configContextEnum);
    List<DefinedFieldModel> emptyConfigContextDefinedFieldModelList = descriptorAccessor.getFieldsForDescriptor(descriptorKey, invalidConfigContextEnum);
    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));
    assertEquals(1, emptyConfigContextDefinedFieldModelList.size());
    DefinedFieldModel emptyConfigContextDefinedFieldModel = emptyConfigContextDefinedFieldModelList.get(0);
    assertEquals(definedFieldsKey, emptyConfigContextDefinedFieldModel.getKey());
    assertEquals(isSensitive, emptyConfigContextDefinedFieldModel.getSensitive());
    List<ConfigContextEnum> configContextList2 = new ArrayList<>(emptyConfigContextDefinedFieldModel.getContexts());
    assertEquals(invalidConfigContextEnum, configContextList2.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) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) 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)

Example 7 with DescriptorTypeRepository

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

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorsTest.

@Test
public void getRegisteredDescriptorsTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final DescriptorType descriptorType = DescriptorType.CHANNEL;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name());
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findAll()).thenReturn(List.of(registeredDescriptorEntity));
    Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository);
    List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptors();
    assertEquals(1, registeredDescriptorModelList.size());
    RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelList.get(0);
    assertEquals(name, registeredDescriptorModel.getName());
    assertEquals(descriptorType, registeredDescriptorModel.getType());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity) RegisteredDescriptorModel(com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel) DescriptorTypeRepository(com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository) RegisteredDescriptorRepository(com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository) Test(org.junit.jupiter.api.Test)

Aggregations

RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)7 DescriptorTypeRepository (com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository)7 RegisteredDescriptorRepository (com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository)7 Test (org.junit.jupiter.api.Test)7 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)5 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)5 DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)5 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)2 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)2 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)2 ConfigContextRepository (com.synopsys.integration.alert.database.configuration.repository.ConfigContextRepository)2 DefinedFieldRepository (com.synopsys.integration.alert.database.configuration.repository.DefinedFieldRepository)2 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)2 ArrayList (java.util.ArrayList)2