use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method resendNotificationTestIT.
@Test
public void resendNotificationTestIT() throws Exception {
String content = ResourceUtil.getResourceAsString(getClass(), "/json/policyOverrideNotification.json", StandardCharsets.UTF_8);
MockNotificationContent mockNotification = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), "POLICY_OVERRIDE", content, 1L, providerConfigModel.getConfigurationId());
ConfigurationFieldModel providerConfigId = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
providerConfigId.setFieldValue(String.valueOf(providerConfigModel.getConfigurationId()));
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(jobModel.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.eq(ConfigContextEnum.GLOBAL.name()), Mockito.eq(AuditDescriptor.AUDIT_COMPONENT))).thenReturn(true);
AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
try {
auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
auditEntryActions.resendNotification(savedNotificationEntity.getId(), jobModel.getJobId());
} catch (Exception e) {
logger.error(e.getMessage(), e);
fail("Expected the Audit POST request(s) not to throw an exception");
}
assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(-1L, null));
assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(savedNotificationEntity.getId(), UUID.randomUUID()));
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ProcessingJobAccessorTestIT method createProvider.
@BeforeEach
public void createProvider() {
ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
providerConfigEnabled.setFieldValue("true");
ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
providerConfigName.setFieldValue("My Black Duck Config");
ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
blackduckUrl.setFieldValue("https://a-blackduck-server");
ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
blackduckApiKey.setFieldValue("123456789012345678901234567890123456789012345678901234567890");
ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
blackduckTimeout.setFieldValue("300");
List<ConfigurationFieldModel> providerConfigFields = List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout);
providerConfigId = configurationModelConfigurationAccessor.createConfiguration(new BlackDuckProviderKey(), ConfigContextEnum.GLOBAL, providerConfigFields).getConfigurationId();
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ConfigurationModelConfigurationAccessorTestIT method updateConfigurationReplaceValueTest.
@Test
public void updateConfigurationReplaceValueTest() throws AlertConfigurationException {
final String initialValue = "initial value";
ConfigurationFieldModel originalField = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
originalField.setFieldValue(initialValue);
DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
ConfigurationModel createdModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, Arrays.asList(originalField));
List<ConfigurationFieldModel> copyOfFieldList = createdModel.getCopyOfFieldList();
assertEquals(1, copyOfFieldList.size());
Optional<String> optionalValue = copyOfFieldList.get(0).getFieldValue();
assertTrue(optionalValue.isPresent());
assertEquals(initialValue, optionalValue.get());
final String additionalValue = "additional value";
ConfigurationFieldModel newFieldWithSameKey = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
newFieldWithSameKey.setFieldValue(additionalValue);
ConfigurationModel updatedModel = configurationModelConfigurationAccessor.updateConfiguration(createdModel.getConfigurationId(), Arrays.asList(newFieldWithSameKey));
List<ConfigurationFieldModel> configuredFields = updatedModel.getCopyOfFieldList();
assertEquals(1, configuredFields.size());
ConfigurationFieldModel configuredField = configuredFields.get(0);
assertEquals(originalField, configuredField);
assertTrue(configuredField.getFieldValues().contains(additionalValue));
List<FieldValueEntity> databaseFieldValues = fieldValueRepository.findByConfigId(updatedModel.getConfigurationId());
assertNotNull(databaseFieldValues);
assertEquals(1, databaseFieldValues.size());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ConfigurationModelConfigurationAccessorTestIT method createConfigTest.
@Test
public void createConfigTest() {
ConfigurationFieldModel configField1 = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
ConfigurationFieldModel configField2 = ConfigurationFieldModel.createSensitive(FIELD_KEY_SENSITIVE);
DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
ConfigurationModel createdConfig = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, List.of(configField1, configField2));
assertTrue(createdConfig.getCopyOfFieldList().contains(configField1));
assertTrue(createdConfig.getCopyOfFieldList().contains(configField2));
Optional<DescriptorConfigEntity> configEntityOptional = descriptorConfigsRepository.findById(createdConfig.getConfigurationId());
assertTrue(configEntityOptional.isPresent());
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel in project hub-alert by blackducksoftware.
the class ConfigurationModelConfigurationAccessorTestIT method updateConfigurationMultipleValueTest.
@Test
public void updateConfigurationMultipleValueTest() throws AlertConfigurationException {
final String initialValue = "initial value";
ConfigurationFieldModel originalField = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
originalField.setFieldValue(initialValue);
DescriptorKey descriptorKey = createDescriptorKey(DESCRIPTOR_NAME);
ConfigurationModel createdModel = configurationModelConfigurationAccessor.createConfiguration(descriptorKey, ConfigContextEnum.DISTRIBUTION, Arrays.asList(originalField));
List<ConfigurationFieldModel> copyOfFieldList = createdModel.getCopyOfFieldList();
assertEquals(1, copyOfFieldList.size());
Optional<String> optionalValue = copyOfFieldList.get(0).getFieldValue();
assertTrue(optionalValue.isPresent());
assertEquals(initialValue, optionalValue.get());
final String additionalValue = "additional value";
ConfigurationFieldModel newFieldWithSameKey = ConfigurationFieldModel.create(FIELD_KEY_INSENSITIVE);
newFieldWithSameKey.setFieldValue(additionalValue);
ConfigurationModel updatedModel = configurationModelConfigurationAccessor.updateConfiguration(createdModel.getConfigurationId(), Arrays.asList(originalField, newFieldWithSameKey));
List<ConfigurationFieldModel> configuredFields = updatedModel.getCopyOfFieldList();
assertEquals(1, configuredFields.size());
ConfigurationFieldModel configuredField = configuredFields.get(0);
assertEquals(originalField, configuredField);
assertTrue(configuredField.getFieldValues().contains(initialValue));
assertTrue(configuredField.getFieldValues().contains(additionalValue));
List<FieldValueEntity> databaseFieldValues = fieldValueRepository.findByConfigId(updatedModel.getConfigurationId());
assertNotNull(databaseFieldValues);
assertEquals(2, databaseFieldValues.size());
assertEquals(configuredField.getFieldValues().size(), databaseFieldValues.size());
}
Aggregations