Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
// Copyright (c) 2015 Electric Cloud, Inc.
// All rights reserved

configurations {
testRuntime {
exclude module: 'gwt-dev'
}
}


buildscript {
repositories {
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -62,8 +71,6 @@ test {
exceptionFormat = 'full'
}
}

gwt {

modules 'ecplugins.s3.ConfigurationManagement'
modules 'ecplugins.s3.ConfigurationManagement'
}
2 changes: 1 addition & 1 deletion src/test/java/ecplugins/s3/StringConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
78 changes: 59 additions & 19 deletions src/test/java/ecplugins/s3/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand All @@ -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);
Expand All @@ -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");

}

/**
Expand All @@ -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();
}
Expand Down Expand Up @@ -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() + "-" +
Expand Down