use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties 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.TestGlobalProperties 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.TestGlobalProperties in project hub-alert by blackducksoftware.
the class RestDistributionChannelTest method sendMessageFailureTest.
@Test
public void sendMessageFailureTest() {
final GlobalProperties globalProperties = new TestGlobalProperties();
final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
final RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity> restChannel = new RestDistributionChannel<AbstractChannelEvent, GlobalChannelConfigEntity, DistributionChannelConfigEntity>(null, null, null, null, null, null, channelRestConnectionFactory) {
@Override
public String getApiUrl() {
return null;
}
@Override
public Request createRequest(final ChannelRequestHelper channelRequestHelper, final DistributionChannelConfigEntity config, final ProjectData projectData) throws AlertException {
return new Request.Builder().uri("http://google.com").build();
}
};
final SlackEvent event = new SlackEvent(createProjectData("Rest channel test"), 1L);
final SlackDistributionConfigEntity config = new SlackDistributionConfigEntity("more garbage", "garbage", "garbage");
Exception thrownException = null;
try {
restChannel.sendAuditedMessage(event, config);
} catch (final IntegrationException ex) {
thrownException = ex;
}
assertNotNull(thrownException);
}
use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties in project hub-alert by blackducksoftware.
the class ChannelRestConnectionFactoryTest method testNullUrl.
@Test
public void testNullUrl() throws IOException {
final TestGlobalProperties globalProperties = new TestGlobalProperties();
final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection("bad");
assertNull(restConnection);
assertTrue(outputLogger.isLineContainingText("Problem generating the URL: "));
}
use of com.blackducksoftware.integration.hub.alert.TestGlobalProperties in project hub-alert by blackducksoftware.
the class ChannelRestConnectionFactoryTest method testConnectionFields.
@Test
public void testConnectionFields() throws EncryptionException {
final String host = "host";
final int port = 1;
final Credentials credentials = new Credentials("username", "password");
final TestGlobalProperties globalProperties = new TestGlobalProperties();
globalProperties.setHubProxyHost(host);
globalProperties.setHubProxyUsername(credentials.getUsername());
globalProperties.setHubProxyPassword(credentials.getDecryptedPassword());
globalProperties.setHubProxyPort(String.valueOf(port));
globalProperties.setHubTrustCertificate(true);
final ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(globalProperties);
final RestConnection restConnection = channelRestConnectionFactory.createUnauthenticatedRestConnection("https:url");
final ProxyInfo expectedProxyInfo = new ProxyInfo(host, port, credentials, null, null, null);
assertNotNull(restConnection);
assertEquals(expectedProxyInfo, restConnection.getProxyInfo());
}
Aggregations