Search in sources :

Example 6 with ChannelRestConnectionFactory

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

Example 7 with ChannelRestConnectionFactory

use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigValidApiKeyTest.

@Test
public void testGlobalConfigValidApiKeyTest() throws Exception {
    final TestGlobalProperties globalProperties = new TestGlobalProperties();
    globalProperties.setHubTrustCertificate(Boolean.TRUE);
    final ChannelRestConnectionFactory restFactory = new ChannelRestConnectionFactory(globalProperties);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    hipChatMockUtil.setApiKey(properties.getProperty(TestPropertyKey.TEST_HIPCHAT_API_KEY));
    final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
    final String validMessage = hipChatChannel.testGlobalConfig(entity);
    assertEquals("API key is valid.", validMessage);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) GlobalHipChatConfigEntity(com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 8 with ChannelRestConnectionFactory

use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory in project hub-alert by blackducksoftware.

the class HipChatChannelTest method testGlobalConfigInvalidApiKeyTest.

@Test
public void testGlobalConfigInvalidApiKeyTest() {
    final TestGlobalProperties globalProperties = new TestGlobalProperties();
    globalProperties.setHubTrustCertificate(Boolean.TRUE);
    final ChannelRestConnectionFactory restFactory = new ChannelRestConnectionFactory(globalProperties);
    final HipChatChannel hipChatChannel = new HipChatChannel(null, null, null, null, null, restFactory);
    hipChatMockUtil.setApiKey("garbage");
    try {
        final GlobalHipChatConfigEntity entity = hipChatMockUtil.createGlobalEntity();
        hipChatChannel.testGlobalConfig(entity);
    } catch (final IntegrationException ex) {
        assertTrue(ex.getMessage().contains("Invalid API key: "));
    }
}
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) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) ExternalConnectionTest(com.blackducksoftware.integration.test.annotation.ExternalConnectionTest) Test(org.junit.Test) ChannelTest(com.blackducksoftware.integration.hub.alert.channel.ChannelTest)

Example 9 with ChannelRestConnectionFactory

use of com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory 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);
}
Also used : ChannelRestConnectionFactory(com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) SlackDistributionConfigEntity(com.blackducksoftware.integration.hub.alert.channel.slack.repository.distribution.SlackDistributionConfigEntity) 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)

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