Search in sources :

Example 66 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class TestBlackDuckProperties method getConfigurationModel.

public static ConfigurationModel getConfigurationModel(TestProperties testProperties) {
    String url = Optional.ofNullable(testProperties.getBlackDuckURL()).orElse("URL not set");
    String apiToken = testProperties.getBlackDuckAPIToken();
    String timeout = testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT);
    final Long defaultDescriptorId = 1L;
    final Long defaultConfigurationId = 1L;
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModel.getDescriptorId()).thenReturn(defaultDescriptorId);
    Mockito.when(configurationModel.getConfigurationId()).thenReturn(defaultConfigurationId);
    final String blackDuckTimeoutKey = BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT;
    ConfigurationFieldModel blackDuckTimeoutField = ConfigurationFieldModel.create(blackDuckTimeoutKey);
    blackDuckTimeoutField.setFieldValue(String.valueOf(timeout));
    Mockito.when(configurationModel.getField(blackDuckTimeoutKey)).thenReturn(Optional.of(blackDuckTimeoutField));
    final String blackDuckApiKey = BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY;
    ConfigurationFieldModel blackDuckApiField = ConfigurationFieldModel.create(blackDuckApiKey);
    blackDuckApiField.setFieldValue(apiToken);
    Mockito.when(configurationModel.getField(blackDuckApiKey)).thenReturn(Optional.of(blackDuckApiField));
    final String blackDuckProviderUrlKey = BlackDuckDescriptor.KEY_BLACKDUCK_URL;
    ConfigurationFieldModel blackDuckProviderUrlField = ConfigurationFieldModel.create(blackDuckProviderUrlKey);
    blackDuckProviderUrlField.setFieldValue(url);
    Mockito.when(configurationModel.getField(blackDuckProviderUrlKey)).thenReturn(Optional.of(blackDuckProviderUrlField));
    Mockito.when(configurationModel.getCopyOfKeyToFieldMap()).thenReturn(Map.of(blackDuckApiKey, blackDuckApiField, blackDuckProviderUrlKey, blackDuckProviderUrlField, blackDuckTimeoutKey, blackDuckTimeoutField));
    Mockito.when(configurationModel.getCopyOfFieldList()).thenReturn(List.of(blackDuckTimeoutField, blackDuckApiField, blackDuckProviderUrlField));
    return configurationModel;
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Example 67 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JobConfigControllerTestIT method testValidateConfig.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidateConfig() throws Exception {
    final String urlPath = REQUEST_URL + "/validate";
    ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of("BLACKDUCK_URL"), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of("BLACKDUCK_API")));
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    JobFieldModel fieldModel = createTestJobFieldModel(null, null, providerGlobalConfig);
    request.content(gson.toJson(fieldModel));
    request.contentType(MEDIA_TYPE);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 68 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JobConfigControllerTestIT method testUpdateConfig.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testUpdateConfig() throws Exception {
    ConfigurationModel providerGlobalConfig = addGlobalConfiguration(blackDuckProviderKey, Map.of(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, List.of(DEFAULT_BLACK_DUCK_CONFIG), BlackDuckDescriptor.KEY_BLACKDUCK_URL, List.of(testProperties.getBlackDuckURL()), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, List.of(testProperties.getBlackDuckAPIToken())));
    JobFieldModel fieldModel = createTestJobFieldModel("1", "2", providerGlobalConfig);
    Map<String, Collection<String>> fieldValueModels = new HashMap<>();
    for (FieldModel newFieldModel : fieldModel.getFieldModels()) {
        fieldValueModels.putAll(newFieldModel.getKeyToValues().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getValues())));
    }
    DistributionJobRequestModel jobRequestModel = createDistributionJobRequestModel(providerGlobalConfig.getConfigurationId());
    DistributionJobModel distributionJobModel = addDistributionJob(jobRequestModel);
    String configId = String.valueOf(distributionJobModel.getJobId());
    String urlPath = REQUEST_URL + "/" + configId;
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.put(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf());
    fieldModel.setJobId(configId);
    request.content(gson.toJson(fieldModel));
    request.contentType(MEDIA_TYPE);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isNoContent());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) HashMap(java.util.HashMap) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Collection(java.util.Collection) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) JobProviderProjectFieldModel(com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 69 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class JmsNotificationReceiverTestIT method init.

@BeforeEach
public void init() {
    properties = new TestProperties();
    ConfigurationFieldModel providerConfigEnabled = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED);
    providerConfigEnabled.setFieldValue("TRUE");
    ConfigurationFieldModel providerConfigName = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
    providerConfigName.setFieldValue("blackduck-config");
    ConfigurationFieldModel blackduckUrl = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    blackduckUrl.setFieldValue("https://www.synopsys.com");
    ConfigurationFieldModel blackduckApiKey = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    blackduckApiKey.setFieldValue("someApiKey");
    ConfigurationFieldModel blackduckTimeout = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
    blackduckTimeout.setFieldValue(String.valueOf(BlackDuckProperties.DEFAULT_TIMEOUT));
    ConfigurationModel blackduckConfigurationModel = defaultConfigurationAccessor.createConfiguration(blackDuckProviderKey, ConfigContextEnum.GLOBAL, List.of(providerConfigEnabled, providerConfigName, blackduckUrl, blackduckApiKey, blackduckTimeout));
    blackDuckGlobalConfigId = blackduckConfigurationModel.getConfigurationId();
    List<AlertNotificationModel> notificationContent = new ArrayList<>();
    for (Long i = 1L; i <= 1000; i++) {
        notificationContent.add(createAlertNotificationModel(i, false));
    }
    savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
    SlackJobDetailsModel slackJobDetailsModel = createSlackJobDetailsModel();
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobRequestModel("jobName1", slackJobDetailsModel);
    distributionJobModel = staticJobAccessor.createJob(distributionJobRequestModel);
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) ArrayList(java.util.ArrayList) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 70 with ConfigurationModel

use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.

the class AlertIntegrationTestConfiguration method initBlackDuckData.

// FIXME delete
@Deprecated(forRemoval = true)
public void initBlackDuckData() throws AlertException {
    TestProperties testProperties = new TestProperties();
    ConfigurationFieldModel blackDuckURLField = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
    blackDuckURLField.setFieldValue(testProperties.getBlackDuckURL());
    ConfigurationFieldModel blackDuckAPITokenField = ConfigurationFieldModel.createSensitive(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
    blackDuckAPITokenField.setFieldValue(testProperties.getBlackDuckAPIToken());
    ConfigurationFieldModel blackDuckTimeoutField = ConfigurationFieldModel.create(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
    blackDuckTimeoutField.setFieldValue(testProperties.getProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT));
    BlackDuckProviderKey blackDuckProviderKey = new BlackDuckProviderKey();
    ConfigurationModel blackDuckConfiguration = configurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(blackDuckProviderKey, ConfigContextEnum.GLOBAL).stream().findFirst().orElse(configurationModelConfigurationAccessor.createConfiguration(blackDuckProviderKey, ConfigContextEnum.GLOBAL, List.of(blackDuckURLField, blackDuckAPITokenField, blackDuckTimeoutField)));
    configurationModelConfigurationAccessor.updateConfiguration(blackDuckConfiguration.getConfigurationId(), List.of(blackDuckURLField, blackDuckAPITokenField, blackDuckTimeoutField));
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)

Aggregations

ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)140 Test (org.junit.jupiter.api.Test)89 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)49 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)33 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)31 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)22 List (java.util.List)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)13 DescriptorMap (com.synopsys.integration.alert.common.descriptor.DescriptorMap)13 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)13 HashMap (java.util.HashMap)13 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)11 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)11 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)11 DescriptorConfigEntity (com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity)10 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)10 ArrayList (java.util.ArrayList)10 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)9 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9