use of com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent in project hub-alert by blackducksoftware.
the class NotificationDetailExtractionDelegatorTest method createProjectVersionNotificationView.
private static ProjectVersionNotificationView createProjectVersionNotificationView() {
ProjectVersionNotificationContent projectVersionNotificationContent = new ProjectVersionNotificationContent();
projectVersionNotificationContent.setProject("https://my-project");
projectVersionNotificationContent.setProjectName("my project!");
projectVersionNotificationContent.setProjectVersion("https://project-version");
projectVersionNotificationContent.setProjectVersionName("a name for a version 02468");
projectVersionNotificationContent.setOperationType(OperationType.CREATE);
ProjectVersionNotificationView projectVersionNotificationView = new ProjectVersionNotificationView();
projectVersionNotificationView.setType(NotificationType.PROJECT_VERSION);
projectVersionNotificationView.setContent(projectVersionNotificationContent);
return projectVersionNotificationView;
}
use of com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent in project hub-alert by blackducksoftware.
the class ProjectVersionNotificationMessageExtractorTest method extractTest.
@Test
public void extractTest() throws IntegrationException {
NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl("https://a.blackduck.server.example.com"));
Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.anyLong())).thenReturn(blackDuckServicesFactory);
ProjectVersionNotificationContent projectVersionNotificationContent = createProjectVersionNotificationContent();
NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectVersionNotificationContent);
ProjectVersionNotificationMessageExtractor extractor = new ProjectVersionNotificationMessageExtractor(providerKey, servicesFactoryCache);
ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectVersionNotificationContent);
assertEquals(1, providerMessageHolder.getProjectMessages().size());
assertEquals(0, providerMessageHolder.getSimpleMessages().size());
ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
assertEquals(MessageReason.PROJECT_VERSION_STATUS, projectMessage.getMessageReason());
assertTrue(projectMessage.getOperation().isPresent());
assertEquals(ProjectOperation.CREATE, projectMessage.getOperation().get());
assertTrue(projectMessage.getBomComponents().isEmpty());
assertEquals(PROJECT, projectMessage.getProject().getValue());
assertTrue(projectMessage.getProject().getUrl().isPresent());
assertEquals(PROJECT_URL, projectMessage.getProject().getUrl().get());
assertTrue(projectMessage.getProjectVersion().isPresent());
LinkableItem projectVersion = projectMessage.getProjectVersion().get();
assertEquals(PROJECT_VERSION, projectVersion.getValue());
assertTrue(projectVersion.getUrl().isPresent());
assertEquals(PROJECT_VERSION_URL, projectVersion.getUrl().get());
}
use of com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent in project hub-alert by blackducksoftware.
the class DetailedNotificationContentTest method projectTest.
@Test
public void projectTest() {
String projectName = "project with version";
String projectVersionName = "version";
ProjectVersionNotificationContent projectVersionNotificationContent = new ProjectVersionNotificationContent();
DetailedNotificationContent detailedContent = DetailedNotificationContent.project(ALERT_NOTIFICATION_MODEL, projectVersionNotificationContent, projectName, projectVersionName);
assertContent(detailedContent, ALERT_NOTIFICATION_MODEL.getProviderConfigId(), projectVersionNotificationContent.getClass(), List.of());
assertEquals(projectName, detailedContent.getProjectName().orElse(null));
assertTrue(detailedContent.getPolicyName().isEmpty(), EXPECTED_NO_POLICY);
assertEquals(projectVersionName, detailedContent.getProjectVersionName().orElse(null));
}
use of com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent in project hub-alert by blackducksoftware.
the class ProjectVersionNotificationDetailExtractorTest method extractDetailedContentTest.
@Test
public void extractDetailedContentTest() throws IOException {
String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
ProjectVersionNotificationView projectNotificationView = gson.fromJson(jsonContent, ProjectVersionNotificationView.class);
ProjectVersionNotificationContent projectVersionNotificationContent = projectNotificationView.getContent();
AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
ProjectVersionNotificationDetailExtractor extractor = new ProjectVersionNotificationDetailExtractor();
List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, projectNotificationView);
assertEquals(1, detailedNotificationContents.size());
DetailedNotificationContent detailedNotificationContent = detailedNotificationContents.get(0);
Optional<String> optionalProjectName = detailedNotificationContent.getProjectName();
assertTrue(optionalProjectName.isPresent(), "Expect project name to be present");
assertEquals(projectVersionNotificationContent.getProjectName(), optionalProjectName.get());
assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
use of com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent in project hub-alert by blackducksoftware.
the class ProjectVersionNotificationMessageExtractorTest method createProjectVersionNotificationContent.
private ProjectVersionNotificationContent createProjectVersionNotificationContent() {
ProjectVersionNotificationContent projectVersionNotificationContent = new ProjectVersionNotificationContent();
projectVersionNotificationContent.setProject(PROJECT_URL);
projectVersionNotificationContent.setProjectName(PROJECT);
projectVersionNotificationContent.setProjectVersion(PROJECT_VERSION_URL);
projectVersionNotificationContent.setProjectVersionName(PROJECT_VERSION);
projectVersionNotificationContent.setOperationType(OperationType.CREATE);
return projectVersionNotificationContent;
}
Aggregations