package eu.dnetlib.oai.mongo;

import java.io.StringReader;

import org.apache.commons.io.IOUtils;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;

/**
 * MetadataExtractor Tester.
 *
 * @author alessia
 * @version 1.0
 * @since
 *
 *        <pre>
 * Apr 6, 2016
 *        </pre>
 */
public class MetadataExtractorTest {

	final MetadataExtractor extractor = new MetadataExtractor();
	final SAXReader reader = new SAXReader();
	private Document doc;
	private final String filePath = "/eu/dnetlib/oai/mongo/testRecord.xml";

	@Before
	public void before() throws Exception {
		final String testRecord = IOUtils.toString(new ClassPathResource(this.filePath).getInputStream());
		this.doc = this.reader.read(new StringReader(testRecord));
	}

	@After
	public void after() throws Exception {}

	/**
	 * Method: evaluate(final Document xmlDoc)
	 */
	@Test
	public void testEvaluate() throws Exception {
		final long timeStart = System.currentTimeMillis();
		final String metadata = this.extractor.apply(this.doc);
		final long timeEnd = System.currentTimeMillis();
		System.out.println("Got metadata in ms " + (timeEnd - timeStart));
		System.out.println(metadata);
	}

}
