package eu.dnetlib.data.mapreduce.dedup;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.HashSet;

import org.junit.Test;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import eu.dnetlib.data.mapreduce.hbase.dedup.config.DedupConfig;
import eu.dnetlib.data.mapreduce.hbase.dedup.config.DedupConfigLoader;
import eu.dnetlib.data.proto.TypeProtos.Type;

public class DedupConfigTest {

	@Test
	public void testCfg1() {
		String s =
				"dedup.conf { " +
						"threshold = 0.99, " +
						"run = '001', " + 
						"entity.type = organization, " +
						"order.field = legalname, " +
						"ngram.fields = [legalname], " +
						"rootbuilder = [organization,projectOrganization,resultOrganization], " +
						"skiplist = [od_______908,od________18] }";

		final DedupConfig cfg = DedupConfigLoader.load(s);

		assertNotNull(cfg);
		assertTrue(cfg.getThreshold() == 0.99);
		assertTrue(cfg.getDedupRun().equals("001"));
		assertTrue(cfg.getEntityType().equals(Type.organization));
		assertTrue(cfg.getOrderField().equals("legalname"));
		assertTrue(Lists.newArrayList("organization", "projectOrganization", "resultOrganization").equals(cfg.getRootBuilderFamilies()));
		assertTrue(Sets.newHashSet("od_______908", "od________18").equals(cfg.getSkipList()));
	}
	
	@Test
	public void testCfg2() {
		String s =
				"dedup.conf { " +
						"threshold = 0.99, " +
						"run = '001', " + 
						"entity.type = organization, " +
						"order.field = legalname, " +
						"ngram.fields = [legalname], " +
						"rootbuilder = [organization,projectOrganization,resultOrganization] }";

		final DedupConfig cfg = DedupConfigLoader.load(s);

		assertNotNull(cfg);
		assertTrue(cfg.getThreshold() == 0.99);
		assertTrue(cfg.getEntityType().equals(Type.organization));
		assertTrue(cfg.getOrderField().equals("legalname"));
		assertTrue(Lists.newArrayList("organization", "projectOrganization", "resultOrganization").equals(cfg.getRootBuilderFamilies()));
		assertTrue(new HashSet<String>().equals(cfg.getSkipList()));
	}
	

}
