Search in sources :

Example 1 with NotificationEntity

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

the class NotificationManagerTestIT method findByCreatedAtBetween.

@Test
public void findByCreatedAtBetween() {
    final LocalDateTime time = LocalDateTime.now();
    final Date startDate = createDate(time.minusHours(1));
    final Date endDate = createDate(time.plusHours(1));
    Date createdAt = createDate(time.minusHours(3));
    NotificationEntity entity = createNotificationEntity(createdAt);
    notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
    createdAt = createDate(time.plusMinutes(1));
    final NotificationEntity entityToFind1 = createNotificationEntity(createdAt);
    createdAt = createDate(time.plusMinutes(5));
    final NotificationEntity entityToFind2 = createNotificationEntity(createdAt);
    createdAt = createDate(time.plusHours(3));
    entity = createNotificationEntity(createdAt);
    notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
    notificationManager.saveNotification(new NotificationModel(entityToFind1, Collections.emptyList()));
    notificationManager.saveNotification(new NotificationModel(entityToFind2, Collections.emptyList()));
    final List<NotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
    assertEquals(2, foundList.size());
    assertNotificationModel(entityToFind1, foundList.get(0));
    assertNotificationModel(entityToFind2, foundList.get(1));
}
Also used : LocalDateTime(java.time.LocalDateTime) 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 2 with NotificationEntity

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

the class NotificationManagerTestIT method findByCreatedAtBetweenInvalidDate.

@Test
public void findByCreatedAtBetweenInvalidDate() {
    final LocalDateTime time = LocalDateTime.now();
    final Date startDate = createDate(time.minusHours(1));
    final Date endDate = createDate(time.plusHours(1));
    final Date createdAtEarlier = createDate(time.minusHours(5));
    NotificationEntity entity = createNotificationEntity(createdAtEarlier);
    notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
    final Date createdAtLater = createDate(time.plusHours(3));
    entity = createNotificationEntity(createdAtLater);
    notificationManager.saveNotification(new NotificationModel(entity, Collections.emptyList()));
    final List<NotificationModel> foundList = notificationManager.findByCreatedAtBetween(startDate, endDate);
    assertTrue(foundList.isEmpty());
}
Also used : LocalDateTime(java.time.LocalDateTime) 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 3 with NotificationEntity

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

the class NotificationManagerTestIT method testSave.

@Test
public void testSave() {
    final NotificationEntity notificationEntity = createNotificationEntity();
    final VulnerabilityEntity vulnerabilityEntity = new VulnerabilityEntity("id1", VulnerabilityOperationEnum.ADD, null);
    final List<VulnerabilityEntity> vulnerabilityList = Arrays.asList(vulnerabilityEntity);
    NotificationModel model = new NotificationModel(notificationEntity, vulnerabilityList);
    NotificationModel savedModel = notificationManager.saveNotification(model);
    assertNotNull(savedModel.getNotificationEntity().getId());
    assertNotificationModel(notificationEntity, savedModel);
    assertEquals(vulnerabilityList.size(), model.getVulnerabilityList().size());
    model = new NotificationModel(notificationEntity, null);
    savedModel = notificationManager.saveNotification(model);
    assertNotNull(savedModel.getNotificationEntity().getId());
    assertNotificationModel(notificationEntity, savedModel);
    assertTrue(model.getVulnerabilityList().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 4 with NotificationEntity

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

the class NotificationManagerTestIT method testFindByIds.

@Test
public void testFindByIds() {
    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);
    final List<Long> notificationIds = Arrays.asList(savedModel.getNotificationEntity().getId());
    final List<NotificationModel> notificationModelList = notificationManager.findByIds(notificationIds);
    assertEquals(1, notificationModelList.size());
}
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 5 with NotificationEntity

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

the class AuditEntryControllerTestIT method testPostConfig.

@Test
@WithMockUser(roles = "ADMIN")
public void testPostConfig() throws Exception {
    CommonDistributionConfigEntity commonEntity = mockCommonDistributionEntity.createEntity();
    final MockNotificationEntity mockNotifications = new MockNotificationEntity();
    NotificationEntity notificationEntity = mockNotifications.createEntity();
    notificationEntity = notificationRepository.save(notificationEntity);
    commonEntity = commonDistributionRepository.save(commonEntity);
    mockAuditEntity.setCommonConfigId(commonEntity.getId());
    AuditEntryEntity auditEntity = mockAuditEntity.createEntity();
    auditEntity = auditEntryRepository.save(auditEntity);
    auditNotificationRepository.save(new AuditNotificationRelation(auditEntity.getId(), notificationEntity.getId()));
    final String resendUrl = auditUrl + "/" + String.valueOf(auditEntity.getId()) + "/" + "/resend";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(resendUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) CommonDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) AuditNotificationRelation(com.blackducksoftware.integration.hub.alert.audit.repository.relation.AuditNotificationRelation) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) AuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryEntity) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) NotificationEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.NotificationEntity) WithMockUser(org.springframework.security.test.context.support.WithMockUser) 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