use of com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity 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.audit.mock.MockAuditEntryEntity 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.audit.mock.MockAuditEntryEntity in project hub-alert by blackducksoftware.
the class ChannelTemplateManagerTest method testSendEvents.
@Test
public void testSendEvents() {
final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = Mockito.mock(AuditEntryRepositoryWrapper.class);
Mockito.when(auditEntryRepositoryWrapper.save(Mockito.any(AuditEntryEntity.class))).thenReturn(mockAuditEntryEntity.createEntity());
final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), auditEntryRepositoryWrapper, null, null) {
@Override
public boolean hasTemplate(final String destination) {
return true;
}
@Override
public AbstractJmsTemplate getTemplate(final String destination) {
testCount++;
final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
return abstractJmsTemplate;
}
};
testCount = 0;
final ProjectData projectData = new ProjectData(DigestTypeEnum.DAILY, "test", "version", Arrays.asList(), null);
final HipChatEvent slackEvent = new HipChatEvent(projectData, 1L);
channelTemplateManager.sendEvents(Arrays.asList(slackEvent));
assertEquals(1, testCount);
}
use of com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryRepositoryWrapperTest method testFindFirstByCommonConfigIdOrderByTimeLastSentDesc.
@Test
public void testFindFirstByCommonConfigIdOrderByTimeLastSentDesc() throws IOException {
final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final AuditEntryRepository repository = Mockito.mock(AuditEntryRepository.class);
Mockito.when(repository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEntity());
final AuditEntryRepositoryWrapper auditEntryRepositoryWrapper = new AuditEntryRepositoryWrapper(repository) {
@Override
public AuditEntryEntity decryptSensitiveData(final AuditEntryEntity entity) throws EncryptionException {
throw new EncryptionException();
}
};
final AuditEntryEntity actual = auditEntryRepositoryWrapper.findFirstByCommonConfigIdOrderByTimeLastSentDesc(1L);
assertNull(actual);
assertTrue(outputLogger.isLineContainingText("Error finding common distribution config"));
}
use of com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testResendNotificationException.
@Test
public void testResendNotificationException() {
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 MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
final MockNotificationEntity mockNotificationEntity = new MockNotificationEntity();
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEmptyEntity());
Mockito.when(commonDistributionRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(null);
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, null, null, null, null);
List<AuditEntryRestModel> restModel = null;
try {
restModel = auditEntryActions.resendNotification(1L);
fail();
} catch (final IllegalArgumentException e) {
assertTrue(true);
} catch (final IntegrationException e) {
fail();
}
assertNull(restModel);
}
Aggregations