Search in sources :

Example 61 with ConfigurationFieldModel

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()));
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) ResponseStatusException(org.springframework.web.server.ResponseStatusException) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 62 with ConfigurationFieldModel

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();
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 63 with ConfigurationFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 64 with ConfigurationFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 65 with ConfigurationFieldModel

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());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)105 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)47 Test (org.junit.jupiter.api.Test)32 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)27 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)23 HashMap (java.util.HashMap)20 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)14 ArrayList (java.util.ArrayList)13 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)12 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)12 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)11 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)11 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)10 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)10 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 ConfigurationModelMutable (com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable)8 EncryptionUtility (com.synopsys.integration.alert.common.security.EncryptionUtility)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)7