use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper 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.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class DistributionChannelTest method setAuditEntrySuccessTest.
@Test
public void setAuditEntrySuccessTest() {
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.SUCCESS, null, null);
entity.setId(1L);
Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(entity);
Mockito.when(auditEntryRepository.save(entity)).thenReturn(entity);
channel.setAuditEntrySuccess(null);
channel.setAuditEntrySuccess(entity.getId());
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class HipChatChannelTest method createRequestThrowsExceptionTest.
@Test
public void createRequestThrowsExceptionTest() throws Exception {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final HipChatChannel hipChatChannel = new HipChatChannel(gson, auditEntryRepository, null, null, null, null);
final ChannelRequestHelper channelRequestHelper = new ChannelRequestHelper(null);
final HipChatDistributionConfigEntity config = new HipChatDistributionConfigEntity(12345, Boolean.FALSE, null);
final ProjectData projectData = createProjectData("HipChat IT test");
final String userDir = System.getProperties().getProperty("user.dir");
try {
System.getProperties().setProperty("user.dir", "garbage");
RuntimeException thrownException = null;
try {
hipChatChannel.createRequest(channelRequestHelper, config, projectData);
} catch (final RuntimeException e) {
thrownException = e;
}
assertNotNull(thrownException);
} finally {
System.getProperties().setProperty("user.dir", userDir);
}
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class SlackChannelTestIT 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);
final SlackChannel slackChannel = new SlackChannel(gson, auditEntryRepository, null, null, channelRestConnectionFactory);
final String roomName = properties.getProperty(TestPropertyKey.TEST_SLACK_CHANNEL_NAME);
final String username = properties.getProperty(TestPropertyKey.TEST_SLACK_USERNAME);
final String webHook = properties.getProperty(TestPropertyKey.TEST_SLACK_WEBHOOK);
final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity(webHook, username, roomName);
final ProjectData projectData = createProjectData("Slack test project");
final SlackEvent event = new SlackEvent(projectData, new Long(0));
slackChannel.sendAuditedMessage(event, config);
final boolean actual = outputLogger.isLineContainingText("Successfully sent a slack_channel message!");
assertTrue(actual);
}
use of com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper in project hub-alert by blackducksoftware.
the class EmailChannelTestIT method sendEmailTest.
@Test
@Category(ExternalConnectionTest.class)
public void sendEmailTest() throws Exception {
final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
final GlobalHubRepositoryWrapper globalRepository = Mockito.mock(GlobalHubRepositoryWrapper.class);
final GlobalHubConfigEntity globalConfig = new GlobalHubConfigEntity(300, properties.getProperty(TestPropertyKey.TEST_HUB_API_KEY));
Mockito.when(globalRepository.findAll()).thenReturn(Arrays.asList(globalConfig));
final TestGlobalProperties globalProperties = new TestGlobalProperties(globalRepository);
globalProperties.setHubUrl(properties.getProperty(TestPropertyKey.TEST_HUB_SERVER_URL));
final String trustCert = properties.getProperty(TestPropertyKey.TEST_TRUST_HTTPS_CERT);
if (trustCert != null) {
globalProperties.setHubTrustCertificate(Boolean.valueOf(trustCert));
}
EmailGroupChannel emailChannel = new EmailGroupChannel(globalProperties, gson, auditEntryRepository, null, null, null);
final ProjectData projectData = createProjectData("Manual test project");
final EmailGroupEvent event = new EmailGroupEvent(projectData, 1L);
final String smtpHost = properties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_HOST);
final String smtpFrom = properties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_FROM);
final GlobalEmailConfigEntity emailGlobalConfigEntity = new GlobalEmailConfigEntity(smtpHost, null, null, null, null, null, smtpFrom, null, null, null, null, null, null, null);
emailChannel = Mockito.spy(emailChannel);
Mockito.doReturn(emailGlobalConfigEntity).when(emailChannel).getGlobalConfigEntity();
final MockEmailEntity mockEmailEntity = new MockEmailEntity();
mockEmailEntity.setGroupName("IntegrationTest");
emailChannel.sendAuditedMessage(event, mockEmailEntity.createEntity());
}
Aggregations