use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class PurgeJobIT method testReaderWithData.
@Test
public void testReaderWithData() throws Exception {
final List<NotificationEntity> 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";
ZonedDateTime zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
zonedDateTime = zonedDateTime.minusDays(1);
Date createdAt = Date.from(zonedDateTime.toInstant());
entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
zonedDateTime = zonedDateTime.minusDays(3);
createdAt = Date.from(zonedDateTime.toInstant());
entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
zonedDateTime = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
zonedDateTime = zonedDateTime.plusDays(1);
createdAt = Date.from(zonedDateTime.toInstant());
entityList.add(new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person));
notificationRepository.save(entityList);
final PurgeReader reader = purgeConfig.reader();
final List<NotificationModel> resultList = reader.read();
assertEquals(2, resultList.size());
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class PurgeJobIT method testProcessorWithData.
@Test
public void testProcessorWithData() throws Exception {
final List<NotificationModel> entityList = new ArrayList<>();
entityList.add(new NotificationModel(null, null));
entityList.add(new NotificationModel(null, null));
entityList.add(new NotificationModel(null, null));
entityList.add(new NotificationModel(null, null));
entityList.add(new NotificationModel(null, null));
final PurgeProcessor processor = purgeConfig.processor();
final List<NotificationModel> resultList = processor.process(entityList);
assertEquals(entityList, resultList);
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class DailyItemReaderTest method testReadException.
@Test
public void testReadException() throws Exception {
final NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
Mockito.when(notificationManager.findByCreatedAtBetween(Mockito.any(), Mockito.any())).thenReturn(null);
final DailyItemReader dailyItemReaderException = new DailyItemReader(notificationManager, globalProperties);
final List<NotificationModel> nullNotificationList = dailyItemReaderException.read();
assertNull(nullNotificationList);
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class DailyItemReader method read.
@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
List<NotificationModel> notificationList;
PhoneHomeResponse phoneHomeResponse = null;
try {
notificationList = super.read();
phoneHomeResponse = phoneHome();
} finally {
if (phoneHomeResponse != null) {
phoneHomeResponse.endPhoneHome();
}
}
return notificationList;
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class DigestItemReader method read.
@Override
public List<NotificationModel> read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
try {
if (hasRead) {
return null;
} else {
logger.debug("{} Digest Item Reader called...", readerName);
final DateRange dateRange = getDateRange();
final Date startDate = dateRange.getStart();
final Date endDate = dateRange.getEnd();
final List<NotificationModel> entityList = notificationManager.findByCreatedAtBetween(startDate, endDate);
hasRead = true;
if (entityList.isEmpty()) {
return null;
} else {
return entityList;
}
}
} catch (final Exception ex) {
logger.error("Error reading Digest Notification Data", ex);
}
return null;
}
Aggregations