Search in sources :

Example 1 with ProjectNotificationContent

use of com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent in project hub-alert by blackducksoftware.

the class ProjectNotificationMessageExtractorTest method createProjectNotificationContent.

private ProjectNotificationContent createProjectNotificationContent() {
    ProjectNotificationContent projectNotificationContent = new ProjectNotificationContent();
    projectNotificationContent.setProject(PROJECT_URL);
    projectNotificationContent.setProjectName(PROJECT);
    projectNotificationContent.setOperationType(OperationType.CREATE);
    return projectNotificationContent;
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent)

Example 2 with ProjectNotificationContent

use of com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent in project hub-alert by blackducksoftware.

the class ProjectNotificationDetailExtractorTest method extractDetailedContentTest.

@Test
public void extractDetailedContentTest() throws IOException {
    String jsonContent = TestResourceUtils.readFileToString(NOTIFICATION_JSON_PATH);
    ProjectNotificationView projectNotificationView = gson.fromJson(jsonContent, ProjectNotificationView.class);
    ProjectNotificationContent projectNotificationContent = projectNotificationView.getContent();
    AlertNotificationModel notification = new AlertNotificationModel(0L, 0L, "BlackDuck", "Config 1", null, null, null, null, false);
    ProjectNotificationDetailExtractor extractor = new ProjectNotificationDetailExtractor();
    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(projectNotificationContent.getProjectName(), optionalProjectName.get());
    assertTrue(detailedNotificationContent.getPolicyName().isEmpty(), "Expected no policy name to be present");
    assertEquals(0, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProjectNotificationView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 3 with ProjectNotificationContent

use of com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent in project hub-alert by blackducksoftware.

the class JmsNotificationReceiverTestIT method createAlertNotificationModel.

private AlertNotificationModel createAlertNotificationModel(Long id, boolean processed) {
    ProjectNotificationContent projectNotificationContent = new ProjectNotificationContent();
    projectNotificationContent.setProject("project");
    projectNotificationContent.setProjectName(String.format("projectName-%s", id));
    projectNotificationContent.setOperationType(OperationType.CREATE);
    ProjectNotificationView projectNotificationView = new ProjectNotificationView();
    projectNotificationView.setContent(projectNotificationContent);
    projectNotificationView.setType(NotificationType.PROJECT);
    String content = gson.toJson(projectNotificationView);
    return new AlertNotificationModel(id, blackDuckGlobalConfigId, "provider_blackduck", "DELETED CONFIGURATION", NotificationType.PROJECT.name(), content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), processed);
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProjectNotificationView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationView)

Example 4 with ProjectNotificationContent

use of com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent in project hub-alert by blackducksoftware.

the class ProjectNotificationMessageExtractorTest 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);
    ProjectNotificationContent projectNotificationContent = createProjectNotificationContent();
    NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectNotificationContent);
    ProjectNotificationMessageExtractor extractor = new ProjectNotificationMessageExtractor(providerKey, servicesFactoryCache);
    ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectNotificationContent);
    assertEquals(1, providerMessageHolder.getProjectMessages().size());
    assertEquals(0, providerMessageHolder.getSimpleMessages().size());
    ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
    assertEquals(MessageReason.PROJECT_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());
    assertFalse(projectMessage.getProjectVersion().isPresent());
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) 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)

Aggregations

ProjectNotificationContent (com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)2 ProjectNotificationView (com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationView)2 Test (org.junit.jupiter.api.Test)2 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 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)1 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)1 HttpUrl (com.synopsys.integration.rest.HttpUrl)1