use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel in project hub-alert by blackducksoftware.
the class JobNotificationMapperTestIT method extractJobsWithMatchingProjectNamePatternFilter.
@Test
public void extractJobsWithMatchingProjectNamePatternFilter() {
createJobs(List.of(new DistributionJobRequestModel(true, "name", FrequencyType.REAL_TIME, ProcessingType.DIGEST, ChannelKeys.SLACK.getUniversalKey(), UUID.randomUUID(), 0L, true, // Regex to verify we retrieve notifications without a number in the name (PROJECT_NAME_1)
"^([^0-9]*)$", null, List.of(NotificationType.VULNERABILITY.name()), List.of(), List.of(), List.of(), new SlackJobDetailsModel(null, "webhook", "channelName", "username"))));
testProjectJob();
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel 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();
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel 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);
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method updateJobTest.
@Test
void updateJobTest() throws Exception {
UUID jobId = UUID.randomUUID();
SlackJobDetailsModel slackJobDetailsModel = new SlackJobDetailsModel(jobId, null, null, null);
DistributionJobRequestModel distributionJobRequestModel = new DistributionJobRequestModel(true, jobName, FrequencyType.DAILY, ProcessingType.DEFAULT, ChannelKeys.SLACK.getUniversalKey(), UUID.randomUUID(), 3L, true, "*", "*", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), slackJobDetailsModel);
SlackJobDetailsEntity slackJobDetailsEntity = new SlackJobDetailsEntity();
DistributionJobEntity distributionJobEntity = new DistributionJobEntity(jobId, distributionJobRequestModel.getName(), distributionJobRequestModel.isEnabled(), distributionJobRequestModel.getDistributionFrequency().name(), distributionJobRequestModel.getProcessingType().name(), distributionJobRequestModel.getChannelDescriptorName(), distributionJobRequestModel.getChannelGlobalConfigId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
distributionJobEntity.setSlackJobDetails(slackJobDetailsEntity);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = new BlackDuckJobDetailsEntity(jobId, distributionJobRequestModel.getBlackDuckGlobalConfigId(), distributionJobRequestModel.isFilterByProject(), distributionJobRequestModel.getProjectNamePattern().orElse(null), distributionJobRequestModel.getProjectVersionNamePattern().orElse(null));
Mockito.when(slackJobDetailsAccessor.saveSlackJobDetails(Mockito.any(), Mockito.any())).thenReturn(slackJobDetailsEntity);
Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
Mockito.when(distributionJobRepository.findById(Mockito.any())).thenReturn(Optional.of(distributionJobEntity));
Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
DistributionJobModel updatedJob = jobAccessor.updateJob(jobId, distributionJobRequestModel);
Mockito.verify(distributionJobRepository).findById(jobId);
Mockito.verify(distributionJobRepository).save(Mockito.any());
assertEquals(jobId, updatedJob.getJobId());
assertEquals(jobName, updatedJob.getName());
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel in project hub-alert by blackducksoftware.
the class SlackChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(SlackJobDetailsModel slackJobDetails, List<SlackChannelMessageModel> channelMessages) throws AlertException {
String webhook = slackJobDetails.getWebhook();
String channelName = slackJobDetails.getChannelName();
String channelUsername = Optional.ofNullable(slackJobDetails.getChannelUsername()).orElse(SLACK_DEFAULT_USERNAME);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> requests = channelMessages.stream().map(channelMessage -> createJsonString(channelMessage.getMarkdownContent(), channelName, channelUsername)).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(requests, slackChannelKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d Slack message(s)", requests.size()));
}
Aggregations