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.";
}
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);
}
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());
}
}
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: "));
}
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());
}
Aggregations