diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 684633d..1ab07e3 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,7 +10,7 @@ - + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..401dd57 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: java +# The cross product of the jdk and env settings form the matrix of builds Travis will run. +jdk: + - oraclejdk8 + - oraclejdk9 + - openjdk7 + - openjdk8 +notifications: + email: + recipients: + - ci.report@ost.com + on_success: always + on_failure: always +sudo: false +branches: + only: + - master + - develop +script: mvn clean verify \ No newline at end of file diff --git a/README.md b/README.md index 1b006cd..8955385 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # OST JavaScript SDK The official [OST Java SDK](https://dev.ost.com/). + +[![Travis](https://travis-ci.org/OpenSTFoundation/ost-sdk-java.svg?branch=master)](https://travis-ci.org/OpenSTFoundation/ost-sdk-java) +[![Gitter: JOIN CHAT](https://img.shields.io/badge/gitter-JOIN%20CHAT-brightgreen.svg)](https://gitter.im/OpenSTFoundation/SimpleToken) + ## Requirements To use this node module, developers will need to: diff --git a/pom.xml b/pom.xml index 7b59e95..a8afdb2 100644 --- a/pom.xml +++ b/pom.xml @@ -12,9 +12,10 @@ org.apache.maven.plugins maven-compiler-plugin + 3.6.0 - 7 - 7 + 1.6 + 1.6 diff --git a/src/main/java/com/ost/lib/OSTRequestClient.java b/src/main/java/com/ost/lib/OSTRequestClient.java index d728a9f..1a9ca49 100644 --- a/src/main/java/com/ost/lib/OSTRequestClient.java +++ b/src/main/java/com/ost/lib/OSTRequestClient.java @@ -35,6 +35,7 @@ public class OSTRequestClient { private static final String HMAC_SHA256 = "HmacSHA256"; private static final Charset UTF_8 = Charset.forName("UTF-8"); private static Boolean DEBUG = System.getenv("OST_SDK_DEBUG").equalsIgnoreCase("true"); + private static Boolean VERBOSE = false; public OSTRequestClient( Map params) { @@ -114,7 +115,7 @@ private JsonObject send(String requestType, String resource, Map // Start Building HMAC Input Buffer by parsing the url. Buffer hmacInputBuffer = new Buffer(); for (String path : url.pathSegments()) { - if ( DEBUG ) System.out.println("path:" + path); + if ( DEBUG && VERBOSE ) System.out.println("path:" + path); hmacInputBuffer.writeByte('/').writeUtf8( PathSegmentEscaper.escape( path ) ); } hmacInputBuffer.writeByte('?'); @@ -157,11 +158,11 @@ private JsonObject send(String requestType, String resource, Map hmacInputBuffer.writeUtf8( paramKey ); hmacInputBuffer.writeByte( '=' ); hmacInputBuffer.writeUtf8( paramVal ); + if ( DEBUG ) System.out.println("paramKey " + paramKey + " paramVal " + paramVal); if ( GET_REQUEST.equalsIgnoreCase( requestType) ) { urlBuilder.addEncodedQueryParameter(paramKey, paramVal); } else { - if ( DEBUG ) System.out.println("paramKey " + paramKey + " paramVal " + paramVal); formBodyBuilder.addEncoded( paramKey, paramVal); } } @@ -191,9 +192,8 @@ private JsonObject send(String requestType, String resource, Map if ( GET_REQUEST.equalsIgnoreCase( requestType) ) { requestBuilder.get(); } else { - if ( DEBUG ) System.out.println("Creating POST request"); FormBody formBody = formBodyBuilder.build(); - if ( DEBUG ) { + if ( DEBUG && VERBOSE ) { for (int i = 0; i < formBody.size(); i++) { System.out.println(formBody.name(i) + "\t\t" + formBody.value(i)); } diff --git a/src/test/java/com/ost/services/ServiceTestBase.java b/src/test/java/com/ost/services/ServiceTestBase.java index 6e61f24..4144718 100644 --- a/src/test/java/com/ost/services/ServiceTestBase.java +++ b/src/test/java/com/ost/services/ServiceTestBase.java @@ -8,12 +8,14 @@ import java.util.HashMap; import java.util.Map; +import java.util.Random; public class ServiceTestBase { private OSTSDK ostsdk; private HashMap apiV0Params; protected com.ost.services.OSTServiceManifest services; private OSTAPIService service; + private static final int sleepMilliSeconds = 300; public void setUp( String apiEndPoint ) throws Exception { @@ -49,8 +51,17 @@ public static void validateResponseWithSuccess( JsonObject response, String resu validateResponseWithSuccess(response, resultType, false); } protected static void validateResponseWithSuccess(JsonObject response, String resultType, Boolean isArrayResultType) { - Assert.assertEquals( response.has("success"), true ); - Assert.assertEquals( response.has("data"), true ); + // Lets sleep for a while. + try { + int randomTimeBuffer = getRandomNumberInRange(10, 99); + Thread.sleep(sleepMilliSeconds + randomTimeBuffer); + } catch (InterruptedException e) { + //Ignore it. + } + + // + Assert.assertEquals( "success key missing in response.", true, response.has("success") ); + Assert.assertEquals( "data key missing in response.", true, response.has("data") ); // Validate Success Flag. boolean success = response.get("success").getAsBoolean(); @@ -87,6 +98,20 @@ protected static void validateResult( Map params, JsonObject resu } } + protected static String generateNamePostFix() { + return String.valueOf(System.currentTimeMillis()) + (getRandomNumberInRange(0, 99)).toString(); + } + + protected static Integer getRandomNumberInRange(int min, int max) { + + if (min >= max) { + throw new IllegalArgumentException("max must be greater than min"); + } + + Random r = new Random(); + return r.nextInt((max - min) + 1) + min; + } + @After public void tearDown() throws Exception { ostsdk = null; diff --git a/src/test/java/com/ost/services/v0/TransactionKindTest.java b/src/test/java/com/ost/services/v0/TransactionKindTest.java index 5113d96..857be73 100644 --- a/src/test/java/com/ost/services/v0/TransactionKindTest.java +++ b/src/test/java/com/ost/services/v0/TransactionKindTest.java @@ -1,8 +1,6 @@ package com.ost.services.v0; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import com.sun.org.apache.xpath.internal.operations.Bool; -import org.junit.Assert; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; @@ -29,7 +27,7 @@ public void setUp() throws Exception { @Test public void t1Create() throws IOException { HashMap params = new HashMap(); - params.put("name", "C1 " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "C1 " + generateNamePostFix() ); params.put("kind", "company_to_user"); params.put("currency_type", "BT"); params.put("currency_value", 10); @@ -47,7 +45,7 @@ public void t1Create() throws IOException { @Test public void t2Edit() throws IOException { HashMap params = new HashMap(); - params.put("name", "C2 " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "C2 " + generateNamePostFix() ); params.put("kind", "user_to_user"); params.put("currency_type", "USD"); params.put("currency_value", 10); diff --git a/src/test/java/com/ost/services/v1/ActionsTest.java b/src/test/java/com/ost/services/v1/ActionsTest.java index 0eaa31c..eacdb55 100644 --- a/src/test/java/com/ost/services/v1/ActionsTest.java +++ b/src/test/java/com/ost/services/v1/ActionsTest.java @@ -29,7 +29,7 @@ public void setUp() throws Exception { @Test public void create() throws IOException { HashMap params = new HashMap(); - params.put("name", "C1 " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "C1 " + generateNamePostFix() ); params.put("kind", "company_to_user"); params.put("currency", "BT"); params.put("arbitrary_amount", true); @@ -48,7 +48,7 @@ public void create() throws IOException { public void edit() throws IOException, OSTAPIService.MissingParameter { // First Create. HashMap params = new HashMap(); - params.put("name", "C2 " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "C2 " + generateNamePostFix() ); params.put("kind", "user_to_user"); params.put("currency", "BT"); params.put("arbitrary_amount", true); @@ -83,7 +83,7 @@ public void edit() throws IOException, OSTAPIService.MissingParameter { public void get() throws IOException, OSTAPIService.MissingParameter { //First Create. HashMap params = new HashMap(); - params.put("name", "C3 " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "C3 " + generateNamePostFix() ); params.put("kind", "user_to_company"); params.put("currency", "BT"); params.put("arbitrary_amount", true); diff --git a/src/test/java/com/ost/services/v1/TransactionsTest.java b/src/test/java/com/ost/services/v1/TransactionsTest.java index 232e958..beb093f 100644 --- a/src/test/java/com/ost/services/v1/TransactionsTest.java +++ b/src/test/java/com/ost/services/v1/TransactionsTest.java @@ -30,7 +30,7 @@ public void setUp() throws Exception { //First Create an action HashMap params = new HashMap(); - params.put("name", "T1 " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "T1 " + generateNamePostFix() ); params.put("kind", "user_to_user"); params.put("currency", "BT"); params.put("arbitrary_amount", false); diff --git a/src/test/java/com/ost/services/v1/UsersTest.java b/src/test/java/com/ost/services/v1/UsersTest.java index 18449ed..25eac4c 100644 --- a/src/test/java/com/ost/services/v1/UsersTest.java +++ b/src/test/java/com/ost/services/v1/UsersTest.java @@ -32,7 +32,7 @@ public void setUp() throws Exception { public void create() throws IOException { //First Create. HashMap params = new HashMap(); - params.put("name", "Alice " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "Tom" + generateNamePostFix() ); JsonObject response; String resultType = "user"; @@ -48,7 +48,7 @@ public void create() throws IOException { public void edit() throws IOException, OSTAPIService.MissingParameter { //First Create. HashMap params = new HashMap(); - params.put("name", "Ben " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "Ben " + generateNamePostFix() ); JsonObject response; String resultType = "user"; @@ -59,7 +59,7 @@ public void edit() throws IOException, OSTAPIService.MissingParameter { validateResult(params, result); params.put("id", result.get("id").getAsString() ); - params.put("name", "Jax " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "Jax " + generateNamePostFix() ); response = getService().edit( params ); validateResponseWithSuccess( response, resultType, isArrayResultType ); result = response.getAsJsonObject("data").getAsJsonObject( resultType ); @@ -71,7 +71,7 @@ public void edit() throws IOException, OSTAPIService.MissingParameter { public void get() throws IOException, OSTAPIService.MissingParameter { //First Create. HashMap params = new HashMap(); - params.put("name", "Bob " + String.valueOf(System.currentTimeMillis() / 1000) ); + params.put("name", "Bob " + generateNamePostFix() ); JsonObject response; String resultType = "user";