Search in sources :

Example 1 with ChannelRestConnectionFactory

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);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 2 with ChannelRestConnectionFactory

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());
    }
}
Also used : UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) URL(java.net.URL) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 3 with ChannelRestConnectionFactory

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());
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 4 with ChannelRestConnectionFactory

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);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) HipChatDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity) GlobalHubRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ProjectData(com.blackducksoftware.integration.hub.alert.digest.model.ProjectData) Category(org.junit.experimental.categories.Category) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 5 with ChannelRestConnectionFactory

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: "));
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Aggregations

ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)9 Test (org.junit.Test)9 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)7 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)7 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)6 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)2 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)2 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)2 Category (org.junit.experimental.categories.Category)2 Credentials (com.blackducksoftware.integration.hub.Credentials)1 HipChatDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.distribution.HipChatDistributionConfigEntity)1 SlackDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity)1 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1 PrintStreamIntLogger (com.blackducksoftware.integration.log.PrintStreamIntLogger)1 URL (java.net.URL)1