use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsCreateTest.
@Test
public void extractProjectMessageIssueModelsCreateTest() throws AlertException {
ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, ISSUE_BOM_COMPONENT_DETAILS, policyDetails);
ActionableIssueSearchResult<String> searchResult = new ActionableIssueSearchResult<>(null, projectIssueModel, ItemOperation.ADD);
MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
IssueTrackerSearcher<String> searcher = Mockito.mock(IssueTrackerSearcher.class);
Mockito.when(searcher.findIssues(Mockito.eq(projectMessage))).thenReturn(List.of(searchResult));
IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, searcher);
IssueTrackerModelHolder<String> modelHolder = extractor.extractProjectMessageIssueModels(projectMessage, "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(projectIssueModel, issueCreationModel.getSource().orElse(null));
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel 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.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class IssueTrackerSimpleMessageConverterTest method convertToIssueCreationModelTruncateTitleTest.
@Test
void convertToIssueCreationModelTruncateTitleTest() {
int maxTitleLength = 10;
int maxDescriptionLength = 12;
MockIssueTrackerMessageFormatter formatter = new MockIssueTrackerMessageFormatter(maxTitleLength, maxDescriptionLength, 1000);
IssueTrackerSimpleMessageConverter converter = new IssueTrackerSimpleMessageConverter(formatter);
IssueCreationModel issueCreationModel = converter.convertToIssueCreationModel(SIMPLE_MESSAGE, "jobName");
assertEquals(maxTitleLength, issueCreationModel.getTitle().length());
assertTrue(maxDescriptionLength >= issueCreationModel.getDescription().length(), "Expected max description length to be greater than or equal to the created description");
assertTrue(issueCreationModel.getPostCreateComments().size() > 0, "Expected truncated title/description to continue in comments");
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel 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");
}
}
use of com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel in project hub-alert by blackducksoftware.
the class ProjectIssueModelConverterTest method toIssueCreationModelPolicyTest.
@Test
public void toIssueCreationModelPolicyTest() {
IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, testPolicy);
IssueCreationModel issueCreationModel = basicIssueCreationModelTest(projectIssueModel);
assertTrue(issueCreationModel.getTitle().contains(testPolicy.getName()), "Expected policy name to be present in the title");
assertTrue(issueCreationModel.getDescription().contains(testPolicy.getName()), "Expected policy name to be present in the description");
}
Aggregations