Search in sources :

Example 21 with NotificationEntity

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;
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 22 with NotificationEntity

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;
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date)

Example 23 with NotificationEntity

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());
}
Also used : 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 NotificationEntity

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

Example 25 with NotificationEntity

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());
}
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

NotificationEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)31 NotificationModel (com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel)21 Test (org.junit.Test)20 DatabaseConnectionTest (com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest)18 Date (java.util.Date)17 VulnerabilityEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.VulnerabilityEntity)12 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)8 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)6 ArrayList (java.util.ArrayList)6 AuditNotificationRelation (com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation)4 LocalDateTime (java.time.LocalDateTime)4 AuditEntryEntity (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity)3 ConfiguredProjectEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.ConfiguredProjectEntity)3 DistributionProjectRelation (com.blackducksoftware.integration.hub.alert.datasource.relation.DistributionProjectRelation)3 DigestTypeEnum (com.blackducksoftware.integration.hub.alert.enumeration.DigestTypeEnum)3 AbstractChannelEvent (com.blackducksoftware.integration.hub.alert.event.AbstractChannelEvent)3 MockNotificationEntity (com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity)3 CommonDistributionConfigRestModel (com.blackducksoftware.integration.hub.alert.web.model.distribution.CommonDistributionConfigRestModel)3 HipChatEvent (com.blackducksoftware.integration.hub.alert.channel.hipchat.HipChatEvent)2 VulnerabilityOperationEnum (com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum)2