Search in sources :

Example 16 with VulnerabilityEntity

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

the class VulnerabilityRepositoryTestIT method testSaveEntity.

@Test
public void testSaveEntity() {
    final VulnerabilityEntity entity = createVulnerabilityEntity(1);
    final VulnerabilityEntity savedEntity = repository.save(entity);
    final long count = repository.count();
    assertEquals(1, count);
    final VulnerabilityEntity foundEntity = repository.findOne(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)

Example 17 with VulnerabilityEntity

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

the class PurgeJobIT method testWriterWithData.

@Test
public void testWriterWithData() throws Exception {
    final List<NotificationModel> entityList = new ArrayList<>();
    final String eventKey = "eventKey";
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
    final String projectName = "ProjectName";
    final String projectUrl = "ProjectUrl";
    final String projectVersion = "ProjectVersion";
    final String projectVersionUrl = "ProjectVersionUrl";
    final String componentName = "ComponentName";
    final String componentVersion = "ComponentVersion";
    final String policyRuleName = "PolicyRuleName";
    final String person = "PolicyPerson";
    final Collection<VulnerabilityEntity> vulnerabilityList = null;
    ZonedDateTime zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.minusDays(1);
    Date createdAt = Date.from(zonedDateTime.toInstant());
    NotificationEntity notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
    notificationRepository.save(notification);
    entityList.add(new NotificationModel(notification, vulnerabilityList));
    zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.minusDays(3);
    createdAt = Date.from(zonedDateTime.toInstant());
    notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
    notificationRepository.save(notification);
    entityList.add(new NotificationModel(notification, vulnerabilityList));
    zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
    zonedDateTime = zonedDateTime.plusDays(1);
    createdAt = Date.from(zonedDateTime.toInstant());
    notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
    notificationRepository.save(notification);
    entityList.add(new NotificationModel(notification, vulnerabilityList));
    assertEquals(3, notificationRepository.count());
    final List<List<NotificationModel>> itemList = new ArrayList<>();
    itemList.add(entityList);
    final PurgeWriter writer = purgeConfig.writer();
    writer.write(itemList);
    assertEquals(0, notificationRepository.count());
}
Also used : ArrayList(java.util.ArrayList) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) ArrayList(java.util.ArrayList) List(java.util.List) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 18 with VulnerabilityEntity

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

the class MockVulnerabilityEntity method createEntity.

@Override
public VulnerabilityEntity createEntity() {
    final VulnerabilityEntity entity = new VulnerabilityEntity(vulnerabilityId, operation, notificationId);
    entity.setId(id);
    return entity;
}
Also used : VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)

Example 19 with VulnerabilityEntity

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

the class ProjectDataFactoryTest method createPolicyNotification.

private NotificationModel createPolicyNotification(final String projectName, final String projectVersion) {
    final String eventKey = "key";
    final Date createdAt = new Date();
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.POLICY_VIOLATION;
    final String projectUrl = "http://localhost:8080";
    final String projectVersionUrl = "http://localhost:8080";
    final String componentName = "Other Component";
    final String componentVersion = "Other Component Version";
    final String policyRuleName = "Policy Rule Name";
    final String person = "Person";
    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, person);
    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 20 with VulnerabilityEntity

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

the class NotificationManager method saveNotification.

public NotificationModel saveNotification(final NotificationModel notification) {
    final NotificationEntity notificationEntity = notificationRepository.save(notification.getNotificationEntity());
    List<VulnerabilityEntity> vulnerabilities = Collections.emptyList();
    if (notification.getVulnerabilityList() != null) {
        final Collection<VulnerabilityEntity> vulnerabilityList = notification.getVulnerabilityList();
        final List<VulnerabilityEntity> vulnerabilitiesToSave = vulnerabilityList.stream().map(vulnerability -> new VulnerabilityEntity(vulnerability.getVulnerabilityId(), vulnerability.getOperation(), notificationEntity.getId())).collect(Collectors.toList());
        vulnerabilities = vulnerabilityRepository.save(vulnerabilitiesToSave);
    }
    return new NotificationModel(notificationEntity, vulnerabilities);
}
Also used : AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) VulnerabilityRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) Date(java.util.Date) Collection(java.util.Collection) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) List(java.util.List) Component(org.springframework.stereotype.Component) NotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) Collections(java.util.Collections) 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)

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