use of com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder 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.configuration.HubServerConfigBuilder in project hub-alert by blackducksoftware.
the class GlobalHubConfigActionsTest method testValidConfig.
@Test
@Override
public void testValidConfig() throws Exception {
final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
final String url = "https://www.google.com/";
final String user = "User";
final String password = "Password";
HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
serverConfigBuilder.setHubUrl(url);
serverConfigBuilder.setUsername(user);
serverConfigBuilder.setUsername(password);
try {
configActions.validateHubConfiguration(serverConfigBuilder);
fail();
} catch (final AlertFieldException e) {
assertNotNull(e);
assertEquals("There were issues with the configuration.", e.getMessage());
assertTrue(!e.getFieldErrors().isEmpty());
}
final HubServerConfigValidator validator = Mockito.mock(HubServerConfigValidator.class);
serverConfigBuilder = Mockito.spy(serverConfigBuilder);
Mockito.when(serverConfigBuilder.createValidator()).thenReturn(validator);
Mockito.when(validator.assertValid()).thenReturn(new ValidationResults());
try {
configActions.validateHubConfiguration(serverConfigBuilder);
} catch (final AlertFieldException e) {
fail();
}
}
use of com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder 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);
}
use of com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder in project hub-alert by blackducksoftware.
the class GlobalProperties method createHubServerConfig.
public HubServerConfig createHubServerConfig(final IntLogger logger, final int hubTimeout, final String hubUsername, final String hubPassword) throws AlertException {
final HubServerConfigBuilder hubServerConfigBuilder = createHubServerConfigBuilderWithoutAuthentication(logger, hubTimeout);
hubServerConfigBuilder.setUsername(hubUsername);
hubServerConfigBuilder.setPassword(hubPassword);
try {
return hubServerConfigBuilder.build();
} catch (final IllegalStateException e) {
throw new AlertException(e.getMessage(), e);
}
}
use of com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder in project hub-alert by blackducksoftware.
the class GlobalProperties method createHubServerConfigBuilderWithoutAuthentication.
private HubServerConfigBuilder createHubServerConfigBuilderWithoutAuthentication(final IntLogger logger, final int hubTimeout) {
final HubServerConfigBuilder hubServerConfigBuilder = new HubServerConfigBuilder();
hubServerConfigBuilder.setHubUrl(getHubUrl());
hubServerConfigBuilder.setTimeout(hubTimeout);
hubServerConfigBuilder.setProxyHost(getHubProxyHost());
hubServerConfigBuilder.setProxyPort(getHubProxyPort());
hubServerConfigBuilder.setProxyUsername(getHubProxyUsername());
hubServerConfigBuilder.setProxyPassword(getHubProxyPassword());
if (hubTrustCertificate != null) {
hubServerConfigBuilder.setAlwaysTrustServerCertificate(hubTrustCertificate);
}
hubServerConfigBuilder.setLogger(logger);
return hubServerConfigBuilder;
}
Aggregations