use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method createConfigurationTest.
@Test
public void createConfigurationTest() {
final Long descriptorId = 3L;
final Long configurationId = 5L;
DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create("channel.common.name");
configurationFieldModel.setFieldValue(fieldValue);
List<ConfigurationFieldModel> configuredFields = List.of(configurationFieldModel);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
registeredDescriptorEntity.setId(descriptorId);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
configContextEntity.setId(3L);
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
definedFieldEntity.setId(4L);
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(5L, 6L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(definedFieldRepository.findByDescriptorIdAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(definedFieldEntity));
Mockito.when(descriptorConfigRepository.save(Mockito.any())).thenReturn(descriptorConfigEntity);
Mockito.when(definedFieldRepository.findFirstByKey(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, null);
ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, configContextEnum, configuredFields);
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey 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.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorKeyTest.
@Test
public void getConfigurationsByDescriptorKeyTest() {
final Long descriptorId = 3L;
final Long configurationId = 5L;
DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
DescriptorKey badDescriptorKey = createDescriptorKey("bad-descriptorKey");
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.findByDescriptorName(descriptorKey.getUniversalKey())).thenReturn(List.of(descriptorConfigEntity));
Mockito.when(registeredDescriptorRepository.findFirstByName(badDescriptorKey.getUniversalKey())).thenReturn(Optional.empty());
setupCreatConfigMocks(descriptorConfigEntity, configContextEntity, fieldValueEntity, definedFieldEntity);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(descriptorKey);
List<ConfigurationModel> configurationModelListEmpty = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(badDescriptorKey);
assertEquals(1, configurationModelList.size());
assertTrue(configurationModelListEmpty.isEmpty());
ConfigurationModel configurationModel = configurationModelList.get(0);
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class DefaultConfigurationModelConfigurationAccessorTest method getConfigurationsByDescriptorKeyAndContextTest.
@Test
public void getConfigurationsByDescriptorKeyAndContextTest() {
final Long descriptorId = 3L;
final Long configurationId = 5L;
DescriptorKey descriptorKey = createDescriptorKey("descriptorKeyName");
DescriptorConfigEntity descriptorConfigEntity = new DescriptorConfigEntity(descriptorId, 4L, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
descriptorConfigEntity.setId(configurationId);
ConfigContextEntity configContextEntity = new ConfigContextEntity(configContextEnum.name());
configContextEntity.setId(3L);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity("name", 1L);
registeredDescriptorEntity.setId(2L);
FieldValueEntity fieldValueEntity = new FieldValueEntity(6L, 7L, fieldValue);
DefinedFieldEntity definedFieldEntity = new DefinedFieldEntity(fieldKey, false);
definedFieldEntity.setId(8L);
Mockito.when(descriptorConfigRepository.findByDescriptorIdAndContextId(Mockito.any(), Mockito.any())).thenReturn(List.of(descriptorConfigEntity));
Mockito.when(configContextRepository.findFirstByContext(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(configContextRepository.findById(Mockito.any())).thenReturn(Optional.of(configContextEntity));
Mockito.when(registeredDescriptorRepository.findFirstByName(Mockito.any())).thenReturn(Optional.of(registeredDescriptorEntity));
Mockito.when(fieldValueRepository.findByConfigId(Mockito.any())).thenReturn(List.of(fieldValueEntity));
Mockito.when(definedFieldRepository.findById(Mockito.any())).thenReturn(Optional.of(definedFieldEntity));
EncryptionUtility encryptionUtility = createEncryptionUtility();
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = new DefaultConfigurationModelConfigurationAccessor(registeredDescriptorRepository, definedFieldRepository, descriptorConfigRepository, configContextRepository, fieldValueRepository, encryptionUtility);
List<ConfigurationModel> configurationModelList = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, configContextEnum);
assertEquals(1, configurationModelList.size());
ConfigurationModel configurationModel = configurationModelList.get(0);
testConfigurationModel(configurationId, descriptorId, configurationModel);
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class PhoneHomeTest method runTest.
@Test
public void runTest() {
RestApiAuditAccessor auditAccessor = Mockito.mock(RestApiAuditAccessor.class);
Mockito.when(auditAccessor.findFirstByJobId(Mockito.any())).thenReturn(Optional.empty());
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
AboutReader aboutReader = Mockito.mock(AboutReader.class);
Mockito.when(aboutReader.getProductVersion()).thenReturn(TEST_VERSION);
JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
// FIXME implement mocks
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
ConfigurationModel config = Mockito.mock(ConfigurationModel.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(config));
DescriptorMap descriptorMap = Mockito.mock(DescriptorMap.class);
Descriptor descriptor = Mockito.mock(Descriptor.class);
DescriptorKey descriptorKey = Mockito.mock(DescriptorKey.class);
Mockito.when(descriptorKey.getUniversalKey()).thenReturn(TEST_DESCRIPTOR_NAME);
Mockito.when(descriptorMap.getDescriptorMap()).thenReturn(Collections.singletonMap(descriptorKey, descriptor));
List<ProviderPhoneHomeHandler> providerHandlers = List.of();
ProviderKey providerKey = new BlackDuckProviderKey();
PhoneHomeTask phoneHomeTask = new PhoneHomeTask(taskScheduler, aboutReader, jobAccessor, configurationModelConfigurationAccessor, null, proxyManager, new Gson(), auditAccessor, providerHandlers, providerKey);
try {
phoneHomeTask.run();
} catch (Exception e) {
fail("Unexpected exception");
}
}
Aggregations