Search in sources :

Example 6 with DescriptorTypeEntity

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

the class DefaultDescriptorAccessorTest method getRegisteredDescriptorsByTypeMissingDescriptorTypeTest.

@Test
public void getRegisteredDescriptorsByTypeMissingDescriptorTypeTest() {
    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.empty());
    Mockito.when(descriptorTypeRepository.save(Mockito.any())).thenReturn(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)

Example 7 with DescriptorTypeEntity

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

Example 8 with DescriptorTypeEntity

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

the class DescriptorMocker method registerDescriptor.

public void registerDescriptor(String descriptorName, DescriptorType type) {
    Optional<Long> optionalTypeId = descriptorTypeRepository.findFirstByType(type.name()).map(DatabaseEntity::getId);
    Long typeId;
    if (optionalTypeId.isPresent()) {
        typeId = optionalTypeId.get();
    } else {
        typeId = descriptorTypeRepository.save(new DescriptorTypeEntity(type.name())).getId();
    }
    registeredDescriptorRepository.save(new RegisteredDescriptorEntity(descriptorName, typeId)).getId();
}
Also used : RegisteredDescriptorEntity(com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity) DescriptorTypeEntity(com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity) DatabaseEntity(com.synopsys.integration.alert.database.DatabaseEntity)

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