/**
 * Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.financial.analytics.volatility.surface;

import static org.testng.AssertJUnit.assertEquals;

import org.testng.annotations.Test;
import org.threeten.bp.DayOfWeek;
import org.threeten.bp.LocalDate;

import com.opengamma.core.id.ExternalSchemes;
import com.opengamma.financial.analytics.ircurve.NextExpiryAdjuster;
import com.opengamma.financial.analytics.model.FutureOptionExpiries;
import com.opengamma.id.ExternalId;

/**
 *
 */
public class BloombergEquityFutureOptionVolatilitySurfaceInstrumentProviderTest {
  private static final String PREFIX = "DJX";
  private static final String POSTFIX = "Index";
  private static final LocalDate DATE = LocalDate.of(2012, 5, 23);
  private static final Short[] EXPIRY_OFFSETS = new Short[] {1, 2, 8};
  private static final Double[] STRIKES = new Double[] {90.0, 145.0, 205.0};

  private static final String DATA_FIELD_NAME = "OPT_IMPLIED_VOLATILITY_MID";

  private static final String[][] RESULTS = new String[][]
    {new String[] {"DJX 06/16/12 P90.0 Index", "DJX 06/16/12 P145.0 Index", "DJX 06/16/12 C205.0 Index"},
    new String[] {"DJX 07/21/12 P90.0 Index", "DJX 07/21/12 P145.0 Index", "DJX 07/21/12 C205.0 Index"},
    new String[] {"DJX 03/16/13 P90.0 Index", "DJX 03/16/13 P145.0 Index", "DJX 03/16/13 C205.0 Index"}}; // TODO Fix date on this last one

  private static final FutureOptionExpiries UTILS = FutureOptionExpiries.of(new NextExpiryAdjuster(3, DayOfWeek.FRIDAY, 1));
  private static LocalDate[] EXPIRY_DATES = new LocalDate[3];
  private static final String EXCHANGE = "OSE";
  static {
    for (int i = 0; i < EXPIRY_OFFSETS.length; i++) {
      EXPIRY_DATES[i] = FutureOptionExpiries.EQUITY.getFutureOptionExpiry(EXPIRY_OFFSETS[i], DATE);
    }
  }

  private static final BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider PROVIDER =
      new BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider(PREFIX, POSTFIX, DATA_FIELD_NAME, 150.25, EXCHANGE);


  @Test
  public void test() {
    for (int i = 0; i < EXPIRY_OFFSETS.length; i++) {
      for (int j = 0; j < STRIKES.length; j++) {
        final String expected = RESULTS[i][j];
        final ExternalId actual = PROVIDER.getInstrument(EXPIRY_OFFSETS[i], STRIKES[j], DATE);
        assertEquals(ExternalSchemes.BLOOMBERG_TICKER_WEAK, actual.getScheme());
        assertEquals(expected, actual.getValue());
      }
    }
  }

  @Test
  public void testUtils() {
    assertEquals(EXPIRY_DATES[0], FutureOptionExpiries.EQUITY.getMonthlyExpiry(1, DATE));
    assertEquals(EXPIRY_DATES[1], FutureOptionExpiries.EQUITY.getMonthlyExpiry(2, DATE));
    assertEquals(EXPIRY_DATES[2], FutureOptionExpiries.EQUITY.getQuarterlyExpiry(EXPIRY_OFFSETS[2]-6, UTILS.getMonthlyExpiry(6, DATE)));
  }


}

@@ -1321,32 +1321,34 @@
 .0 Index%22%7D,%0A    
+  
 new String%5B%5D %7B%22D
@@ -1345,29 +1345,30 @@
 ring%5B%5D %7B
+ 
 %22DJX 0
-3/16/13
+1/18/14
  P90.0 I
@@ -1380,23 +1380,23 @@
 , %22DJX 0
-3/16/13
+1/18/14
  P145.0 
@@ -1413,15 +1413,15 @@
 JX 0
-3/16/13
+1/18/14
  C20
@@ -1430,17 +1430,19 @@
 0 Index%22
-%7D
+ %7D 
 %7D; // TO

Fix EquityFutureOptionVolatilitySurfaceProvider test (yearly expires after 6 months)