package eu.dnetlib.r2d2;

import static org.junit.Assert.*;

import java.util.List;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;

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

public class ScholarlynkImplTest {

	private ScholarlynkImpl server;

	@Before
	public void setUp() throws Exception {
		server = new ScholarlynkImpl();
	}

	@Test
	public void testToAdd() {
		Set<String> res = server.toAdd(Sets.newHashSet("A", "B", "C"), Sets.newHashSet("A", "B", "X"));
		System.out.println(res);
		
		assertEquals(1, res.size());
		assertTrue(res.contains("X"));
		
		Set<String> res2 = server.toAdd(Sets.newHashSet("X"), Sets.newHashSet("A", "B", "X"));
		assertEquals(2, res2.size());
		assertTrue(res2.contains("A"));
		assertTrue(res2.contains("B"));
	}

	@Test
	public void testToRemove() {
		Set<String> res = server.toRemove(Sets.newHashSet("A", "B", "C"), Sets.newHashSet("A", "B", "X"));
		System.out.println(res);
		
		assertEquals(1, res.size());
		assertTrue(res.contains("C"));
		
		Set<String> res2 = server.toRemove(Sets.newHashSet("X"), Sets.newHashSet("A", "B", "X"));
		assertEquals(0, res2.size());
	}
	
	@Test
	public void testParseTags() {
		
		List<String> tags = server.parseTags("wow #figata test #altra aa #\"quoted\" ss #\"other things\" xx");
		
		System.out.println("tags: " + tags);
		
		assertEquals(4, tags.size());
		assertEquals("figata", tags.get(0));
		assertEquals("altra", tags.get(1));
		assertEquals("quoted", tags.get(2));
		assertEquals("other things", tags.get(3));
		
	}
	
	@Test
	public void testHash() {
		String hash = server.hashPassword("xx");
		System.out.println("hash: " + hash);
	}
	
}
