Search in sources :

Example 11 with VulnerabilityEntity

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

the class NotificationManagerTestIT method testDeleteNotification.

@Test
public void testDeleteNotification() {
    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);
    assertEquals(1, notificationRepository.count());
    assertEquals(1, vulnerabilityRepository.count());
    notificationManager.deleteNotification(savedModel);
    assertEquals(0, notificationRepository.count());
    assertEquals(0, vulnerabilityRepository.count());
}
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 12 with VulnerabilityEntity

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

the class NotificationManagerTestIT method testFindByIdsInvalidIds.

@Test
public void testFindByIdsInvalidIds() {
    final NotificationEntity notificationEntity = createNotificationEntity();
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id2", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    final NotificationModel model = new NotificationModel(notificationEntity, vulnerabilityList);
    notificationManager.saveNotification(model);
    final List<Long> notificationIds = Arrays.asList(34L, 22L, 10L);
    final List<NotificationModel> notificationModelList = notificationManager.findByIds(notificationIds);
    assertTrue(notificationModelList.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 13 with VulnerabilityEntity

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

the class NotificationManagerTestIT method testDeleteNotificationList.

@Test
public void testDeleteNotificationList() {
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    final LocalDateTime time = LocalDateTime.now();
    final Date startDate = createDate(time.minusHours(1));
    final Date endDate = createDate(time.plusHours(1));
    final Date createdAt = createDate(time.minusHours(3));
    NotificationEntity entity = createNotificationEntity(createdAt);
    notificationManager.saveNotification(new NotificationModel(entity, vulnerabilityList));
    Date createdAtInRange = createDate(time.plusMinutes(1));
    final NotificationEntity entityToFind1 = createNotificationEntity(createdAtInRange);
    createdAtInRange = createDate(time.plusMinutes(5));
    final NotificationEntity entityToFind2 = createNotificationEntity(createdAtInRange);
    final Date createdAtLater = createDate(time.plusHours(3));
    entity = createNotificationEntity(createdAtLater);
    notificationManager.saveNotification(new NotificationModel(entity, vulnerabilityList));
    notificationManager.saveNotification(new NotificationModel(entityToFind1, vulnerabilityList));
    notificationManager.saveNotification(new NotificationModel(entityToFind2, vulnerabilityList));
    final List<NotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
    assertEquals(4, notificationRepository.count());
    assertEquals(4, vulnerabilityRepository.count());
    notificationManager.deleteNotificationList(foundList);
    assertEquals(2, notificationRepository.count());
    assertEquals(2, vulnerabilityRepository.count());
}
Also used : LocalDateTime(java.time.LocalDateTime) 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) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 14 with VulnerabilityEntity

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

the class VulnerabilityRepositoryTestIT method testFindByNotificationIdException.

@Test
public void testFindByNotificationIdException() throws Exception {
    final VulnerabilityEntity entity1 = createVulnerabilityEntity(1);
    final VulnerabilityRepositoryWrapper repositoryWrapper = Mockito.spy(repository);
    Mockito.doThrow(EncryptionException.class).when(repositoryWrapper).decryptSensitiveData(entity1);
    repositoryWrapper.save(entity1);
    final List<VulnerabilityEntity> vulnerabilityList = repositoryWrapper.findByNotificationId(1L);
    assertEquals(Collections.emptyList(), vulnerabilityList);
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 15 with VulnerabilityEntity

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

the class VulnerabilityRepositoryTestIT method testFindById.

@Test
public void testFindById() {
    final VulnerabilityEntity entity = createVulnerabilityEntity(1);
    final VulnerabilityEntity savedEntity = repository.save(entity);
    final long count = repository.count();
    assertEquals(1, count);
    final VulnerabilityEntity foundEntity = repository.findById(savedEntity.getId());
    assertEquals(savedEntity.getId(), foundEntity.getId());
    assertEquals(savedEntity.getVulnerabilityId(), foundEntity.getVulnerabilityId());
    assertEquals(savedEntity.getOperation(), foundEntity.getOperation());
    assertEquals(savedEntity.getNotificationId(), foundEntity.getNotificationId());
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

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