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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations