Search in sources :

Example 6 with NotificationEntity

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

the class AuditEntryHandlerTestIT method resendNotificationTestIt.

@Test
public void resendNotificationTestIt() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    final AuditEntryEntity badAuditEntryEntity_1 = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final AuditEntryEntity badAuditEntryEntity_2 = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final AuditEntryEntity badAuditEntryEntityBoth = auditEntryRepository.save(new AuditEntryEntity(-1L, new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, "Failed: stuff happened", ""));
    final ResponseEntity<String> invalidIdResponse = auditEntryHandler.resendNotification(-1L);
    assertEquals(HttpStatus.BAD_REQUEST, invalidIdResponse.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_1 = auditEntryHandler.resendNotification(badAuditEntryEntity_1.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_1.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponse_2 = auditEntryHandler.resendNotification(badAuditEntryEntity_2.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponse_2.getStatusCode());
    final ResponseEntity<String> invalidReferenceResponseBoth = auditEntryHandler.resendNotification(badAuditEntryEntityBoth.getId());
    assertEquals(HttpStatus.GONE, invalidReferenceResponseBoth.getStatusCode());
    final ResponseEntity<String> validResponse = auditEntryHandler.resendNotification(savedAuditEntryEntity.getId());
    assertEquals(HttpStatus.OK, validResponse.getStatusCode());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 7 with NotificationEntity

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

the class AuditEntryHandlerTestIT method getTestIT.

@Test
public void getTestIT() {
    final MockNotificationEntity mockNotification = new MockNotificationEntity();
    final MockCommonDistributionEntity mockDistributionConfig = new MockCommonDistributionEntity();
    final NotificationEntity savedNotificationEntity = notificationRepository.save(mockNotification.createEntity());
    final CommonDistributionConfigEntity savedConfigEntity = commonDistributionRepository.save(mockDistributionConfig.createEntity());
    final AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(savedConfigEntity.getId(), new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis()), StatusEnum.SUCCESS, null, null));
    auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
    final List<AuditEntryRestModel> auditEntries = auditEntryHandler.get();
    assertEquals(1, auditEntries.size());
    final AuditEntryRestModel auditEntry = auditEntryHandler.get(savedAuditEntryEntity.getId());
    assertNotNull(auditEntry);
    assertEquals(auditEntry, auditEntries.get(0));
    assertEquals(savedAuditEntryEntity.getId().toString(), auditEntry.getId());
    assertEquals(savedConfigEntity.getDistributionType(), auditEntry.getEventType());
    assertEquals(savedConfigEntity.getName(), auditEntry.getName());
    final NotificationRestModel notification = auditEntry.getNotification();
    assertEquals(savedNotificationEntity.getEventKey(), notification.getEventKey());
    assertEquals(savedNotificationEntity.getCreatedAt().toString(), notification.getCreatedAt());
    assertEquals(savedNotificationEntity.getNotificationType().name(), notification.getNotificationTypes().iterator().next());
    assertEquals(savedNotificationEntity.getProjectName(), notification.getProjectName());
    assertEquals(savedNotificationEntity.getProjectVersion(), notification.getProjectVersion());
    assertEquals(savedNotificationEntity.getProjectUrl(), notification.getProjectUrl());
    assertEquals(savedNotificationEntity.getProjectVersionUrl(), notification.getProjectVersionUrl());
    assertNotNull(notification.getComponents());
    assertTrue(!notification.getComponents().isEmpty());
    final ComponentRestModel component = notification.getComponents().iterator().next();
    assertEquals(savedNotificationEntity.getComponentName(), component.getComponentName());
    assertEquals(savedNotificationEntity.getComponentVersion(), component.getComponentVersion());
    assertEquals(savedNotificationEntity.getPolicyRuleName(), component.getPolicyRuleName());
    assertEquals(savedNotificationEntity.getPolicyRuleUser(), component.getPolicyRuleUser());
}
Also used : ComponentRestModel(com.blackducksoftware.integration.hub.alert.web.model.ComponentRestModel) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) NotificationRestModel(com.blackducksoftware.integration.hub.alert.web.model.NotificationRestModel) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockCommonDistributionEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) Date(java.sql.Date) DatabaseConnectionTest(com.blackducksoftware.integration.test.annotation.DatabaseConnectionTest) Test(org.junit.Test)

Example 8 with NotificationEntity

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

the class DigestRemovalProcessorTest method createVulnerabilityNotifications.

private List<NotificationModel> createVulnerabilityNotifications() {
    final String keyPrefix = "key";
    final String projectName = "Project Name";
    final String projectVersion = "Project Version";
    final NotificationEntity notification1 = new NotificationEntity(keyPrefix + "1", null, NotificationCategoryEnum.HIGH_VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationEntity notification2 = new NotificationEntity(keyPrefix + "2", null, NotificationCategoryEnum.MEDIUM_VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationEntity notification3 = new NotificationEntity(keyPrefix + "3", null, NotificationCategoryEnum.LOW_VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationEntity notification4 = new NotificationEntity(keyPrefix + "4", null, NotificationCategoryEnum.VULNERABILITY, projectName, "", projectVersion, "", "", "", "", "");
    final NotificationModel model1 = new NotificationModel(notification1, createVulnerabilityList());
    final NotificationModel model2 = new NotificationModel(notification2, createVulnerabilityList());
    final NotificationModel model3 = new NotificationModel(notification3, createVulnerabilityList());
    final NotificationModel model4 = new NotificationModel(notification4, Collections.emptyList());
    return Arrays.asList(model1, model2, model1, model3, model2, model4);
}
Also used : NotificationModel(com.blackducksoftware.integration.hub.alert.hub.model.NotificationModel) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity)

Example 9 with NotificationEntity

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

the class ProjectDataFactoryTest method createVulnerabilityNotification.

private NotificationModel createVulnerabilityNotification(final String projectName, final String projectVersion) {
    final String eventKey = "key";
    final Date createdAt = new Date();
    final NotificationCategoryEnum notificationType = NotificationCategoryEnum.MEDIUM_VULNERABILITY;
    final String projectUrl = "http://localhost:8080";
    final String projectVersionUrl = "http://localhost:8080";
    final String componentName = "Component";
    final String componentVersion = "Component Version";
    final String policyRuleName = null;
    final String policyRuleUser = null;
    final String vulnerabilityId = NotificationCategoryEnum.VULNERABILITY.name();
    final VulnerabilityOperationEnum vulnerabilityOperation = VulnerabilityOperationEnum.ADD;
    final NotificationEntity notification = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, policyRuleUser);
    notification.setId(1L);
    final Collection<VulnerabilityEntity> vulnerabilityList = Arrays.asList(new VulnerabilityEntity(vulnerabilityId, vulnerabilityOperation, notification.getId()));
    return new NotificationModel(notification, vulnerabilityList);
}
Also used : NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) VulnerabilityOperationEnum(com.blackducksoftware.integration.hub.alert.enumeration.VulnerabilityOperationEnum) 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)

Example 10 with NotificationEntity

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

the class MockNotificationEntity method createEntity.

@Override
public NotificationEntity createEntity() {
    final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, policyRuleUser);
    entity.setId(id);
    return entity;
}
Also used : 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