use of com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testGetException.
@Test
public void testGetException() throws AlertException, IOException {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final NotificationRepositoryWrapper notificationRepository = Mockito.mock(NotificationRepositoryWrapper.class);
final VulnerabilityRepositoryWrapper vulnerabilityRepository = Mockito.mock(VulnerabilityRepositoryWrapper.class);
final AuditNotificationRepositoryWrapper auditNotificationRepository = Mockito.mock(AuditNotificationRepositoryWrapper.class);
final CommonDistributionRepositoryWrapper commonDistributionRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
final ObjectTransformer objectTransformer = new ObjectTransformer();
final ObjectTransformer spyObjectTransformer = Mockito.spy(objectTransformer);
final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final MockNotificationEntity mockNotificationEntity = new MockNotificationEntity();
final MockCommonDistributionEntity mockCommonDistributionEntity = new MockCommonDistributionEntity();
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEmptyEntity());
Mockito.when(commonDistributionRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(mockCommonDistributionEntity.createEntity());
Mockito.doThrow(new AlertException()).when(spyObjectTransformer).databaseEntityToConfigRestModel(Mockito.any(), Mockito.any());
Mockito.when(notificationRepository.findAll(Mockito.any())).thenReturn(Arrays.asList(mockNotificationEntity.createEntity()));
final AuditEntryActions auditEntryActions = new AuditEntryActions(auditEntryRepository, new NotificationManager(notificationRepository, vulnerabilityRepository, auditEntryRepository, auditNotificationRepository), auditNotificationRepository, commonDistributionRepositoryWrapper, spyObjectTransformer, null, null, null);
auditEntryActions.get(1L);
assertTrue(outputLogger.isLineContainingText("Problem converting audit entry"));
}
use of com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity 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.mock.entity.MockCommonDistributionEntity 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.mock.entity.MockCommonDistributionEntity in project hub-alert by blackducksoftware.
the class AuditEntryControllerTestIT method setup.
@Before
public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(SecurityMockMvcConfigurers.springSecurity()).build();
auditEntryRepository.deleteAllInBatch();
commonDistributionRepository.deleteAllInBatch();
auditNotificationRepository.deleteAllInBatch();
notificationRepository.deleteAllInBatch();
mockAuditEntity = new MockAuditEntryEntity();
mockCommonDistributionEntity = new MockCommonDistributionEntity();
}
use of com.blackducksoftware.integration.hub.alert.mock.entity.MockCommonDistributionEntity in project hub-alert by blackducksoftware.
the class CommonDistributionRepositoryWrapperTest method getMockedRepository.
@Override
public CommonDistributionRepository getMockedRepository() {
final MockCommonDistributionEntity mockCommonDistributionEntity = getMockEntityUtil();
final CommonDistributionRepository commonDistributionRepository = Mockito.mock(CommonDistributionRepository.class);
Mockito.when(commonDistributionRepository.findByDistributionConfigIdAndDistributionType(Mockito.anyLong(), Mockito.anyString())).thenReturn(mockCommonDistributionEntity.createEntity());
return commonDistributionRepository;
}
Aggregations