use of com.blackducksoftware.integration.hub.rest.UriCombiner 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.UriCombiner 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.rest.UriCombiner in project hub-fortify-ssc-integration-service by blackducksoftware.
the class RestConnectionHelper method getRestConnection.
/**
* Get the Hub REST connection
*
* @param serverConfig
* @param logLevel
* @return
*/
private static CredentialsRestConnection getRestConnection(final HubServerConfig serverConfig, final LogLevel logLevel) {
CredentialsRestConnection restConnection;
try {
final ProxyInfo proxyInfo = getProxyInfo(serverConfig);
restConnection = new CredentialsRestConnection(new PrintStreamIntLogger(System.out, logLevel), serverConfig.getHubUrl(), serverConfig.getGlobalCredentials().getUsername(), serverConfig.getGlobalCredentials().getDecryptedPassword(), serverConfig.getTimeout(), proxyInfo, new UriCombiner());
} catch (final IllegalArgumentException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (final EncryptionException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return restConnection;
}
use of com.blackducksoftware.integration.hub.rest.UriCombiner in project hub-detect by blackducksoftware.
the class OfflineScanner method offlineScan.
boolean offlineScan(final DetectProject detectProject, final HubScanConfig hubScanConfig, final String hubSignatureScannerOfflineLocalPath) throws IllegalArgumentException, IntegrationException, DetectUserFriendlyException, InterruptedException {
final IntLogger intLogger = new Slf4jIntLogger(logger);
final HubServerConfig hubServerConfig = new HubServerConfig(null, 0, (String) null, null, false, new UriCombiner());
final CIEnvironmentVariables ciEnvironmentVariables = new CIEnvironmentVariables();
ciEnvironmentVariables.putAll(System.getenv());
final SimpleScanUtility simpleScanUtility = new SimpleScanUtility(intLogger, gson, hubServerConfig, ciEnvironmentVariables, hubScanConfig, detectProject.getProjectName(), detectProject.getProjectVersionName());
CLILocation cliLocation = new CLILocation(intLogger, hubScanConfig.getToolsDir());
if (StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
cliLocation = new OfflineCLILocation(intLogger, new File(hubSignatureScannerOfflineLocalPath));
}
boolean cliInstalledOkay = checkCliInstall(cliLocation, intLogger);
if (!cliInstalledOkay && StringUtils.isNotBlank(detectConfiguration.getHubSignatureScannerHostUrl())) {
installSignatureScannerFromUrl(intLogger, hubScanConfig, ciEnvironmentVariables);
cliInstalledOkay = checkCliInstall(cliLocation, intLogger);
}
if (!cliInstalledOkay && StringUtils.isNotBlank(hubSignatureScannerOfflineLocalPath)) {
OfflineScanner.logger.warn(String.format("The signature scanner is not correctly installed at %s", hubSignatureScannerOfflineLocalPath));
return false;
} else if (!cliInstalledOkay) {
OfflineScanner.logger.warn(String.format("The signature scanner is not correctly installed at %s", hubScanConfig.getToolsDir()));
return false;
} else {
simpleScanUtility.setupAndExecuteScan(cliLocation);
OfflineScanner.logger.info(String.format("The scan dry run files can be found in : %s", simpleScanUtility.getDataDirectory()));
return true;
}
}
Aggregations