Search in sources :

Example 21 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class NotificationManagerTestIT method testDeleteNotification.

@Test
public void testDeleteNotification() {
    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);
    assertEquals(1, notificationRepository.count());
    assertEquals(1, vulnerabilityRepository.count());
    notificationManager.deleteNotification(savedModel);
    assertEquals(0, notificationRepository.count());
    assertEquals(0, vulnerabilityRepository.count());
}
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 22 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class NotificationManagerTestIT method testFindByIdsInvalidIds.

@Test
public void testFindByIdsInvalidIds() {
    final NotificationEntity notificationEntity = createNotificationEntity();
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id2", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    final NotificationModel model = new NotificationModel(notificationEntity, vulnerabilityList);
    notificationManager.saveNotification(model);
    final List<Long> notificationIds = Arrays.asList(34L, 22L, 10L);
    final List<NotificationModel> notificationModelList = notificationManager.findByIds(notificationIds);
    assertTrue(notificationModelList.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 23 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class NotificationManagerTestIT method testDeleteNotificationList.

@Test
public void testDeleteNotificationList() {
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    final LocalDateTime time = LocalDateTime.now();
    final Date startDate = createDate(time.minusHours(1));
    final Date endDate = createDate(time.plusHours(1));
    final Date createdAt = createDate(time.minusHours(3));
    NotificationEntity entity = createNotificationEntity(createdAt);
    notificationManager.saveNotification(new NotificationModel(entity, vulnerabilityList));
    Date createdAtInRange = createDate(time.plusMinutes(1));
    final NotificationEntity entityToFind1 = createNotificationEntity(createdAtInRange);
    createdAtInRange = createDate(time.plusMinutes(5));
    final NotificationEntity entityToFind2 = createNotificationEntity(createdAtInRange);
    final Date createdAtLater = createDate(time.plusHours(3));
    entity = createNotificationEntity(createdAtLater);
    notificationManager.saveNotification(new NotificationModel(entity, vulnerabilityList));
    notificationManager.saveNotification(new NotificationModel(entityToFind1, vulnerabilityList));
    notificationManager.saveNotification(new NotificationModel(entityToFind2, vulnerabilityList));
    final List<NotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
    assertEquals(4, notificationRepository.count());
    assertEquals(4, vulnerabilityRepository.count());
    notificationManager.deleteNotificationList(foundList);
    assertEquals(2, notificationRepository.count());
    assertEquals(2, vulnerabilityRepository.count());
}
Also used : LocalDateTime(java.time.LocalDateTime) 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) Date(java.util.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 24 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel in project hub-alert by blackducksoftware.

the class RealTimeListenerTest method testReceiveMessage.

@Test
public void testReceiveMessage() {
    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);
    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);
    Mockito.doNothing().when(channelTemplateManager).sendEvents(Mockito.any());
    Mockito.verify(channelTemplateManager).sendEvents(Mockito.any());
}
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) 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)

Example 25 with NotificationModel

use of com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel 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());
}
Also used : ArrayList(java.util.ArrayList) NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) VulnerabilityEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) ArrayList(java.util.ArrayList) List(java.util.List) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) 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