use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory in project hub-alert by blackducksoftware.
the class HipChatChannelTest method testGlobalConfigNullTest.
@Test
public void testGlobalConfigNullTest() throws Exception {
final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(null);
final String nullEntityMessage = hipChatChannel.testGlobalConfig(null);
assertEquals("The provided entity was null.", nullEntityMessage);
hipChatMockUtil.setApiKey("apiKey");
final GlobalHipChatConfigEntity entityWithKey = hipChatMockUtil.createGlobalEntity();
final String restConnectionNullMessage = hipChatChannel.testGlobalConfig(entityWithKey);
assertEquals("Connection error: see logs for more information.", restConnectionNullMessage);
}
use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory in project hub-alert by blackducksoftware.
the class HipChatChannelTest method testGlobalConfigThrowsExceptionTest.
@Test
public void testGlobalConfigThrowsExceptionTest() throws IntegrationException, MalformedURLException {
final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
RestConnection restConnection = new UnauthenticatedRestConnection(new PrintStreamIntLogger(System.out, LogLevel.INFO), new URL("http://google.com"), 100, null, new UriCombiner());
restConnection = Mockito.spy(restConnection);
Mockito.doThrow(new IntegrationException("Mock exception")).when(restConnection).connect();
Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(restConnection);
hipChatMockUtil.setApiKey("apiKey");
try {
final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
hipChatChannel.testGlobalConfig(entity);
} catch (final IntegrationException ex) {
assertEquals("Invalid API key: Mock exception", ex.getMessage());
}
}
use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory in project hub-alert by blackducksoftware.
the class HipChatChannelTest method testGlobalConfigAPIKeyNullTest.
@Test
public void testGlobalConfigAPIKeyNullTest() {
final ChannelRestConnectionFactory restFactory = Mockito.mock(ChannelRestConnectionFactory.class);
final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
Mockito.when(restFactory.createUnauthenticatedRestConnection(Mockito.anyString())).thenReturn(null);
try {
final GlobalHipChatConfigEntity entity = hipChatMockUtil.createEmptyGlobalEntity();
hipChatChannel.testGlobalConfig(entity);
fail();
} catch (final IntegrationException ex) {
assertEquals("Invalid API key: API key not provided", ex.getMessage());
}
}
use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory 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.channel.rest.ChannelRestConnectionFactory 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: "));
}
Aggregations