Search in sources :

Example 6 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class DigestRemovalProcessorTest method createVulnerabilityNotifications.

private List<NotificationModel> createVulnerabilityNotifications() {
    final String keyPrefix = "key";
    final String projectName = "Project Name";
    final String projectVersion = "Project Version";
    final NotificationEntity notification1 = new NotificationEntity(keyPrefix + "1", null, NotificationCategoryEnum.HIGH_VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationEntity notification2 = new NotificationEntity(keyPrefix + "2", null, NotificationCategoryEnum.MEDIUM_VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationEntity notification3 = new NotificationEntity(keyPrefix + "3", null, NotificationCategoryEnum.LOW_VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationEntity notification4 = new NotificationEntity(keyPrefix + "4", null, NotificationCategoryEnum.VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationModel model1 = new NotificationModel(notification1, createVulnerabilityList());
    final NotificationModel model2 = new NotificationModel(notification2, createVulnerabilityList());
    final NotificationModel model3 = new NotificationModel(notification3, createVulnerabilityList());
    final NotificationModel model4 = new NotificationModel(notification4, Collections.emptyList());
    return Arrays.asList(model1, model2, model1, model3, model2, model4);
}
Also used : NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 7 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class ProjectDataFactoryTest method createProjectDataTest.

@Test
public void createProjectDataTest() {
    final NotificationModel notification = createVulnerabilityNotification();
    final ProjectDataFactory projectDataFactory = new ProjectDataFactory();
    final ProjectData projectData = projectDataFactory.createProjectData(notification);
    assertFields(notification, projectData);
    assertEquals(DigestTypeEnum.REAL_TIME, projectData.getDigestType());
}
Also used : NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) Test(org.junit.Test)

Example 8 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class ProjectDataFactoryTest method createVulnerabilityNotification.

private NotificationModel createVulnerabilityNotification(final String projectName, final String projectVersion) {
    final String eventKey = "key";
    final Date createdAt = new Date();
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.MEDIUM_VULNERABILITY;
    final String projectUrl = "http://localhost:8080";
    final String projectVersionUrl = "http://localhost:8080";
    final String componentName = "Component";
    final String componentVersion = "Component Version";
    final String policyRuleName = null;
    final String policyRuleUser = null;
    final String vulnerabilityId = NotificationCategoryEnum.VULNERABILITY.name();
    final VulnerabilityOperationEnum vulnerabilityOperation = VulnerabilityOperationEnum.ADD;
    final NotificationEntity notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, policyRuleUser);
    notification.setId(1L);
    final Collection<VulnerabilityEntity> vulnerabilityList = Arrays.asList(new VulnerabilityEntity(vulnerabilityId, vulnerabilityOperation, notification.getId()));
    return new NotificationModel(notification, vulnerabilityList);
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) VulnerabilityOperationEnum(com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date)

Example 9 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class NotificationModelTest method testNotificationNull.

@Test
public void testNotificationNull() {
    final NotificationEntity entity = null;
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vuln1);
    final NotificationModel model = new NotificationModel(entity, vulnerabilityList);
    assertNull(model.getComponentName());
    assertNull(model.getComponentVersion());
    assertNull(model.getCreatedAt());
    assertNull(model.getEventKey());
    assertNull(model.getNotificationEntity());
    assertNull(model.getNotificationType());
    assertNull(model.getPolicyRuleName());
    assertNull(model.getPolicyRuleUser());
    assertNull(model.getProjectName());
    assertNull(model.getProjectUrl());
    assertNull(model.getProjectVersion());
    assertNull(model.getProjectVersionUrl());
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    final boolean allEqual = model.getVulnerabilityList().stream().allMatch(vuln1::equals);
    assertTrue(allEqual);
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Test(org.junit.Test)

Example 10 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class NotificationModelTest method testModel.

@Test
public void testModel() {
    final NotificationEntity entity = createNotificationEntity();
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vuln1);
    final NotificationModel model = new NotificationModel(entity, vulnerabilityList);
    assertEquals(entity.getComponentName(), model.getComponentName());
    assertEquals(entity.getComponentVersion(), model.getComponentVersion());
    assertEquals(entity.getCreatedAt(), model.getCreatedAt());
    assertEquals(entity.getEventKey(), model.getEventKey());
    assertEquals(entity, model.getNotificationEntity());
    assertEquals(entity.getNotificationType(), model.getNotificationType());
    assertEquals(entity.getPolicyRuleName(), model.getPolicyRuleName());
    assertEquals(entity.getPolicyRuleUser(), model.getPolicyRuleUser());
    assertEquals(entity.getProjectName(), model.getProjectName());
    assertEquals(entity.getProjectUrl(), model.getProjectUrl());
    assertEquals(entity.getProjectVersion(), model.getProjectVersion());
    assertEquals(entity.getProjectVersionUrl(), model.getProjectVersionUrl());
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    final boolean allEqual = model.getVulnerabilityList().stream().allMatch(vuln1::equals);
    assertTrue(allEqual);
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Test(org.junit.Test)

Aggregations

NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)39 Test (org.junit.Test)25 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)21 Date (java.util.Date)15 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)13 ArrayList (java.util.ArrayList)10 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)4 ProjectDataFactory (com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory)4 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)3 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)3