Search in sources :

Example 1 with DescriptorTypeRepository

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

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

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

Example 4 with DescriptorTypeRepository

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

Example 5 with DescriptorTypeRepository

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

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