use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT method findByCreatedAtBetween.
@Test
public void findByCreatedAtBetween() {
final LocalDateTime time = LocalDateTime.now();
final Date startDate = createDate(time.minusHours(1));
final Date endDate = createDate(time.plusHours(1));
Date createdAt = createDate(time.minusHours(3));
NotificationEntity entity = createNotificationEntity(createdAt);
notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
createdAt = createDate(time.plusMinutes(1));
final NotificationEntity entityToFind1 = createNotificationEntity(createdAt);
createdAt = createDate(time.plusMinutes(5));
final NotificationEntity entityToFind2 = createNotificationEntity(createdAt);
createdAt = createDate(time.plusHours(3));
entity = createNotificationEntity(createdAt);
notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
notificationManager.saveNotification(new NotificationModel(entityToFind1, Collections.emptyList()));
notificationManager.saveNotification(new NotificationModel(entityToFind2, Collections.emptyList()));
final List<NotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
assertEquals(2, foundList.size());
assertNotificationModel(entityToFind1, foundList.get(0));
assertNotificationModel(entityToFind2, foundList.get(1));
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT method findByCreatedAtBetweenInvalidDate.
@Test
public void findByCreatedAtBetweenInvalidDate() {
final LocalDateTime time = LocalDateTime.now();
final Date startDate = createDate(time.minusHours(1));
final Date endDate = createDate(time.plusHours(1));
final Date createdAtEarlier = createDate(time.minusHours(5));
NotificationEntity entity = createNotificationEntity(createdAtEarlier);
notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
final Date createdAtLater = createDate(time.plusHours(3));
entity = createNotificationEntity(createdAtLater);
notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
final List<NotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
assertTrue(foundList.isEmpty());
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT method testSave.
@Test
public void testSave() {
final NotificationEntity notificationEntity = createNotificationEntity();
final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, null);
final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
NotificationModel model = new NotificationModel(notificationEntity, vulnerabilityList);
NotificationModel savedModel = notificationManager.saveNotification(model);
assertNotNull(savedModel.getNotificationEntity().getId());
assertNotificationModel(notificationEntity, savedModel);
assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
model = new NotificationModel(notificationEntity, null);
savedModel = notificationManager.saveNotification(model);
assertNotNull(savedModel.getNotificationEntity().getId());
assertNotificationModel(notificationEntity, savedModel);
assertTrue(model.getVulnerabilityList().isEmpty());
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class NotificationManagerTestIT method testFindByIds.
@Test
public void testFindByIds() {
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);
final List<Long> notificationIds = Arrays.asList(savedModel.getNotificationEntity().getId());
final List<NotificationModel> notificationModelList = notificationManager.findByIds(notificationIds);
assertEquals(1, notificationModelList.size());
}
use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.
the class RealTimeListenerTest method testReceiveMessageException.
@SuppressWarnings("unchecked")
@Test
public void testReceiveMessageException() throws IOException, Exception {
try (OutputLogger outputLogger = new OutputLogger()) {
final Gson gson = new Gson();
final MockNotificationEntity notificationEntity = new MockNotificationEntity();
final NotificationModel model = new NotificationModel(notificationEntity.createEntity(), Collections.emptyList());
final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
final ProjectDataFactory projectDataFactory = Mockito.mock(ProjectDataFactory.class);
final NotificationEventManager eventManager = Mockito.mock(NotificationEventManager.class);
Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.any());
Mockito.doThrow(new NullPointerException("null error")).when(projectDataFactory).createProjectDataCollection(Mockito.anyCollection(), Mockito.any());
final RealTimeListener realTimeListener = new RealTimeListener(gson, channelTemplateManager, projectDataFactory, eventManager);
final RealTimeEvent realTimeEvent = new RealTimeEvent(Arrays.asList(model));
final String realTimeEventString = gson.toJson(realTimeEvent);
realTimeListener.receiveMessage(realTimeEventString);
assertTrue(outputLogger.isLineContainingText("null"));
}
}
Aggregations