Search in sources :

Example 1 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class NotificationManagerTestIT method testSave.

@Test
public void testSave() {
    final NotificationEntity notificationEntity = createNotificationEntity();
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    NotificationModel model = new NotificationModel(notificationEntity, vulnerabilityList);
    NotificationModel savedModel = notificationManager.saveNotification(model);
    assertNotNull(savedModel.getNotificationEntity().getId());
    assertNotificationModel(notificationEntity, savedModel);
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    model = new NotificationModel(notificationEntity, null);
    savedModel = notificationManager.saveNotification(model);
    assertNotNull(savedModel.getNotificationEntity().getId());
    assertNotificationModel(notificationEntity, savedModel);
    assertTrue(model.getVulnerabilityList().isEmpty());
}
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) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class NotificationManagerTestIT method testFindByIds.

@Test
public void testFindByIds() {
    final NotificationEntity notificationEntity = createNotificationEntity();
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    final NotificationModel model = new NotificationModel(notificationEntity, vulnerabilityList);
    final NotificationModel savedModel = notificationManager.saveNotification(model);
    final List<Long> notificationIds = Arrays.asList(savedModel.getNotificationEntity().getId());
    final List<NotificationModel> notificationModelList = notificationManager.findByIds(notificationIds);
    assertEquals(1, notificationModelList.size());
}
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) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class VulnerabilityRepositoryTestIT method testFindByNotificationId.

@Test
public void testFindByNotificationId() {
    final VulnerabilityEntity entity1 = createVulnerabilityEntity(1);
    final VulnerabilityEntity entity2 = createVulnerabilityEntity(2);
    final VulnerabilityEntity entity3 = createVulnerabilityEntity(3);
    final VulnerabilityEntity doNotFindEntity = new VulnerabilityEntity("id4", VulnerabilityOperationEnum.DELETE, 2L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(entity1, entity2, entity3, doNotFindEntity);
    repository.save(vulnerabilityList);
    final long count = repository.count();
    assertEquals(vulnerabilityList.size(), count);
    final List<VulnerabilityEntity> foundEntityList = repository.findByNotificationId(1L);
    final boolean entity1Found = foundEntityList.stream().anyMatch(entity1::equals);
    final boolean entity2Found = foundEntityList.stream().anyMatch(entity1::equals);
    final boolean entity3Found = foundEntityList.stream().anyMatch(entity1::equals);
    final boolean noneMatchNotFound = foundEntityList.stream().noneMatch(doNotFindEntity::equals);
    assertTrue(entity1Found);
    assertTrue(entity2Found);
    assertTrue(entity3Found);
    assertTrue(noneMatchNotFound);
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 4 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity in project hub-alert by blackducksoftware.

the class DigestRemovalProcessorTest method createVulnerabilityList.

private List<VulnerabilityEntity> createVulnerabilityList() {
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final VulnerabilityEntity vuln2 = new VulnerabilityEntity("id2", VulnerabilityOperationEnum.DELETE, 2L);
    final VulnerabilityEntity vuln3 = new VulnerabilityEntity("id3", VulnerabilityOperationEnum.UPDATE, 1L);
    return Arrays.asList(vuln1, vuln2, vuln1, vuln3, vuln2);
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)

Example 5 with VulnerabilityEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity 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)

Aggregations

VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)22 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)13 Test (org.junit.Test)13 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)12 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)10 Date (java.util.Date)6 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ArrayList (java.util.ArrayList)5 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)3 List (java.util.List)2 Set (java.util.Set)2 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)1 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)1 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)1 NotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper)1 VulnerabilityRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper)1 RealTimeEvent (com.blackducksoftware.integration.hub.alert.event.RealTimeEvent)1 MockVulnerabilityEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockVulnerabilityEntity)1 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1