Search in sources :

Example 1 with RestConnection

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

the class GlobalHubConfigActions method channelTestConfig.

@Override
public String channelTestConfig(final GlobalHubConfigRestModel restModel) throws IntegrationException {
    final Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
    String apiToken;
    if (restModel.isHubApiKeyIsSet()) {
        final GlobalHubConfigEntity foundEntity = getRepository().findOne(Long.parseLong(restModel.getId()));
        apiToken = foundEntity.getHubApiKey();
    } else {
        apiToken = restModel.getHubApiKey();
    }
    final HubServerConfigBuilder hubServerConfigBuilder = new HubServerConfigBuilder();
    hubServerConfigBuilder.setHubUrl(globalProperties.getHubUrl());
    hubServerConfigBuilder.setTimeout(restModel.getHubTimeout());
    hubServerConfigBuilder.setProxyHost(globalProperties.getHubProxyHost());
    hubServerConfigBuilder.setProxyPort(globalProperties.getHubProxyPort());
    hubServerConfigBuilder.setProxyUsername(globalProperties.getHubProxyUsername());
    hubServerConfigBuilder.setApiToken(apiToken);
    hubServerConfigBuilder.setProxyPassword(globalProperties.getHubProxyPassword());
    if (globalProperties.getHubTrustCertificate() != null) {
        hubServerConfigBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
    }
    hubServerConfigBuilder.setLogger(intLogger);
    validateHubConfiguration(hubServerConfigBuilder);
    final RestConnection restConnection = createRestConnection(hubServerConfigBuilder);
    restConnection.connect();
    return "Successfully connected to the Hub.";
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigEntity(com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)

Example 2 with RestConnection

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

the class TestGlobalProperties method createHubServicesFactoryWithCredential.

public HubServicesFactory createHubServicesFactoryWithCredential(final IntLogger logger) throws Exception {
    setHubUrl(testProperties.getProperty(TestPropertyKey.TEST_HUB_SERVER_URL));
    setHubTrustCertificate(true);
    final HubServerConfig hubServerConfig = createHubServerConfigWithCredentials(logger);
    final RestConnection restConnection = hubServerConfig.createCredentialsRestConnection(logger);
    return new HubServicesFactory(restConnection);
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory)

Example 3 with RestConnection

use of com.blackducksoftware.integration.hub.rest.RestConnection 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 4 with RestConnection

use of com.blackducksoftware.integration.hub.rest.RestConnection 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)

Example 5 with RestConnection

use of com.blackducksoftware.integration.hub.rest.RestConnection 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)

Aggregations

RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)24 Test (org.junit.Test)10 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)9 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)6 Request (com.blackducksoftware.integration.hub.request.Request)6 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)5 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)5 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)4 UnauthenticatedRestConnectionBuilder (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)4 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)3 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)3 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)3 Slf4jIntLogger (com.blackducksoftware.integration.log.Slf4jIntLogger)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)2 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)2 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)2 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)2 LoginRestModel (com.blackducksoftware.integration.hub.alert.web.model.LoginRestModel)2 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)2