Search in sources :

Example 1 with DescriptorTypeEntity

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

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorByKeyTest.

@Test
public void getRegisteredDescriptorByKeyTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final DescriptorType descriptorType = DescriptorType.CHANNEL;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorKey descriptorKey = createDescriptorKey("descriptorKey-test");
    DescriptorKey emptyDescriptorKey = createDescriptorKey("bad-key");
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name());
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findFirstByName(descriptorKey.getUniversalKey())).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(registeredDescriptorRepository.findFirstByName(emptyDescriptorKey.getUniversalKey())).thenReturn(Optional.empty());
    Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository);
    Optional<RegisteredDescriptorModel> registeredDescriptorModelOptional = descriptorAccessor.getRegisteredDescriptorByKey(descriptorKey);
    Optional<RegisteredDescriptorModel> registeredDescriptorModelOptionalEmpty = descriptorAccessor.getRegisteredDescriptorByKey(emptyDescriptorKey);
    assertTrue(registeredDescriptorModelOptional.isPresent());
    RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelOptional.get();
    assertFalse(registeredDescriptorModelOptionalEmpty.isPresent());
    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) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) 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)

Example 2 with DescriptorTypeEntity

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

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorByIdTest.

@Test
public void getRegisteredDescriptorByIdTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final DescriptorType descriptorType = DescriptorType.CHANNEL;
    final Long descriptorId = 2L;
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name());
    descriptorTypeEntity.setId(2L);
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    Mockito.when(registeredDescriptorRepository.findById(descriptorId)).thenReturn(Optional.of(registeredDescriptorEntity));
    Mockito.when(descriptorTypeRepository.findById(Mockito.any())).thenReturn(Optional.of(descriptorTypeEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository);
    Optional<RegisteredDescriptorModel> registeredDescriptorModelOptional = descriptorAccessor.getRegisteredDescriptorById(descriptorId);
    assertTrue(registeredDescriptorModelOptional.isPresent());
    RegisteredDescriptorModel registeredDescriptorModel = registeredDescriptorModelOptional.get();
    assertEquals(typeId, registeredDescriptorModel.getId());
    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)

Example 3 with DescriptorTypeEntity

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

the class DefaultDescriptorAccessor method saveDescriptorTypeAndReturnId.

private Long saveDescriptorTypeAndReturnId(DescriptorType descriptorType) {
    String descriptorTypeString = descriptorType.name();
    Optional<Long> optionalDescriptorType = descriptorTypeRepository.findFirstByType(descriptorTypeString).map(DescriptorTypeEntity::getId);
    if (optionalDescriptorType.isPresent()) {
        return optionalDescriptorType.get();
    }
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorTypeString);
    DescriptorTypeEntity savedDescriptorTypeEntity = descriptorTypeRepository.save(descriptorTypeEntity);
    return savedDescriptorTypeEntity.getId();
}
Also used : DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)

Example 4 with DescriptorTypeEntity

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

the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorTypeTest.

@Test
public void getConfigurationsByDescriptorTypeTest() {
    final Long descriptorId = 3L;
    final Long configurationId = 5L;
    DescriptorType descriptorType = DescriptorType.CHANNEL;
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity("CHANNEL");
    descriptorTypeEntity.setId(1L);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name-test", 1L);
    registeredDescriptorEntity.setId(2L);
    DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
    descriptorConfigEntity.setId(configurationId);
    ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
    FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
    DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
    definedFieldEntity.setId(8L);
    Mockito.when(descriptorConfigRepository.findByDescriptorType(Mockito.eq(descriptorType.name()))).thenReturn(List.of(descriptorConfigEntity));
    setupCreatConfigMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
    List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(descriptorType);
    assertEquals(1, configurationModelList.size());
    ConfigurationModel configurationModel = configurationModelList.get(0);
    testConfigurationModel(configurationId, descriptorId, configurationModel);
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity) DefinedFieldEntity(com.synopsys.integration.alert.database.configuration.DefinedFieldEntity) ConfigContextEntity(com.synopsys.integration.alert.database.configuration.ConfigContextEntity) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) Test(org.junit.jupiter.api.Test)

Example 5 with DescriptorTypeEntity

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

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorsByTypeTest.

@Test
public void getRegisteredDescriptorsByTypeTest() {
    final String name = "name-test";
    final Long typeId = 1L;
    final DescriptorType descriptorType = DescriptorType.CHANNEL;
    RegisteredDescriptorRepository registeredDescriptorRepository = Mockito.mock(RegisteredDescriptorRepository.class);
    DescriptorTypeRepository descriptorTypeRepository = Mockito.mock(DescriptorTypeRepository.class);
    RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(name, typeId);
    registeredDescriptorEntity.setId(1L);
    DescriptorTypeEntity descriptorTypeEntity = new DescriptorTypeEntity(descriptorType.name());
    descriptorTypeEntity.setId(1L);
    Mockito.when(descriptorTypeRepository.findFirstByType(descriptorType.name())).thenReturn(Optional.of(descriptorTypeEntity));
    Mockito.when(registeredDescriptorRepository.findByTypeId(Mockito.any())).thenReturn(List.of(registeredDescriptorEntity));
    Mockito.when(descriptorTypeRepository.findById(registeredDescriptorEntity.getTypeId())).thenReturn(Optional.of(descriptorTypeEntity));
    DefaultDescriptorAccessor descriptorAccessor = new DefaultDescriptorAccessor(registeredDescriptorRepository, null, null, descriptorTypeRepository);
    List<RegisteredDescriptorModel> registeredDescriptorModelList = descriptorAccessor.getRegisteredDescriptorsByType(descriptorType);
    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

DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)8 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)7 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)6 Test (org.junit.jupiter.api.Test)6 RegisteredDescriptorModel (com.synopsys.integration.alert.common.persistence.model.RegisteredDescriptorModel)5 DescriptorTypeRepository (com.synopsys.integration.alert.database.configuration.repository.DescriptorTypeRepository)5 RegisteredDescriptorRepository (com.synopsys.integration.alert.database.configuration.repository.RegisteredDescriptorRepository)5 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 DatabaseEntity (com.synopsys.integration.alert.database.DatabaseEntity)1 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)1 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)1 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)1 FieldValueEntity (com.synopsys.integration.alert.database.configuration.FieldValueEntity)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1