package mobi.boilr.libdynticker.exchanges; import java.io.File; import java.io.IOException; import java.util.List; import mobi.boilr.libdynticker.core.ExchangeTest; import mobi.boilr.libdynticker.core.Pair; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class OKCoinExchangeTest extends ExchangeTest { @Override @Before public void setUp() throws Exception { testExchange = new OKCoinExchange(1000); } @Override @After public void tearDown() throws Exception { } @Test public void testGetPairs() { List<Pair> pairs; try { pairs = testExchange.getPairs(); Assert.assertTrue(pairs.contains(new Pair("BTC", "CNY"))); Assert.assertTrue(pairs.contains(new Pair("LTC", "USD"))); Assert.assertFalse(pairs.contains(new Pair("InvalidCoin", "BTC"))); } catch(IOException e) { Assert.fail(); } } @Test public void testParseTicker() { try { Pair pair = new Pair("BTC", "CNY"); JsonNode node = (new ObjectMapper().readTree(new File("src/test/json/okcoin-ticker.json"))); String lastValue = testExchange.parseTicker(node, pair); Assert.assertEquals("3652.0", lastValue); } catch(IOException e) { e.printStackTrace(); Assert.fail(); } } @Test public void testParseJSONFuture() { try { Pair pair = new Pair("BTC", "CNY"); JsonNode node = (new ObjectMapper().readTree(new File("src/test/json/okcoin-future-ticker.json"))); String lastValue = ((OKCoinExchange) testExchange).parseJSONFuture(node, pair); Assert.assertEquals("374.1", lastValue); } catch(IOException e) { e.printStackTrace(); Assert.fail(); } } }