use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel 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.persistence.model.ConfigurationModel 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");
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class PhoneHomeTask method runTask.
@Override
public void runTask() {
String productVersion = aboutReader.getProductVersion();
if (AboutReader.PRODUCT_VERSION_UNKNOWN.equals(productVersion)) {
return;
}
ExecutorService phoneHomeExecutor = Executors.newSingleThreadExecutor();
try {
String[] channelMetaData = retrieveChannelMetadataForAllJobs();
for (ProviderPhoneHomeHandler handler : providerHandlers) {
List<ConfigurationModel> configurations = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(handler.getProviderKey(), ConfigContextEnum.GLOBAL);
for (ConfigurationModel configuration : configurations) {
PhoneHomeService phoneHomeService = createPhoneHomeService(phoneHomeExecutor);
NameVersion alertArtifactInfo = new NameVersion(ARTIFACT_ID, productVersion);
PhoneHomeRequestBodyBuilder requestBodyBuilder = handler.populatePhoneHomeData(configuration, alertArtifactInfo);
requestBodyBuilder.addArtifactModules(channelMetaData);
PhoneHomeRequestBody requestBody = requestBodyBuilder.build();
PhoneHomeResponse phoneHomeResponse = phoneHomeService.phoneHome(requestBody, System.getenv());
boolean taskSucceeded = BooleanUtils.isTrue(phoneHomeResponse.awaitResult(DEFAULT_TIMEOUT));
if (!taskSucceeded) {
logger.debug("Phone home task timed out and did not send any results.");
}
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
phoneHomeExecutor.shutdownNow();
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class DefaultDescriptorGlobalConfigUtility method getFieldModel.
public Optional<FieldModel> getFieldModel() throws AlertException {
Optional<ConfigurationModel> configurationModelOptional = getConfiguration();
if (configurationModelOptional.isPresent()) {
ConfigurationModel configurationModel = configurationModelOptional.get();
FieldModel fieldModel = configurationFieldModelConverter.convertToFieldModel(configurationModel);
return Optional.ofNullable(apiAction.afterGetAction(fieldModel));
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProviderConfigMissingValidatorTest method testValidConfigurations.
@Test
public void testValidConfigurations() {
SystemMessageAccessor systemMessageAccessor = Mockito.mock(SystemMessageAccessor.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
List<Provider> providers = List.of(Mockito.mock(Provider.class));
ConfigurationModel model = Mockito.mock(ConfigurationModel.class);
Mockito.when(model.getCopyOfFieldList()).thenReturn(List.of(Mockito.mock(ConfigurationFieldModel.class)));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.any(), Mockito.any())).thenReturn(List.of(model));
ProviderConfigMissingValidator validator = new ProviderConfigMissingValidator(systemMessageAccessor, providers, configurationModelConfigurationAccessor);
validator.validate();
Mockito.verify(systemMessageAccessor, Mockito.never()).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.anyString());
}
Aggregations