Search in sources :

Example 11 with NotificationEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.

the class NotificationModelTest method testNotificationNull.

@Test
public void testNotificationNull() {
    final NotificationEntity entity = null;
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vuln1);
    final NotificationModel model = new NotificationModel(entity, vulnerabilityList);
    assertNull(model.getComponentName());
    assertNull(model.getComponentVersion());
    assertNull(model.getCreatedAt());
    assertNull(model.getEventKey());
    assertNull(model.getNotificationEntity());
    assertNull(model.getNotificationType());
    assertNull(model.getPolicyRuleName());
    assertNull(model.getPolicyRuleUser());
    assertNull(model.getProjectName());
    assertNull(model.getProjectUrl());
    assertNull(model.getProjectVersion());
    assertNull(model.getProjectVersionUrl());
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    final boolean allEqual = model.getVulnerabilityList().stream().allMatch(vuln1::equals);
    assertTrue(allEqual);
}
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) Test(org.junit.Test)

Example 12 with NotificationEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.

the class NotificationModelTest method testModel.

@Test
public void testModel() {
    final NotificationEntity entity = createNotificationEntity();
    final VulnerabilityEntity vuln1 = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, 1L);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vuln1);
    final NotificationModel model = new NotificationModel(entity, vulnerabilityList);
    assertEquals(entity.getComponentName(), model.getComponentName());
    assertEquals(entity.getComponentVersion(), model.getComponentVersion());
    assertEquals(entity.getCreatedAt(), model.getCreatedAt());
    assertEquals(entity.getEventKey(), model.getEventKey());
    assertEquals(entity, model.getNotificationEntity());
    assertEquals(entity.getNotificationType(), model.getNotificationType());
    assertEquals(entity.getPolicyRuleName(), model.getPolicyRuleName());
    assertEquals(entity.getPolicyRuleUser(), model.getPolicyRuleUser());
    assertEquals(entity.getProjectName(), model.getProjectName());
    assertEquals(entity.getProjectUrl(), model.getProjectUrl());
    assertEquals(entity.getProjectVersion(), model.getProjectVersion());
    assertEquals(entity.getProjectVersionUrl(), model.getProjectVersionUrl());
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    final boolean allEqual = model.getVulnerabilityList().stream().allMatch(vuln1::equals);
    assertTrue(allEqual);
}
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) Test(org.junit.Test)

Example 13 with NotificationEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity 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());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) 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 14 with NotificationEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.

the class NotificationRepositoryTestIT method createEntity.

private NotificationEntity createEntity(final String dateString) throws ParseException {
    final Date createdAt = RestConnection.parseDateString(dateString);
    final NotificationEntity entity = createNotificationEntity(createdAt);
    final NotificationEntity savedEntity = repository.save(entity);
    return savedEntity;
}
Also used : NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.util.Date)

Example 15 with NotificationEntity

use of com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity in project hub-alert by blackducksoftware.

the class NotificationRepositoryTestIT 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 NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, null, projectVersion, null, componentName, componentVersion, policyRuleName, person);
    return entity;
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

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