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());
}
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());
}
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;
}
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);
}
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);
}
Aggregations