Files
ATS_Esper/src/test/java/ats/orders/StopLossDetailsTest.java

54 lines
1.5 KiB
Java

package ats.orders;
import java.math.BigDecimal;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.joda.time.DateTime;
import org.json.JSONException;
import org.junit.Test;
/**
* StopLossDetailsTest tests JSON format serialization of
* StopLossDetails objects.
*/
public class StopLossDetailsTest extends OrderSerializationTestBase {
/**
* Test the simplest form, including default values.
*/
@Test
public void testToJSONSmall()
throws JsonProcessingException, JSONException
{
StopLossDetails obj = new StopLossDetails();
obj.price = "12.34";
String expected = "{\"price\":\"12.34\",\"timeInForce\":\"GTC\",\"guaranteed\":false}";
doTest(obj, expected);
}
/**
* Test a fully filled out object.
*/
@Test
public void testToJSONLarge()
throws JsonProcessingException, JSONException
{
StopLossDetails obj = new StopLossDetails();
obj.distance = new BigDecimal("12.34");
obj.timeInForce = TimeInForce.GFD;
obj.gtdTime = new DateTime("2000-09-17T18:02:52.957Z");
obj.clientExtensions = new ClientExtensions();
obj.clientExtensions.id = "my id";
obj.clientExtensions.tag = "my tag";
obj.clientExtensions.comment = "my comment";
String expected = "{\"distance\":12.34,\"timeInForce\":\"GFD\",\"gtdTime\":\"2000-09-17T18:02:52.957Z\",\"clientExtensions\":{\"id\":\"my id\",\"tag\":\"my tag\",\"comment\":\"my comment\"},\"guaranteed\":false}";
doTest(obj, expected);
}
}