// Path: pentaho-mongodb-plugin/src/main/java/org/pentaho/di/trans/steps/mongodboutput/MongoDbOutputMeta.java
// public static class MongoIndex {
// 
//   /**
//    * Dot notation for accessing a fields - e.g. person.address.street. Can also specify entire embedded documents as
//    * an index (rather than a primitive key) - e.g. person.address.
//    *
//    * Multiple fields are comma-separated followed by an optional "direction" indicator for the index (1 or -1). If
//    * omitted, direction is assumed to be 1.
//    */
//   @Injection( name = "INDEX_FIELD", group = "INDEXES" )
//   public String m_pathToFields = ""; //$NON-NLS-1$
// 
//   /** whether to drop this index - default is create */
//   @Injection( name = "DROP", group = "INDEXES" )
//   public boolean m_drop;
// 
//   // other options unique, sparse
//   @Injection( name = "UNIQUE", group = "INDEXES" )
//   public boolean m_unique;
//   @Injection( name = "SPARSE", group = "INDEXES" )
//   public boolean m_sparse;
// 
//   @Override
//   public String toString() {
//     StringBuffer buff = new StringBuffer();
//     buff.append( m_pathToFields + " (unique = " //$NON-NLS-1$
//         + new Boolean( m_unique ).toString() + " sparse = " //$NON-NLS-1$
//         + new Boolean( m_sparse ).toString() + ")" ); //$NON-NLS-1$
// 
//     return buff.toString();
//   }
// }


import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.trans.steps.mongodboutput.MongoDbOutputMeta.MongoIndex;
import org.pentaho.mongo.MongoDbException;
import org.pentaho.mongo.wrapper.MongoClientWrapper;
import org.pentaho.mongo.wrapper.collection.DefaultMongoCollectionWrapper;
import org.pentaho.mongo.wrapper.collection.MongoCollectionWrapper;
import java.util.Arrays;
import java.util.List;
import static junit.framework.TestCase.fail;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
        .thenAnswer( new Answer<String>() {
          @Override public String answer( InvocationOnMock invocationOnMock ) throws Throwable {
            return (String) invocationOnMock.getArguments()[0];
          }
        } );
    when( space.environmentSubstitute( any( String.class ), anyBoolean() ) )
      .thenAnswer( new Answer<String>() {
        @Override public String answer( InvocationOnMock invocationOnMock ) throws Throwable {
          return (String) invocationOnMock.getArguments()[0];
        }
      } );
  }

  @BeforeClass
  public static void setUpBeforeClass() throws KettleException {
    KettleEnvironment.init( false );
  }

  @Test
  public void testApplyIndexesOptions() throws KettleException, MongoDbException {
    MongoDbOutputData data = new MongoDbOutputData();
    LogChannelInterface log = new LogChannel( data );
    DBCollection collection = mock( DBCollection.class );
    MongoCollectionWrapper collectionWrapper = spy( new DefaultMongoCollectionWrapper( collection ) );
    data.setCollection( collectionWrapper );

    ArgumentCaptor<BasicDBObject> captorIndexes = ArgumentCaptor.forClass( BasicDBObject.class );
    ArgumentCaptor<BasicDBObject> captorOptions = ArgumentCaptor.forClass( BasicDBObject.class );
    doNothing().when( collectionWrapper ).createIndex( captorIndexes.capture(), captorOptions.capture() );

// Path: pentaho-mongodb-plugin/src/main/java/org/pentaho/di/trans/steps/mongodboutput/MongoDbOutputMeta.java
// public static class MongoIndex {
// 
//   /**
//    * Dot notation for accessing a fields - e.g. person.address.street. Can also specify entire embedded documents as
//    * an index (rather than a primitive key) - e.g. person.address.
//    *
//    * Multiple fields are comma-separated followed by an optional "direction" indicator for the index (1 or -1). If
//    * omitted, direction is assumed to be 1.
//    */
//   @Injection( name = "INDEX_FIELD", group = "INDEXES" )
//   public String m_pathToFields = ""; //$NON-NLS-1$
// 
//   /** whether to drop this index - default is create */
//   @Injection( name = "DROP", group = "INDEXES" )
//   public boolean m_drop;
// 
//   // other options unique, sparse
//   @Injection( name = "UNIQUE", group = "INDEXES" )
//   public boolean m_unique;
//   @Injection( name = "SPARSE", group = "INDEXES" )
//   public boolean m_sparse;
// 
//   @Override
//   public String toString() {
//     StringBuffer buff = new StringBuffer();
//     buff.append( m_pathToFields + " (unique = " //$NON-NLS-1$
//         + new Boolean( m_unique ).toString() + " sparse = " //$NON-NLS-1$
//         + new Boolean( m_sparse ).toString() + ")" ); //$NON-NLS-1$
// 
//     return buff.toString();
//   }
// }


// Path: pentaho-mongodb-plugin/src/test/java/org/pentaho/di/trans/steps/mongodboutput/MongoDbOutputDataTest.java
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.trans.steps.mongodboutput.MongoDbOutputMeta.MongoIndex;
import org.pentaho.mongo.MongoDbException;
import org.pentaho.mongo.wrapper.MongoClientWrapper;
import org.pentaho.mongo.wrapper.collection.DefaultMongoCollectionWrapper;
import org.pentaho.mongo.wrapper.collection.MongoCollectionWrapper;
import java.util.Arrays;
import java.util.List;
import static junit.framework.TestCase.fail;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

        .thenAnswer( new Answer<String>() {
          @Override public String answer( InvocationOnMock invocationOnMock ) throws Throwable {
            return (String) invocationOnMock.getArguments()[0];
          }
        } );
    when( space.environmentSubstitute( any( String.class ), anyBoolean() ) )
      .thenAnswer( new Answer<String>() {
        @Override public String answer( InvocationOnMock invocationOnMock ) throws Throwable {
          return (String) invocationOnMock.getArguments()[0];
        }
      } );
  }

  @BeforeClass
  public static void setUpBeforeClass() throws KettleException {
    KettleEnvironment.init( false );
  }

  @Test
  public void testApplyIndexesOptions() throws KettleException, MongoDbException {
    MongoDbOutputData data = new MongoDbOutputData();
    LogChannelInterface log = new LogChannel( data );
    DBCollection collection = mock( DBCollection.class );
    MongoCollectionWrapper collectionWrapper = spy( new DefaultMongoCollectionWrapper( collection ) );
    data.setCollection( collectionWrapper );

    ArgumentCaptor<BasicDBObject> captorIndexes = ArgumentCaptor.forClass( BasicDBObject.class );
    ArgumentCaptor<BasicDBObject> captorOptions = ArgumentCaptor.forClass( BasicDBObject.class );
    doNothing().when( collectionWrapper ).createIndex( captorIndexes.capture(), captorOptions.capture() );

    MongoIndex index = new MongoDbOutputMeta.MongoIndex();