package com.gengo.client;

import java.lang.System;
import java.util.ArrayList;
import java.util.List;

import com.gengo.client.GengoClient;
import com.gengo.client.exceptions.GengoException;
import com.gengo.client.payloads.TranslationJob;
import com.gengo.client.enums.Tier;

import org.json.JSONObject;
import org.json.JSONException;
import org.junit.Assert;
import org.junit.Test;

public class JobsTest {

    private String public_key = System.getenv("GENGO_PUBKEY");
    private String private_key = System.getenv("GENGO_PRIVKEY");

    @Test
    public void testPostJobs() throws GengoException, JSONException {

        GengoClient Gengo = new GengoClient(this.public_key, this.private_key, true);
        List<TranslationJob> jobList = new ArrayList<TranslationJob>();
        jobList.add(new TranslationJob("java client test", "This is a short story.","en","ja",Tier.STANDARD));
        JSONObject response = Gengo.postTranslationJobs(jobList, true);
        Assert.assertEquals(response.get("opstat").toString(), "ok");
        Assert.assertTrue(response.has("response"));
    }
}

@@ -37,22 +37,112 @@
 va.lang.
-System
+Integer;%0Aimport java.lang.System;%0Aimport java.lang.Thread;%0Aimport java.lang.InterruptedException
 ;%0Aimport
@@ -661,16 +661,20 @@
 PostJobs
+Text
 () throw
@@ -704,19 +704,67 @@
 xception
- %7B%0A
+, InterruptedException %7B%0A        // POST a text job
 %0A       
@@ -926,20 +926,29 @@
     
-jobList.add(
+TranslationJob job = 
 new 
@@ -1011,18 +1011,21 @@
 y.%22,
+ 
 %22en%22,
+ 
 %22ja%22,
+ 
 Tier
@@ -1034,16 +1034,83 @@
 TANDARD)
+;%0A        job.setForceNewTranslation(true);%0A        jobList.add(job
 );%0A     
@@ -1123,24 +1123,24 @@
 NObject 
-response
+postResp
  = Gengo
@@ -1188,120 +1188,1403 @@
     
-Assert.assertEquals(response.get(%22opstat%22).toString(), %22ok%22);%0A        Assert.assertTrue(response.has(%22response%22)
+// Make assertions on POST response%0A        Assert.assertEquals(postResp.getString(%22opstat%22), %22ok%22);%0A        Assert.assertTrue(postResp.has(%22response%22));%0A        JSONObject postResponse = postResp.getJSONObject(%22response%22);%0A        Assert.assertEquals(postResponse.get(%22job_count%22), 1);%0A        Assert.assertTrue(postResponse.has(%22credits_used%22));%0A        Assert.assertTrue(postResponse.has(%22order_id%22));%0A        String orderId = postResponse.getString(%22order_id%22);%0A%0A        // GET order%0A        Thread.sleep(3000);%0A        JSONObject getOrderResp = Gengo.getOrderJobs(Integer.parseInt(orderId));%0A        // Make assertions on GET response%0A        Assert.assertEquals(getOrderResp.getString(%22opstat%22), %22ok%22);%0A        Assert.assertTrue(getOrderResp.has(%22response%22));%0A        JSONObject getOrderResponse = getOrderResp.getJSONObject(%22response%22);%0A        String jobId = getOrderResponse.getJSONObject(%22order%22).getJSONArray(%22jobs_available%22).getString(0);%0A%0A        // GET job%0A        JSONObject getJobResp = Gengo.getTranslationJob(Integer.parseInt(jobId));%0A        Assert.assertEquals(getJobResp.getString(%22opstat%22), %22ok%22);%0A        Assert.assertTrue(getJobResp.has(%22response%22));%0A        JSONObject getJobResponse = getJobResp.getJSONObject(%22response%22);%0A        String bodySrc = getJobResponse.getJSONObject(%22job%22).getString(%22body_src%22);%0A        Assert.assertEquals(bodySrc, %22This is a short story.%22
 );%0A 

test GET methods for order and job