use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT method createNotificationEntity.
private NotificationEntity createNotificationEntity(final Date createdAt) {
final String eventKey = "event_key_for_notification";
final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
final String projectName = "projectName";
final String projectVersion = "projectVersion";
final String componentName = "componentName";
final String componentVersion = "componentVersion";
final String policyRuleName = "policyRuleName";
final String person = "person";
final String projectUrl = "projectURL";
final String projectVersionUrl = "projectVersionUrl";
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
return entity;
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationModelTest method createNotificationEntity.
private NotificationEntity createNotificationEntity() {
final String eventKey = "event_key_for_notification";
final Date createdAt = Date.from(LocalDateTime.now().toInstant(ZoneOffset.UTC));
final NotificationCategoryEnum notificationType = NotificationCategoryEnum.VULNERABILITY;
final String projectName = "projectName";
final String projectVersion = "projectVersion";
final String componentName = "componentName";
final String componentVersion = "componentVersion";
final String policyRuleName = "policyRuleName";
final String person = "person";
final String projectUrl = "projectURL";
final String projectVersionUrl = "projectVersionUrl";
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
return entity;
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationRepositoryTestIT method testSaveEntity.
@Test
public void testSaveEntity() {
final Date createdAt = Date.from(Instant.now());
final NotificationEntity entity = createNotificationEntity(createdAt);
final NotificationEntity savedEntity = repository.save(entity);
final long count = repository.count();
assertEquals(1, count);
final NotificationEntity foundEntity = repository.findOne(savedEntity.getId());
assertEquals(entity.getEventKey(), foundEntity.getEventKey());
assertEquals(entity.getNotificationType(), foundEntity.getNotificationType());
assertEquals(entity.getProjectName(), foundEntity.getProjectName());
assertEquals(entity.getProjectVersion(), foundEntity.getProjectVersion());
assertEquals(entity.getComponentName(), foundEntity.getComponentName());
assertEquals(entity.getComponentVersion(), foundEntity.getComponentVersion());
assertEquals(entity.getPolicyRuleName(), foundEntity.getPolicyRuleName());
assertEquals(entity.getPolicyRuleUser(), foundEntity.getPolicyRuleUser());
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.
the class NotificationRepositoryTestIT method testFindByDate.
@Test
public void testFindByDate() throws Exception {
final Set<String> validResultDates = new HashSet<>();
NotificationEntity savedEntity = createEntity("2017-10-15T1:00:00.000Z");
validResultDates.add(RestConnection.formatDate(savedEntity.getCreatedAt()));
savedEntity = createEntity("2017-10-21T14:00:00.000Z");
validResultDates.add(RestConnection.formatDate(savedEntity.getCreatedAt()));
savedEntity = createEntity("2017-10-22T14:00:00.000Z");
validResultDates.add(RestConnection.formatDate(savedEntity.getCreatedAt()));
savedEntity = createEntity("2017-10-23T14:00:00.000Z");
validResultDates.add(RestConnection.formatDate(savedEntity.getCreatedAt()));
savedEntity = createEntity("2017-10-30T14:00:00.000Z");
validResultDates.add(RestConnection.formatDate(savedEntity.getCreatedAt()));
createEntity("2017-10-10T16:00:00.000Z");
createEntity("2017-10-31T15:00:00.000Z");
createEntity("2017-10-31T16:00:00.000Z");
createEntity("2017-10-31T17:00:00.000Z");
createEntity("2017-10-31T18:00:00.000Z");
final long count = repository.count();
assertEquals(10, count);
final Date startDate = RestConnection.parseDateString("2017-10-12T01:30:59.000Z");
final Date endDate = RestConnection.parseDateString("2017-10-30T16:59:59.000Z");
final List<NotificationEntity> foundEntityList = repository.findByCreatedAtBetween(startDate, endDate);
assertEquals(5, foundEntityList.size());
foundEntityList.forEach(entity -> {
final String createdAtString = RestConnection.formatDate(entity.getCreatedAt());
assertTrue(validResultDates.contains(createdAtString));
});
}
use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity 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());
}
Aggregations