Skip to content

Commit

Permalink
Some modification on API client test
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Apr 11, 2012
1 parent baeb3a0 commit 88ef1b9
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions client/src/test/java/io/iron/ironworker/client/APIClientTest.java
Expand Up @@ -3,6 +3,9 @@
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.iron.ironworker.client.builders.ParamsObject;
import io.iron.ironworker.client.builders.ScheduleOptionsObject;
import io.iron.ironworker.client.entities.ScheduleEntity;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
Expand All @@ -11,6 +14,9 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map; import java.util.Map;


import static org.junit.Assert.*; import static org.junit.Assert.*;
Expand Down Expand Up @@ -48,6 +54,19 @@ public void shouldHaveEnvironmentVariable() {
assertNotNull(IRON_IO_TOKEN + " environment variable not set", _ironToken); assertNotNull(IRON_IO_TOKEN + " environment variable not set", _ironToken);
} }


/*@Test
public void shouldCodesCreate() throws APIException, ParseException {
Client client = new Client("P7g9m72eTekPHd0bNCkCeBytrhQ", "4f63775f8de4561d19000804");
//params
ParamsObject paramsObject = new ParamsObject();
paramsObject.add("test", "http://");
//options
ScheduleOptionsObject scheduleOptionsObject = new ScheduleOptionsObject();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
scheduleOptionsObject.startAt(simpleDateFormat.parse("08/04/2012 23:45:00"));
ScheduleEntity entity = client.createSchedule("JavaHelloWorker", paramsObject, scheduleOptionsObject);
}*/

@Test(expected = APIException.class) @Test(expected = APIException.class)
public void shouldConnexionFail() throws APIException { public void shouldConnexionFail() throws APIException {
APIClient client = new APIClient("badToken", "badProject"); APIClient client = new APIClient("badToken", "badProject");
Expand Down Expand Up @@ -107,11 +126,7 @@ public void shouldCodesDelete() throws APIException {
assertEquals("Deleted", deleteMessage.get("msg").getAsString()); assertEquals("Deleted", deleteMessage.get("msg").getAsString());
} }


/**
* Check the validity of revision object.
*
* @param revision the json object that represent a revision
*/
private void checkCodeRevisionValidity(JsonObject revision) { private void checkCodeRevisionValidity(JsonObject revision) {
assertNotNull(revision); assertNotNull(revision);
assertNotNull(revision.get("id").getAsString()); assertNotNull(revision.get("id").getAsString());
Expand All @@ -123,12 +138,6 @@ private void checkCodeRevisionValidity(JsonObject revision) {
assertEquals(WORKER_FILE, revision.get("file_name").getAsString()); assertEquals(WORKER_FILE, revision.get("file_name").getAsString());
} }


/**
* Check the validity of code object.
*
* @param code the json object that represent a code package
* @return id of the code
*/
private String checkCodePackageValidity(JsonObject code) { private String checkCodePackageValidity(JsonObject code) {
assertNotNull(code); assertNotNull(code);
String id = code.get("id").getAsString(); String id = code.get("id").getAsString();
Expand All @@ -138,13 +147,6 @@ private String checkCodePackageValidity(JsonObject code) {
return id; return id;
} }


/**
* Find a code by name.
*
* @param codes the list of available codes
* @param name the name of the code to find
* @return the json object code or IllegalArgumentException
*/
private JsonObject fetchCodeFromName(JsonArray codes, String name) { private JsonObject fetchCodeFromName(JsonArray codes, String name) {
for (JsonElement code : codes) { for (JsonElement code : codes) {
String codeName = code.getAsJsonObject().get("name").getAsString(); String codeName = code.getAsJsonObject().get("name").getAsString();
Expand Down

0 comments on commit 88ef1b9

Please sign in to comment.