UploaderApp extends DataBridgeApp { @Override protected ReturnValue parseCommandLineArguments(String[] args, ApplicationContext applicationContext) { ReturnValue returnValue = super.parseCommandLineArguments(args, applicationContext); if (returnValue != null) { return returnValue; } try { maxRetryAttempts = argParser.getIntegerValue(maxRetryAttemptsOpt, MAX_RETRY_ATTEMPTS_DEFAULT, MAX_RETRY_ATTEMPTS_MIN, MAX_RETRY_ATTEMPTS_MAX); retryDelaySecs = argParser.getIntegerValue(retryDelaySecsOpt, RETRY_DELAY_SECS_DEFAULT, RETRY_DELAY_SECS_MIN, RETRY_DELAY_SECS_MAX); } catch (Exception ex) { LOGGER.error("Error parsing command line arguments: " + ex.getMessage() + "\n" + argParser.getUsageInformation()); return ReturnValue.FAILURE; } return null; } UploaderApp(); @Override ReturnValue go(String[] args); @Override ArgumentParser getArgumentParser(); @SuppressWarnings("PMD.DoNotCallSystemExit") // Using System.exit is allowed for an actual application to exit. static void main(String[] args);  }
@Test public void testGoEnvPasswordSuccess() { environmentVariables.set("HERD_PASSWORD", "WEB_SERVICE_HTTPS_PASSWORD"); String[] arguments = {"--s3AccessKey", S3_ACCESS_KEY, "--s3SecretKey", S3_SECRET_KEY, "--s3Endpoint", S3_ENDPOINT_US_STANDARD, "--localPath", LOCAL_TEMP_PATH_INPUT.toString(), "--manifestPath", STRING_VALUE, "--regServerHost", WEB_SERVICE_HOSTNAME, "--regServerPort", WEB_SERVICE_HTTPS_PORT.toString(), "--httpProxyHost", HTTP_PROXY_HOST, "--httpProxyPort", HTTP_PROXY_PORT.toString(), "--ssl", "true", "-u", WEB_SERVICE_HTTPS_USERNAME, "-E", "true", "-C", "true", "-d", "true"}; assertNull(uploaderApp.parseCommandLineArguments(arguments, applicationContext)); environmentVariables.clear("HERD_PASSWORD"); }
@Test public void testGoCliAndEnvPasswordSuccess() { environmentVariables.set("HERD_PASSWORD", ""); String[] arguments = {"--s3AccessKey", S3_ACCESS_KEY, "--s3SecretKey", S3_SECRET_KEY, "--s3Endpoint", S3_ENDPOINT_US_STANDARD, "--localPath", LOCAL_TEMP_PATH_INPUT.toString(), "--manifestPath", STRING_VALUE, "--regServerHost", WEB_SERVICE_HOSTNAME, "--regServerPort", WEB_SERVICE_HTTPS_PORT.toString(), "--httpProxyHost", HTTP_PROXY_HOST, "--httpProxyPort", HTTP_PROXY_PORT.toString(), "--ssl", "true", "-u", WEB_SERVICE_HTTPS_USERNAME, "-w", WEB_SERVICE_HTTPS_PASSWORD, "-E", "true", "-C", "true", "-d", "true"}; assertNull(uploaderApp.parseCommandLineArguments(arguments, applicationContext)); environmentVariables.set("HERD_PASSWORD", WEB_SERVICE_HTTPS_PASSWORD); String[] argumentsEnvPassword = {"--s3AccessKey", S3_ACCESS_KEY, "--s3SecretKey", S3_SECRET_KEY, "--s3Endpoint", S3_ENDPOINT_US_STANDARD, "--localPath", LOCAL_TEMP_PATH_INPUT.toString(), "--manifestPath", STRING_VALUE, "--regServerHost", WEB_SERVICE_HOSTNAME, "--regServerPort", WEB_SERVICE_HTTPS_PORT.toString(), "--httpProxyHost", HTTP_PROXY_HOST, "--httpProxyPort", HTTP_PROXY_PORT.toString(), "--ssl", "true", "-u", WEB_SERVICE_HTTPS_USERNAME, "-w", "", "-E", "true", "-C", "true", "-d", "true"}; assertNull(uploaderApp.parseCommandLineArguments(argumentsEnvPassword, applicationContext)); environmentVariables.clear("HERD_PASSWORD"); }
@Test public void testParseCommandLineArgumentsInvalidMaxRetryAttempts() { String[] arguments = {"-a", S3_ACCESS_KEY, "-p", S3_SECRET_KEY, "-e", S3_ENDPOINT_US_STANDARD, "-l", LOCAL_TEMP_PATH_INPUT.toString(), "-m", STRING_VALUE, "-H", WEB_SERVICE_HOSTNAME, "-P", WEB_SERVICE_HTTPS_PORT.toString(), "-n", HTTP_PROXY_HOST, "-o", HTTP_PROXY_PORT.toString(), "-R", "INVALID_INTEGER"}; assertEquals(DataBridgeApp.ReturnValue.FAILURE, uploaderApp.parseCommandLineArguments(arguments, applicationContext)); }
@Test public void testParseCommandLineArgumentsNone() { assertEquals(DataBridgeApp.ReturnValue.FAILURE, uploaderApp.parseCommandLineArguments(new String[] {}, applicationContext)); }
@Test public void testParseShortCommandLineArgumentsSuccess() { String[] arguments = {"-a", S3_ACCESS_KEY, "-p", S3_SECRET_KEY, "-e", S3_ENDPOINT_US_STANDARD, "-l", LOCAL_TEMP_PATH_INPUT.toString(), "-m", STRING_VALUE, "-H", WEB_SERVICE_HOSTNAME, "-P", WEB_SERVICE_HTTPS_PORT.toString(), "-n", HTTP_PROXY_HOST, "-o", HTTP_PROXY_PORT.toString(), "-s", "true", "-u", WEB_SERVICE_HTTPS_USERNAME, "-w", WEB_SERVICE_HTTPS_PASSWORD, "-C", "true", "-d", "true"}; assertNull(uploaderApp.parseCommandLineArguments(arguments, applicationContext)); }