use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckNotificationRetrieverFactoryTest method createBlackDuckProperties.
private BlackDuckProperties createBlackDuckProperties(String blackDuckUrl) {
ConfigurationModel configurationModel = createConfigurationModel(blackDuckUrl);
ProxyManager proxyManager = new ProxyManager(new MockSettingsUtility());
return new BlackDuckProperties(1L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), new MockAlertProperties(), proxyManager, configurationModel);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method initializeConfiguration.
private void initializeConfiguration(Collection<DescriptorKey> descriptorKeys) {
for (DescriptorKey descriptorKey : descriptorKeys) {
logger.info(LINE_DIVIDER);
logger.info("Descriptor: {}", descriptorKey.getUniversalKey());
logger.info(LINE_DIVIDER);
logger.info(" Starting Descriptor Initialization...");
try {
List<DefinedFieldModel> fieldsForDescriptor = descriptorAccessor.getFieldsForDescriptor(descriptorKey, ConfigContextEnum.GLOBAL).stream().sorted(Comparator.comparing(DefinedFieldModel::getKey)).collect(Collectors.toList());
List<ConfigurationModel> foundConfigurationModels = fieldConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, ConfigContextEnum.GLOBAL);
Map<String, ConfigurationFieldModel> existingConfiguredFields = new HashMap<>();
foundConfigurationModels.forEach(config -> existingConfiguredFields.putAll(config.getCopyOfKeyToFieldMap()));
Set<ConfigurationFieldModel> configurationModels = createFieldModelsFromDefinedFields(descriptorKey, fieldsForDescriptor, existingConfiguredFields);
logConfiguration(configurationModels);
updateConfigurationFields(descriptorKey, foundConfigurationModels, configurationModels);
} catch (IllegalArgumentException | SecurityException | AlertException ex) {
logger.error("error initializing descriptor", ex);
} finally {
logger.info(" Finished Descriptor Initialization...");
logger.info(LINE_DIVIDER);
}
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckGlobalConfigurationFieldModelValidatorTest method nonUniqueName.
@Test
public void nonUniqueName() {
String duplicateName = "duplicateName";
Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(duplicateName), true);
defaultKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, apiKeyFieldValueModel);
FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
ConfigurationFieldModel configurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
Mockito.when(configurationFieldModel.getFieldValue()).thenReturn(Optional.of(duplicateName));
ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
Mockito.when(configurationModel.getDescriptorContext()).thenReturn(ConfigContextEnum.GLOBAL);
Mockito.when(configurationModel.getField(Mockito.any())).thenReturn(Optional.of(configurationFieldModel));
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of(configurationModel));
BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(configurationModelConfigurationAccessor);
Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
assertEquals(1, alertFieldStatuses.size());
AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElse(null);
assertNotNull(alertFieldStatus);
assertEquals(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, alertFieldStatus.getFieldName());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCacheTest method createConfigurationModel.
private ConfigurationModel createConfigurationModel() {
Map<String, ConfigurationFieldModel> configuredFields = new HashMap<>();
ConfigurationFieldModel apiKey = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
apiKey.setFieldValue("blackDuckApiKey");
configuredFields.put(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, apiKey);
ConfigurationFieldModel url = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
url.setFieldValue("http://blackDuckUrl");
configuredFields.put(BlackDuckDescriptor.KEY_BLACKDUCK_URL, url);
return new ConfigurationModel(1L, 2L, "createdAt", "lastUpdated", ConfigContextEnum.GLOBAL, configuredFields);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCacheTest method invalidConfigurationTest.
@Test
public void invalidConfigurationTest() {
ConfigurationModel configurationModel = new ConfigurationModel(1L, 2L, "createdAt", "lastUpdated", ConfigContextEnum.GLOBAL, Map.of());
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.eq(blackDuckConfigId))).thenReturn(Optional.of(configurationModel));
try {
cache.retrieveBlackDuckServicesFactory(blackDuckConfigId);
fail("Expected AlertConfigurationException to be thrown due to missing configuredFields in the ConfigurationModel.");
} catch (AlertConfigurationException e) {
// Pass
}
}
Aggregations