package eu.dnetlib.data.collective.manager.log;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.Properties;

import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.store.LockObtainFailedException;
import org.junit.Before;
import org.junit.Test;

public class GenericInfoServiceTest {
	
	private transient String indexDirectory = "/tmp/testComments/testIndex";

	private transient GenericInfoService infoService;
	private transient String id1 = "id-1";
	private transient String comment1 = "This is the first comment.";
	private transient String id2 = "id-2";
	private transient String comment2 = "This is the second comment.";
	
	@Before
	public void setUp(){
		infoService = new GenericInfoService();
		infoService.setIndexDirectory(indexDirectory);
		infoService.init();
	}
	
	@Test
	public void testComment() throws CorruptIndexException, LockObtainFailedException, IOException{
		Properties props = new Properties();
		props.setProperty("comment", comment1);
		infoService.persist(id1, props);
		assertEquals(comment1, infoService.findProperties(id1).getProperty("comment"));
		props.setProperty("comment", comment1 + "some more words.");
		infoService.persist(id1, props);
		assertEquals(comment1 + "some more words.", infoService.findProperties(id1).getProperty("comment"));
		props.setProperty("comment", comment2);
		infoService.persist(id2, props);
		assertEquals(comment2, infoService.findProperties(id2).getProperty("comment"));
		assertEquals(comment1 + "some more words.", infoService.findProperties(id1).getProperty("comment"));
	}
}
