1 package org.oxerr.okcoin.rest.dto.valuereader; 2 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.assertTrue; 5 import static org.junit.Assert.fail; 6 7 import java.io.IOException; 8 import java.io.InputStream; 9 import java.math.BigDecimal; 10 import java.nio.charset.StandardCharsets; 11 12 import org.apache.commons.io.IOUtils; 13 import org.junit.Test; 14 import org.oxerr.okcoin.rest.dto.IcebergOrder; 15 import org.oxerr.okcoin.rest.dto.IcebergOrderHistory; 16 import org.oxerr.okcoin.rest.dto.Status; 17 import org.oxerr.okcoin.rest.dto.Type; 18 import org.oxerr.okcoin.rest.service.web.LoginRequiredException; 19 import org.oxerr.okcoin.rest.service.web.OKCoinClient; 20 21 public class IcebergOrdersReaderTest { 22 23 private final IcebergOrdersReader reader = new IcebergOrdersReader(); 24 25 @Test 26 public void testNotLoggedIn() throws IOException { 27 try (InputStream inputStream = IOUtils.toInputStream("", OKCoinClient.ENCODING)) { 28 reader.read(inputStream, null, StandardCharsets.UTF_8); 29 fail("A LoginRequiredException should be thrown."); 30 } catch (LoginRequiredException e) { 31 assertEquals("No HTML table found.", e.getMessage()); 32 } 33 } 34 35 @Test 36 public void testIcebergOrders0() throws IOException { 37 try (InputStream inputStream = getClass().getResourceAsStream( 38 "open-iceberg-orders-0.html")) { 39 IcebergOrder[] orders = reader.read(inputStream, null, StandardCharsets.UTF_8).getOrders(); 40 assertEquals(0, orders.length); 41 } 42 } 43 44 @Test 45 public void testIcebergOrders1() throws IOException { 46 try (InputStream inputStream = getClass().getResourceAsStream( 47 "open-iceberg-orders-1.html")) { 48 IcebergOrder[] orders = reader.read(inputStream, null, StandardCharsets.UTF_8).getOrders(); 49 assertEquals(1, orders.length); 50 IcebergOrder order = orders[0]; 51 assertEquals("2015-02-15T09:53:28Z", order.getDate().toString()); 52 assertEquals(Type.BUY, order.getSide()); 53 assertEquals(new BigDecimal("100"), order.getTradeValue()); 54 assertEquals(new BigDecimal("1"), order.getSingleAvg()); 55 assertEquals(new BigDecimal("0.1"), order.getDepthRange()); 56 assertEquals(new BigDecimal("1"), order.getProtectedPrice()); 57 assertEquals(new BigDecimal("0"), order.getFilled()); 58 assertEquals(12732L, order.getId()); 59 } 60 } 61 62 @Test 63 public void testIcebergOrderHistory() throws IOException { 64 try (InputStream inputStream = getClass().getResourceAsStream("order-history-iceberg-orders.html")) { 65 IcebergOrderHistory history = reader.read(inputStream, null, StandardCharsets.UTF_8); 66 IcebergOrder[] orders = history.getOrders(); 67 assertEquals(10, orders.length); 68 assertEquals("2015-02-17T14:23:25Z", orders[0].getDate().toString()); 69 assertEquals(Type.BUY, orders[0].getSide()); 70 assertEquals(new BigDecimal("100"), orders[0].getTradeValue()); 71 assertEquals(new BigDecimal("1"), orders[0].getSingleAvg()); 72 assertEquals(new BigDecimal("0.1"), orders[0].getDepthRange()); 73 assertEquals(new BigDecimal("1"), orders[0].getProtectedPrice()); 74 assertEquals(new BigDecimal("0"), orders[0].getFilled()); 75 assertEquals(Status.CANCELLED, orders[0].getStatus()); 76 assertEquals(12836L, orders[0].getId()); 77 78 assertEquals(1, history.getCurrentPage()); 79 assertTrue(history.hasNextPage()); 80 } 81 } 82 83 }