Search in sources :

Example 1 with ProjectVersionNotificationContent

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;
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) ProjectVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationView)

Example 2 with ProjectVersionNotificationContent

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());
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) HttpUrl(com.synopsys.integration.rest.HttpUrl) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectVersionNotificationContent

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));
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) Test(org.junit.jupiter.api.Test)

Example 4 with ProjectVersionNotificationContent

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());
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProjectVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 5 with ProjectVersionNotificationContent

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;
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent)

Aggregations

ProjectVersionNotificationContent (com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent)7 Test (org.junit.jupiter.api.Test)5 ProjectVersionNotificationView (com.synopsys.integration.blackduck.api.manual.view.ProjectVersionNotificationView)2 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)1 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)1 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)1 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)1 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)1 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)1 ProjectVersionNotificationDetailExtractor (com.synopsys.integration.alert.provider.blackduck.processor.detail.ProjectVersionNotificationDetailExtractor)1 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1