package com.goree.api.controller;

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

import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.goree.api.domain.Tag;
import com.goree.api.util.IDataSetFactory;
import com.goree.api.util.TestWithDBUnit;

public class TagSearchTest extends TestWithDBUnit{
    @Autowired
    private TagController tagController;
    
    private List<Tag> expecteds;

    @Override
    public String getDatasetFilePath() {
        return "src/test/resources/testdataset/tag_search_test.xml";
    }
    
    @Override
    @Before
    public void setUp() {
        super.setUp();
               
        expecteds = new ArrayList<>();
        IDataSet dataSet = IDataSetFactory.fromXml(getDatasetFilePath());
        try {
            ITable itable = dataSet.getTable("tag");
            for(int i = 0; i < itable.getRowCount() ; i++){
                Tag tag = new Tag();
                tag.setId(Integer.parseInt((String)itable.getValue(i, "tag_id")));
                tag.setTagName((String)itable.getValue(i, "tag_name"));
                expecteds.add(tag);
            }
        } catch (DataSetException e) {
            throw new RuntimeException(e);
        }
    }
    
    @Test
    public void searchTagsByStartWord() throws Exception{
        List<Tag> actuals = tagController.searchTagsByStartWord("Search");
        Assert.assertTrue(actuals.containsAll(expecteds));
    }
    
    @Test
    public void searchTagsByStartWordOrdered() {
        expecteds.sort(new Comparator<Tag>() {
            @Override
            public int compare(Tag o1, Tag o2) {
                return o2.getCount() - o1.getCount();
            }
        });
        
        List<Tag> actuals = tagController.searchTagsByStartWord("Search");
        for(int i = 0 ; i < expecteds.size(); i++){
            Assert.assertEquals(expecteds.get(i), actuals.get(i));
        }
    }
}

@@ -1712,215 +1712,8 @@
 ) %7B%0A
-        expecteds.sort(new Comparator%3CTag%3E() %7B%0A            @Override%0A            public int compare(Tag o1, Tag o2) %7B%0A                return o2.getCount() - o1.getCount();%0A            %7D%0A        %7D);%0A        %0A
     

fix sort mistake...