diff --git a/build.gradle b/build.gradle index afa7ae8..7086e72 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,12 @@ // Copyright (c) 2015 Electric Cloud, Inc. // All rights reserved +configurations { + testRuntime { + exclude module: 'gwt-dev' + } +} + buildscript { repositories { @@ -34,11 +40,14 @@ license { } dependencies { testCompile 'junit:junit:[4,)' - testCompile 'org.mockito:mockito-core:1.9.5' - testCompile 'com.amazonaws:aws-java-sdk-s3:1.9.30' + compile 'com.amazonaws:aws-java-sdk-s3:+' + + } test { + classpath = sourceSets.test.runtimeClasspath + Properties props = new Properties() def propFileName = "ecplugin.properties" @@ -49,7 +58,7 @@ test { props.load(new FileInputStream(propFileName)) } - systemProperties['COMMANDER_SERVER'] = "$commanderServer" + systemProperties['COMMANDER_SERVER'] = props.getProperty("COMMANDER_SERVER") systemProperties['COMMANDER_USER'] = props.getProperty("COMMANDER_USER") systemProperties['COMMANDER_PASSWORD'] = props.getProperty("COMMANDER_PASSWORD") systemProperties['PLUGIN_VERSION'] = version @@ -62,8 +71,6 @@ test { exceptionFormat = 'full' } } - gwt { - - modules 'ecplugins.s3.ConfigurationManagement' + modules 'ecplugins.s3.ConfigurationManagement' } diff --git a/src/test/java/ecplugins/s3/StringConstants.java b/src/test/java/ecplugins/s3/StringConstants.java index 059d017..f210c99 100644 --- a/src/test/java/ecplugins/s3/StringConstants.java +++ b/src/test/java/ecplugins/s3/StringConstants.java @@ -20,7 +20,7 @@ public class StringConstants { - final static String COMMANDER_SERVER = System.getProperty("COMMANDER_SERVER"); + final static String COMMANDER_SERVER = "COMMANDER_SERVER"; final static String PLUGIN_VERSION = System.getProperty("PLUGIN_VERSION"); final static String COMMANDER_USER = "COMMANDER_USER"; final static String COMMANDER_PASSWORD = "COMMANDER_PASSWORD"; diff --git a/src/test/java/ecplugins/s3/TestUtils.java b/src/test/java/ecplugins/s3/TestUtils.java index 82a6656..0bbc16e 100644 --- a/src/test/java/ecplugins/s3/TestUtils.java +++ b/src/test/java/ecplugins/s3/TestUtils.java @@ -18,11 +18,18 @@ package ecplugins.s3; import org.apache.http.HttpResponse; +import org.apache.http.auth.AuthScope; + +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.CredentialsProvider; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicCredentialsProvider; + import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONException; @@ -67,17 +74,32 @@ public static Properties getProperties() throws Exception { */ public static String callRunProcedure(JSONObject jo) throws Exception { + String encoding = new String( + org.apache.commons.codec.binary.Base64 + .encodeBase64(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(props + .getProperty(StringConstants.COMMANDER_USER) + + ":" + + props.getProperty(StringConstants.COMMANDER_PASSWORD)))); + HttpClient httpClient = new DefaultHttpClient(); - JSONObject result = null; + + JSONObject result; try { - HttpPost httpPostRequest = new HttpPost("http://" + props.getProperty(StringConstants.COMMANDER_USER) - + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@" + StringConstants.COMMANDER_SERVER + + + HttpPost httpPostRequest = + new HttpPost("http://" + + props + .getProperty(StringConstants.COMMANDER_SERVER) + ":8000/rest/v1.0/jobs?request=runProcedure"); + + StringEntity input = new StringEntity(jo.toString()); input.setContentType("application/json"); httpPostRequest.setEntity(input); + httpPostRequest.setHeader("Authorization", "Basic " + encoding); HttpResponse httpResponse = httpClient.execute(httpPostRequest); result = new JSONObject(EntityUtils.toString(httpResponse.getEntity())); @@ -95,16 +117,16 @@ public static String callRunProcedure(JSONObject jo) throws Exception { * @param jobId * @return outcome of job */ - static String waitForJob(String jobId, long jobTimeOutMillis) throws Exception { + static String waitForJob(String jobId, long jobTimeOutMillis) + throws Exception { long timeTaken = 0; - String url = "http://" + props.getProperty(StringConstants.COMMANDER_USER) + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + - "@" + StringConstants.COMMANDER_SERVER + ":8000/rest/v1.0/jobs/" + - jobId + "?request=getJobStatus"; + String url = "http://" + props + .getProperty(StringConstants.COMMANDER_SERVER) + + ":8000/rest/v1.0/jobs/" + jobId + "?request=getJobStatus"; JSONObject jsonObject = performHTTPGet(url); - while (!jsonObject.getString("status").equalsIgnoreCase("completed")) { Thread.sleep(jobStatusPollIntervalMillis); jsonObject = performHTTPGet(url); @@ -113,9 +135,7 @@ static String waitForJob(String jobId, long jobTimeOutMillis) throws Exception { throw new Exception("Job did not completed within time."); } } - return jsonObject.getString("outcome"); - } /** @@ -128,21 +148,34 @@ static String getJobStatus(String jobId) throws IOException, JSONException { HttpClient httpClient = new DefaultHttpClient(); String output = ""; - HttpGet httpGetRequest = new HttpGet("http://" + props.getProperty(StringConstants.COMMANDER_USER) - + ":" + props.getProperty(StringConstants.COMMANDER_PASSWORD) + "@" + StringConstants.COMMANDER_SERVER - + ":8000/rest/v1.0/jobs/" + jobId + "?request=getJobDetails"); - try { + String encoding = new String( + org.apache.commons.codec.binary.Base64 + .encodeBase64(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(props + .getProperty(StringConstants.COMMANDER_USER) + + ":" + + props.getProperty(StringConstants.COMMANDER_PASSWORD)))); + HttpGet httpGetRequest = new HttpGet("http://" + + props.getProperty(StringConstants.COMMANDER_SERVER) + ":8000/rest/v1.0/jobs/" + + jobId + "?request=getJobDetails"); + httpGetRequest.setHeader("Authorization", "Basic " + encoding); + try { HttpResponse httpResponse = httpClient.execute(httpGetRequest); if (httpResponse.getStatusLine().getStatusCode() >= 400) { - throw new RuntimeException("HTTP GET failed with " + - httpResponse.getStatusLine().getStatusCode() + "-" + - httpResponse.getStatusLine().getReasonPhrase()); + throw new RuntimeException("HTTP GET failed with " + + httpResponse.getStatusLine().getStatusCode() + "-" + + httpResponse.getStatusLine().getReasonPhrase()); } - output = new JSONObject(EntityUtils.toString(httpResponse.getEntity())).getJSONObject("job").getJSONArray("jobStep").getJSONObject(0).getJSONObject("propertySheet").getJSONArray("property").getJSONObject(1).getString("value"); + output = new JSONObject(EntityUtils.toString(httpResponse + .getEntity())).getJSONObject("job").getJSONArray("jobStep") + .getJSONObject(0).getJSONObject("propertySheet") + .getJSONArray("property").getJSONObject(1) + .getString("value"); + } catch (Exception e) { + e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } @@ -173,10 +206,17 @@ static String getSubstring(String string,String regex){ static JSONObject performHTTPGet(String url) throws IOException, JSONException { HttpClient httpClient = new DefaultHttpClient(); + String encoding = new String( + org.apache.commons.codec.binary.Base64 + .encodeBase64(org.apache.commons.codec.binary.StringUtils.getBytesUtf8(props + .getProperty(StringConstants.COMMANDER_USER) + + ":" + + props.getProperty(StringConstants.COMMANDER_PASSWORD)))); try { HttpGet httpGetRequest = new HttpGet(url); - + httpGetRequest.setHeader("Authorization", "Basic " + encoding); HttpResponse httpResponse = httpClient.execute(httpGetRequest); + if (httpResponse.getStatusLine().getStatusCode() >= 400) { throw new RuntimeException("HTTP GET failed with " + httpResponse.getStatusLine().getStatusCode() + "-" +