Search in sources :

Example 1 with NotificationModel

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));
}
Also used : LocalDateTime(java.time.LocalDateTime) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 2 with NotificationModel

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());
}
Also used : LocalDateTime(java.time.LocalDateTime) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 3 with NotificationModel

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());
}
Also used : 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) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 4 with NotificationModel

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());
}
Also used : 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) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 5 with NotificationModel

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"));
    }
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) NotificationEventManager(com.blackducksoftware.integration.hub.alert.digest.filter.NotificationEventManager) OutputLogger(com.blackducksoftware.integration.hub.alert.OutputLogger) Gson(com.google.gson.Gson) RealTimeEvent(com.blackducksoftware.integration.hub.alert.event.RealTimeEvent) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) ProjectDataFactory(com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory) Test(org.junit.Test)

Aggregations

NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)39 Test (org.junit.Test)25 NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)21 Date (java.util.Date)15 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)14 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)13 ArrayList (java.util.ArrayList)10 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)6 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)5 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)5 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)5 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)5 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)5 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)4 ProjectDataFactory (com.blackducksoftware.integration.hub.alert.digest.model.ProjectDataFactory)4 LocalDateTime (java.time.LocalDateTime)4 List (java.util.List)4 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)3 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)3