use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class MessageContentKey method from.
public static MessageContentKey from(String topicName, String topicValue, Set<LinkableItem> subTopics) {
if (null == subTopics || subTopics.isEmpty()) {
return from(topicName, topicValue);
}
StringBuilder builder = new StringBuilder();
builder.append(topicName);
builder.append(SEPARATOR);
builder.append(topicValue);
for (LinkableItem subTopic : subTopics) {
builder.append(SEPARATOR);
builder.append(subTopic.getLabel());
builder.append(SEPARATOR);
builder.append(subTopic.getValue());
}
return new MessageContentKey(builder.toString());
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class IssueTrackerModelExtractorTest method extractSimpleMessageIssueModelsTest.
@Test
public void extractSimpleMessageIssueModelsTest() {
String testSummary = "A test summary";
String testDescription = "A description for the test";
LinkableItem additionalDetail = new LinkableItem("A label", "A value");
MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, null);
SimpleMessage simpleMessage = SimpleMessage.original(PROVIDER_DETAILS, testSummary, testDescription, List.of(additionalDetail));
IssueTrackerModelHolder<String> modelHolder = extractor.extractSimpleMessageIssueModels(List.of(simpleMessage), "jobName");
List<IssueCreationModel> issueCreationModels = modelHolder.getIssueCreationModels();
assertEquals(1, issueCreationModels.size());
assertEquals(0, modelHolder.getIssueTransitionModels().size());
assertEquals(0, modelHolder.getIssueCommentModels().size());
IssueCreationModel issueCreationModel = issueCreationModels.get(0);
assertEquals(PROVIDER_DETAILS.getProvider(), issueCreationModel.getProvider());
assertTrue(issueCreationModel.getTitle().contains(testSummary), "Expected the issue title to contain the simple message's summary");
assertTrue(issueCreationModel.getDescription().contains(testDescription), "Expected the issue description to contain the simple message's description");
assertTrue(issueCreationModel.getDescription().contains(additionalDetail.getValue()), "Expected the issue description to contain the simple message's additional detail(s)");
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForVulnerabilitiesTest.
@Test
public void convertToIssueModelsForVulnerabilitiesTest() {
LinkableItem vulnerabilityItem0 = createVulnerabilityItem("CVE-000");
LinkableItem vulnerabilityItem7 = createVulnerabilityItem("CVE-007");
ComponentConcern vulnConcern0 = ComponentConcern.vulnerability(ItemOperation.ADD, vulnerabilityItem0.getValue(), ComponentConcernSeverity.CRITICAL, vulnerabilityItem0.getUrl().orElse(null));
ComponentConcern vulnConcern7 = ComponentConcern.vulnerability(ItemOperation.DELETE, vulnerabilityItem7.getValue(), ComponentConcernSeverity.MINOR_MEDIUM, vulnerabilityItem7.getUrl().orElse(null));
BomComponentDetails bomComponentDetails = createBomComponentDetails(List.of(vulnConcern0, ComponentConcern.vulnerability(ItemOperation.UPDATE, VULNERABILITY_2.getValue(), ComponentConcernSeverity.MINOR_MEDIUM, VULNERABILITY_2.getUrl().orElse(null)), vulnConcern7));
ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
List<ProjectIssueModel> vulnerabilityIssueModels = modelTransformer.convertToIssueModels(projectMessage);
assertEquals(1, vulnerabilityIssueModels.size());
ProjectIssueModel policyIssueModel = vulnerabilityIssueModels.get(0);
assertRequiredDetails(policyIssueModel);
Optional<IssueVulnerabilityDetails> optionalIssueVulnerabilityDetails = policyIssueModel.getVulnerabilityDetails();
assertTrue(optionalIssueVulnerabilityDetails.isPresent(), "Expected vulnerability details to be present");
IssueVulnerabilityDetails issueVulnerabilityDetails = optionalIssueVulnerabilityDetails.get();
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesAdded().size());
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesUpdated().size());
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesDeleted().size());
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class IssueTrackerCallbackInfoCreatorTest method createCallbackInfoNoProjectVersionUrlTest.
@Test
public void createCallbackInfoNoProjectVersionUrlTest() {
LinkableItem projectVersionNoUrl = new LinkableItem("Project Version", "A Project Version", null);
ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(PROVIDER_DETAILS, TEST_ITEM, projectVersionNoUrl, ISSUE_BOM_COMPONENT_DETAILS);
IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
Optional<IssueTrackerCallbackInfo> callbackInfo = callbackInfoCreator.createCallbackInfo(projectIssueModel);
assertTrue(callbackInfo.isEmpty(), "Expected no callback info to be present because no project-version url was present");
}
use of com.synopsys.integration.alert.common.message.model.LinkableItem in project hub-alert by blackducksoftware.
the class IssueTrackerSimpleMessageConverterTest method convertToIssueCreationModelUnboundedTest.
@Test
void convertToIssueCreationModelUnboundedTest() {
MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
IssueTrackerSimpleMessageConverter converter = new IssueTrackerSimpleMessageConverter(formatter);
IssueCreationModel issueCreationModel = converter.convertToIssueCreationModel(SIMPLE_MESSAGE, "jobName");
assertTrue(issueCreationModel.getTitle().contains(SIMPLE_MESSAGE.getSummary()), "Expected title to contain the simple message's summary");
String issueCreationModelDescription = issueCreationModel.getDescription();
assertTrue(issueCreationModelDescription.contains(SIMPLE_MESSAGE.getDescription()), "Expected description to contain the simple message's description");
for (LinkableItem detail : SIMPLE_MESSAGE.getDetails()) {
assertTrue(issueCreationModelDescription.contains(detail.getLabel()) && issueCreationModelDescription.contains(detail.getValue()), "Expected description to contain the simple message's details");
}
}
Aggregations