Search in sources :

Example 1 with ProxyInfo

use of com.blackducksoftware.integration.hub.proxy.ProxyInfo 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 2 with ProxyInfo

use of com.blackducksoftware.integration.hub.proxy.ProxyInfo in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testCreateRestConnection.

@Test
public void testCreateRestConnection() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String apiToken = "User";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setApiToken(apiToken);
    // we create this spy to skip the server validation that happens in the build method
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.doAnswer(new Answer<HubServerConfig>() {

        @Override
        public HubServerConfig answer(final InvocationOnMock invocation) throws Throwable {
            final HubServerConfig hubServerConfig = new HubServerConfig(new URL(url), 0, apiToken, new ProxyInfo(null, 0, null, null, null, null), false, new UriCombiner());
            return hubServerConfig;
        }
    }).when(serverConfigBuilder).build();
    final RestConnection restConnection = configActions.createRestConnection(serverConfigBuilder);
    assertNotNull(restConnection);
}
Also used : ProxyInfo(com.blackducksoftware.integration.hub.proxy.ProxyInfo) UriCombiner(com.blackducksoftware.integration.hub.rest.UriCombiner) RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) URL(java.net.URL) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Aggregations

ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)2 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)2 Test (org.junit.Test)2 Credentials (com.blackducksoftware.integration.hub.Credentials)1 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)1 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)1 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)1 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)1 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)1 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)1 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)1 URL (java.net.URL)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1