use of com.synopsys.integration.rest.proxy.ProxyInfoBuilder in project hub-alert by blackducksoftware.
the class ChannelRestConnectionFactoryTest method testConnectionFields.
@Test
void testConnectionFields() {
String baseUrl = "https://example-base-url";
final String host = "host";
final int port = 1;
CredentialsBuilder builder = Credentials.newBuilder();
builder.setUsername("username");
builder.setPassword("password");
Credentials credentials = builder.build();
ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
proxyBuilder.setHost(host);
proxyBuilder.setPort(port);
proxyBuilder.setCredentials(credentials);
proxyBuilder.setNtlmDomain(null);
proxyBuilder.setNtlmWorkstation(null);
ProxyInfo expectedProxyInfo = proxyBuilder.build();
MockAlertProperties testAlertProperties = new MockAlertProperties();
testAlertProperties.setAlertTrustCertificate(true);
ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
Mockito.when(proxyManager.createProxyInfoForHost(baseUrl)).thenReturn(expectedProxyInfo);
ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(testAlertProperties, proxyManager, gson);
IntHttpClient intHttpClient = channelRestConnectionFactory.createIntHttpClient(baseUrl);
assertNotNull(intHttpClient);
assertEquals(expectedProxyInfo, intHttpClient.getProxyInfo());
}
use of com.synopsys.integration.rest.proxy.ProxyInfoBuilder in project hub-alert by blackducksoftware.
the class SystemValidatorTest method testValidateHubValidProviderWithProxy.
@Test
public void testValidateHubValidProviderWithProxy() throws Exception {
ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
CredentialsBuilder builder = Credentials.newBuilder();
builder.setUsername("AUser");
builder.setPassword("aPassword");
Credentials credentials = builder.build();
ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
proxyBuilder.setHost("google.com");
proxyBuilder.setPort(3218);
proxyBuilder.setCredentials(credentials);
proxyBuilder.setNtlmDomain(null);
proxyBuilder.setNtlmWorkstation(null);
ProxyInfo expectedProxyInfo = proxyBuilder.build();
Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(expectedProxyInfo);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("Black Duck URL"));
Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Black Duck API Token");
Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(false);
DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
blackDuckSystemValidator.validate(blackDuckProperties);
Mockito.verify(defaultSystemMessageUtility, Mockito.times(0)).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.any(SystemMessageType.class));
}
use of com.synopsys.integration.rest.proxy.ProxyInfoBuilder in project hub-alert by blackducksoftware.
the class ProxyManager method createProxyInfo.
public ProxyInfo createProxyInfo(SettingsProxyModel settingsProxyModel) {
ProxyInfoBuilder proxyBuilder = new ProxyInfoBuilder();
settingsProxyModel.getProxyHost().ifPresent(proxyBuilder::setHost);
settingsProxyModel.getProxyPort().ifPresent(proxyBuilder::setPort);
CredentialsBuilder credentialsBuilder = new CredentialsBuilder();
settingsProxyModel.getProxyUsername().ifPresent(credentialsBuilder::setUsername);
settingsProxyModel.getProxyPassword().ifPresent(credentialsBuilder::setPassword);
proxyBuilder.setCredentials(credentialsBuilder.build());
return proxyBuilder.build();
}
Aggregations