package org.devgateway.ocds.web.rest.controller.excelchart;

import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author idobre
 * @since 9/14/16
 */
public class ExcelChartHelperTest {
    private static Logger logger = Logger.getLogger(ExcelChartHelperTest.class);

    @Test
    public void getCategoriesValuesFromDBObject() throws Exception {
        final ExcelChartHelper excelChartHelper = new ExcelChartHelper();
        final List<DBObject> testDBObject = new ArrayList<>();
        testDBObject.add((DBObject) JSON.parse("{'yearTest': 2015, 'amountTest': 1000}"));
        testDBObject.add((DBObject) JSON.parse("{'yearTest': 2016, 'amountTest': 2000}"));
        testDBObject.add((DBObject) JSON.parse("{'yearTest': 2017}"));
        testDBObject.add((DBObject) JSON.parse("{'amountTest': 3000}"));


        final List<?> categories = excelChartHelper.getCategoriesFromDBObject("yearTest", testDBObject);
        Assert.assertArrayEquals(new Integer[] {2015, 2016, 2017},
                categories.toArray());

        final List<Number> values = excelChartHelper.getValuesFromDBObject(testDBObject,
                categories, "yearTest", "amountTest");
        Assert.assertArrayEquals(new Integer[] {1000, 2000, null},
                values.toArray());
    }
}

@@ -160,43 +160,229 @@
 org.
-junit.Assert;%0Aimport org.junit.Test
+devgateway.toolkit.web.AbstractWebTest;%0Aimport org.junit.Assert;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.cache.CacheManager
 ;%0A%0Ai
@@ -510,16 +510,40 @@
 perTest 
+extends AbstractWebTest 
 %7B%0A    pr
@@ -614,24 +614,355 @@
 st.class);%0A%0A
+    @Autowired%0A    private CacheManager cacheManager;%0A%0A    @Before%0A    public final void setUp() throws Exception %7B%0A        // clean the cache (we need this especially for endpoints cache)%0A        if (cacheManager != null) %7B%0A            cacheManager.getCacheNames().forEach(c -%3E cacheManager.getCache(c).clear());%0A        %7D%0A    %7D%0A%0A
     @Test%0A  

improve excel-chart-helper.