55 lines
2.0 KiB
Java
55 lines
2.0 KiB
Java
package ats.orders;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.oanda.v20.order.OrderTriggerCondition;
|
|
|
|
import org.joda.time.DateTime;
|
|
import org.json.JSONException;
|
|
import org.junit.Test;
|
|
|
|
/**
|
|
* TakeProfitOrderRequestTest tests JSON format serialization of
|
|
* TakeProfitOrderRequest objects.
|
|
*/
|
|
public class TakeProfitOrderRequestTest extends OrderSerializationTestBase {
|
|
|
|
|
|
/**
|
|
* Test the simplest form, including default values.
|
|
*/
|
|
@Test
|
|
public void testToJSONSmall()
|
|
throws JsonProcessingException, JSONException
|
|
{
|
|
TakeProfitOrderRequest obj = new TakeProfitOrderRequest("12", "23", "45.67");
|
|
|
|
String expected = "{\"type\":\"TAKE_PROFIT\",\"tradeID\":\"12\",\"clientTradeID\":\"23\",\"price\":\"45.67\",\"timeInForce\":\"GTC\",\"triggerCondition\":\"DEFAULT\"}";
|
|
|
|
doTest(obj, expected);
|
|
}
|
|
|
|
/**
|
|
* Test a fully filled out object.
|
|
*/
|
|
@Test
|
|
public void testToJSONLarge()
|
|
throws JsonProcessingException, JSONException
|
|
{
|
|
ClientExtensions clientExtensions = new ClientExtensions();
|
|
clientExtensions.id = "my id";
|
|
clientExtensions.tag = "my tag";
|
|
clientExtensions.comment = "my comment";
|
|
|
|
TakeProfitOrderRequest obj = new TakeProfitOrderRequest("12", "23", "45.67",
|
|
TimeInForce.IOC,
|
|
new DateTime("2000-09-17T18:02:52.957Z"),
|
|
OrderTriggerCondition.MID,
|
|
clientExtensions);
|
|
|
|
|
|
String expected = "{\"type\":\"TAKE_PROFIT\",\"tradeID\":\"12\",\"clientTradeID\":\"23\",\"price\":\"45.67\",\"timeInForce\":\"IOC\",\"gtdTime\":\"2000-09-17T18:02:52.957Z\",\"triggerCondition\":\"MID\",\"clientExtensions\":{\"id\":\"my id\",\"tag\":\"my tag\",\"comment\":\"my comment\"}}";
|
|
|
|
doTest(obj, expected);
|
|
}
|
|
}
|