Search in sources :

Example 1 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType 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 2 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType 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 3 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType 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 4 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType in project hub-alert by blackducksoftware.

the class DescriptorMetadataActionsTest method getDescriptorsWithAllParametersTest.

@Test
public void getDescriptorsWithAllParametersTest() {
    DescriptorType type1 = DescriptorType.CHANNEL;
    String componentName1 = getNamePrefix(type1) + "_2";
    ConfigContextEnum context1 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response1 = actions.getDescriptorsByPermissions(componentName1, type1.name(), context1.name());
    assertTrue(response1.isSuccessful());
    assertTrue(response1.hasContent());
    Set<DescriptorMetadata> descriptorMetadata1 = response1.getContent().get().getDescriptors();
    assertEquals(1, descriptorMetadata1.size());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test)

Example 5 with DescriptorType

use of com.synopsys.integration.alert.common.enumeration.DescriptorType 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

DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)8 Test (org.junit.jupiter.api.Test)8 DescriptorTypeEntity (com.synopsys.integration.alert.database.configuration.DescriptorTypeEntity)6 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)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 DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)2 DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)2 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)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