package org.knowm.xchange.kraken.dto.marketdata;

import static org.fest.assertions.api.Assertions.assertThat;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.knowm.xchange.kraken.dto.marketdata.results.KrakenAssetPairsResult;

import com.fasterxml.jackson.databind.ObjectMapper;

public class KrakenAssetPairsJSONTest {

  private KrakenAssetPair expectedAssetPairInfo;

  @Before
  public void before() {

    List<KrakenFee> fees = new ArrayList<>();
    fees.add(new KrakenFee(new BigDecimal("0"), new BigDecimal("0.3")));
    expectedAssetPairInfo = new KrakenAssetPair("XBTUSD", "currency", "XXBT", "currency", "ZUSD", "unit", 5, 8, new BigDecimal(1),
        new ArrayList<String>(), fees, "ZUSD", new BigDecimal(80), new BigDecimal(40));
  }

  @Test
  public void testUnmarshal() throws IOException {

    // Read in the JSON from the example resources
    InputStream is = KrakenAssetPairsJSONTest.class.getResourceAsStream("/marketdata/example-assetpairs-data.json");

    // Use Jackson to parse it
    ObjectMapper mapper = new ObjectMapper();
    KrakenAssetPairsResult krakenAssetPairs = mapper.readValue(is, KrakenAssetPairsResult.class);

    // Verify that the example data was unmarshalled correctly
    assertThat(krakenAssetPairs.getResult().get("XXBTZEUR")).isNotNull();
    assertThat(krakenAssetPairs.getResult().get("XBTCEUR")).isNull();

    KrakenAssetPair krakenAssetPairInfo = krakenAssetPairs.getResult().get("XXBTZUSD");
    assertThat(krakenAssetPairInfo.getAltName()).isEqualTo(expectedAssetPairInfo.getAltName());
    assertThat(krakenAssetPairInfo.getBase()).isEqualTo(expectedAssetPairInfo.getBase());
    assertThat(krakenAssetPairInfo.getClassBase()).isEqualTo(expectedAssetPairInfo.getClassBase());
    assertThat(krakenAssetPairInfo.getClassQuote()).isEqualTo(expectedAssetPairInfo.getClassQuote());
    assertThat(krakenAssetPairInfo.getFeeVolumeCurrency()).isEqualTo(expectedAssetPairInfo.getFeeVolumeCurrency());
    assertThat(krakenAssetPairInfo.getLeverage()).isEqualTo(expectedAssetPairInfo.getLeverage());
    assertThat(krakenAssetPairInfo.getQuote()).isEqualTo(expectedAssetPairInfo.getQuote());
    assertThat(krakenAssetPairInfo.getVolumeLotSize()).isEqualTo(expectedAssetPairInfo.getVolumeLotSize());
    assertThat(krakenAssetPairInfo.getPairScale()).isEqualTo(expectedAssetPairInfo.getPairScale());
    assertThat(krakenAssetPairInfo.getVolumeLotScale()).isEqualTo(expectedAssetPairInfo.getVolumeLotScale());
    assertThat(krakenAssetPairInfo.getMarginCall()).isEqualTo(expectedAssetPairInfo.getMarginCall());
    assertThat(krakenAssetPairInfo.getMarginStop()).isEqualTo(expectedAssetPairInfo.getMarginStop());
    assertThat(krakenAssetPairInfo.getVolumeMultiplier()).isEqualTo(expectedAssetPairInfo.getVolumeMultiplier());
    assertThat(krakenAssetPairInfo.getFees().size()).isEqualTo(26);

    KrakenFee deserializedFee = krakenAssetPairInfo.getFees().get(0);
    KrakenFee expectedFee = expectedAssetPairInfo.getFees().get(0);
    assertThat(deserializedFee.getPercentFee()).isEqualTo(expectedFee.getPercentFee());
    assertThat(deserializedFee.getVolume()).isEqualTo(expectedFee.getVolume());
  }
}

@@ -214,24 +214,49 @@
 .ArrayList;%0A
+import java.util.Arrays;%0A
 import java.
@@ -266,16 +266,16 @@
 l.List;%0A
-
 %0Aimport 
@@ -691,15 +691,276 @@
 (%220.
-3
+26
 %22)));%0A
+    List%3CKrakenFee%3E fees_maker = new ArrayList%3C%3E();%0A    fees.add(new KrakenFee(new BigDecimal(%220%22), new BigDecimal(%220.1%22)));%0A    List%3CString%3E leverage_buy = Arrays.asList(%222%22, %223%22, %224%22, %225%22);%0A    List%3CString%3E leverage_sell = Arrays.asList(%222%22, %223%22, %224%22, %225%22);%0A
     
@@ -1061,17 +1061,17 @@
 %22unit%22, 
-5
+3
 , 8, new
@@ -1098,37 +1098,25 @@
     
-new ArrayList%3CString%3E(), fees
+fees,  fees_maker
 , %22Z
@@ -1163,16 +1163,44 @@
 (40)
+, leverage_buy, leverage_sell
 );%0A  %7D%0A
-%0A
   @T
@@ -2446,16 +2446,20 @@
 Leverage
+_buy
 ()).isEq
@@ -2497,16 +2497,128 @@
 Leverage
+_buy());%0A    assertThat(krakenAssetPairInfo.getLeverage_sell()).isEqualTo(expectedAssetPairInfo.getLeverage_sell
 ());%0A   
@@ -3405,18 +3405,17 @@
 EqualTo(
-26
+9
 );%0A%0A    

Update KrakenAssetPairsJSONTest.java