use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class DistributionChannelTest method receiveMessageTest.
@Test
public void receiveMessageTest() {
final GlobalProperties globalProperties = new TestGlobalProperties();
final Gson gson = new Gson();
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final GlobalEmailRepositoryWrapper globalEmailRepositoryWrapper = Mockito.mock(GlobalEmailRepositoryWrapper.class);
final EmailGroupDistributionRepositoryWrapper emailGroupRepositoryWrapper = Mockito.mock(EmailGroupDistributionRepositoryWrapper.class);
final CommonDistributionRepositoryWrapper commonRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
final EmailGroupChannel channel = new EmailGroupChannel(globalProperties, gson, auditEntryRepository, globalEmailRepositoryWrapper, emailGroupRepositoryWrapper, commonRepositoryWrapper);
final Long commonId = 1L;
final EmailGroupEvent event = new EmailGroupEvent(createProjectData("Distribution Channel Test"), commonId);
final String jsonRepresentation = gson.toJson(event);
final CommonDistributionConfigEntity commonEntity = new CommonDistributionConfigEntity(commonId, SupportedChannels.EMAIL_GROUP, "Email Config", DigestTypeEnum.REAL_TIME, false);
Mockito.when(commonRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(commonEntity);
final EmailGroupDistributionConfigEntity specificEntity = new EmailGroupDistributionConfigEntity("admins", "", "TEST SUBJECT LINE");
Mockito.when(emailGroupRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(specificEntity);
channel.receiveMessage(jsonRepresentation);
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class DistributionChannelTest method setAuditEntryFailureTest.
@Test
public void setAuditEntryFailureTest() {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final EmailGroupChannel channel = new EmailGroupChannel(null, null, auditEntryRepository, null, null, null);
final AuditEntryEntity entity = new AuditEntryEntity(1L, new Date(System.currentTimeMillis() - 1000), new Date(System.currentTimeMillis()), StatusEnum.FAILURE, null, null);
entity.setId(1L);
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(entity);
Mockito.when(auditEntryRepository.save(entity)).thenReturn(entity);
channel.setAuditEntryFailure(null, null, null);
channel.setAuditEntryFailure(entity.getId(), "error", new Exception());
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class HipChatChannelTest method sendMessageTestIT.
@Test
@Category(ExternalConnectionTest.class)
public void sendMessageTestIT() throws IOException, IntegrationException {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final GlobalHubRepositoryWrapper mockedGlobalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
final TestGlobalProperties globalProperties = new TestGlobalProperties(mockedGlobalRepository, null);
final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
HipChatChannel hipChatChannel = new HipChatChannel(gson, auditEntryRepository, null, null, null, channelRestConnectionFactory);
final ProjectData data = createProjectData("Integration test project");
final HipChatEvent event = new HipChatEvent(data, null);
final int roomId = Integer.parseInt(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_ROOM_ID));
final boolean notify = false;
final String color = "random";
final HipChatDistributionConfigEntity config = new HipChatDistributionConfigEntity(roomId, notify, color);
hipChatChannel = Mockito.spy(hipChatChannel);
Mockito.doReturn(new GlobalHipChatConfigEntity(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_API_KEY))).when(hipChatChannel).getGlobalConfigEntity();
hipChatChannel.sendAuditedMessage(event, config);
final boolean responseLine = outputLogger.isLineContainingText("Successfully sent a hipchat_channel message!");
assertTrue(responseLine);
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper 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.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testGetNull.
@Test
public void testGetNull() {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(null);
final AuditEntryActions auditEntryActions = new AuditEntryActions(auditEntryRepository, null, null, null, null, null, null, null);
final AuditEntryRestModel restModel = auditEntryActions.get(1L);
assertNull(restModel);
}
Aggregations