Search in sources :

Example 21 with DistributionJobRequestModel

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

the class JobNotificationMapperTestIT method extractSingleJob.

@Test
public void extractSingleJob() {
    DistributionJobRequestModel jobRequestModel = createJobRequestModel(FrequencyType.REAL_TIME, ProcessingType.DIGEST, List.of(), List.of(NotificationType.VULNERABILITY.name(), NotificationType.POLICY_OVERRIDE.name()), List.of(), List.of());
    testSingleJob(jobRequestModel, 4);
}
Also used : DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with DistributionJobRequestModel

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

the class JobNotificationMapperTestIT method createDistributionJobModels.

private List<DistributionJobRequestModel> createDistributionJobModels(List<String> vulnTypes, int numberOfJobs) {
    List<DistributionJobRequestModel> jobModels = new ArrayList<>();
    for (int i = 0; i < numberOfJobs; i++) {
        DistributionJobRequestModel distributionJobRequestModel = createJobRequestModel(FrequencyType.REAL_TIME, ProcessingType.DIGEST, List.of(), List.of(NotificationType.VULNERABILITY.name()), vulnTypes, List.of());
        jobModels.add(distributionJobRequestModel);
    }
    return jobModels;
}
Also used : ArrayList(java.util.ArrayList) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)

Example 23 with DistributionJobRequestModel

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

the class JobNotificationMapperTestIT method extractJobsWithMatchingProjectVersionNamePatternFilter.

@Test
public void extractJobsWithMatchingProjectVersionNamePatternFilter() {
    createJobs(List.of(new DistributionJobRequestModel(true, "name", FrequencyType.REAL_TIME, ProcessingType.DIGEST, ChannelKeys.SLACK.getUniversalKey(), UUID.randomUUID(), 0L, true, null, // Regex to verify we retrieve notifications without a number in the name (PROJECT_VERSION_NAME_1)
    "^([^0-9]*)$", List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of(), new SlackJobDetailsModel(null, "webhook", "channelName", "username"))));
    testProjectJob();
}
Also used : SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel 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 25 with DistributionJobRequestModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel 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)

Aggregations

DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)34 Test (org.junit.jupiter.api.Test)25 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 UUID (java.util.UUID)10 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)7 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)7 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)6 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)6 ArrayList (java.util.ArrayList)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)4 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)3