package es.tid.bdp.samples.wordcount.export.mongodb;

import static java.util.Arrays.asList;
import java.util.List;

import com.mongodb.hadoop.io.BSONWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mrunit.mapreduce.ReduceDriver;
import org.apache.hadoop.mrunit.types.Pair;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;

/**
 * Use case for ExporterReducer
 *
 * @author dmicol, sortega
 */
public class MongoDBExporterReducerTest {
    private MongoDBExporterReducer instance;
    private ReduceDriver<LongWritable, Text, NullWritable, BSONWritable> driver;

    @Before
    public void setUp() {
        this.instance = new MongoDBExporterReducer();
        this.driver = new ReduceDriver<LongWritable, Text, NullWritable,
                                       BSONWritable>(this.instance);
    }

    @Test
    public void testReduce() throws Exception {
        List<Pair<NullWritable, BSONWritable>> results =
                this.driver.withInput(new LongWritable(2L),
                                      asList(new Text("this\t192"))).run();
        assertEquals(1, results.size());
        Pair<NullWritable, BSONWritable> result = results.get(0);
        assertEquals("this", result.getSecond().get("word"));
        assertEquals(192L, result.getSecond().get("count"));
    }
}

@@ -667,34 +667,26 @@
 , Text, 
-NullWritable, BSON
+Text, Long
 Writable
@@ -851,75 +851,45 @@
 xt, 
-NullWritable,%0A                                       BSONWritable%3E(
+Text, LongWritable%3E(%0A                
 this
@@ -983,34 +983,26 @@
 st%3CPair%3C
-NullWritable, BSON
+Text, Long
 Writable
@@ -1208,26 +1208,18 @@
 air%3C
-NullWritable, BSON
+Text, Long
 Writ
@@ -1292,27 +1292,14 @@
 .get
-Second().get(%22word%22
+First(
 ));%0A
@@ -1347,21 +1347,8 @@
 nd()
-.get(%22count%22)
 );%0A 

Fix unit tests.