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