package eu.dnetlib.data.utils;

import java.io.IOException;

import javax.xml.bind.JAXBException;

import org.apache.commons.io.IOUtils;
import org.junit.Ignore;
import org.junit.Test;

import com.google.gson.JsonSyntaxException;

import eu.dnetlib.data.mdstore.plugins.objects.Author;
import eu.dnetlib.data.mdstore.plugins.objects.MdRecord;
import eu.dnetlib.data.mdstore.plugins.objects.MdRecordConvertUtils;

public class BibTexConverterTest {

	@Test
	@Ignore
	public void testAsBibTex_1() {

		final MdRecord record = new MdRecord();

		record.setId("1234");
		record.setTitle("The D-NET software toolkit A framework for the realization, maintenance, and operation of aggregative infrastructures");

		record.getCreators().add(new Author("Manghi P."));
		record.getCreators().add(new Author("Artini M."));

		record.setPublisher("Emerald, Bradford, Regno Unito");
		record.getDois().add("10.1108/PROG-08-2013-0045");
		record.setDate(2014);
		record.setSource("Program (Lond., 1966) 48 (2014): 322–354. doi:10.1108/PROG-08-2013-0045");
		record.setType("Journal article");

		final String bib = BibTexConverter.asBibTex(record);

		System.out.println(bib);

	}

	@Test
	@Ignore
	public void testAsBibTex_3() {

		final MdRecord record = new MdRecord();

		record.setId("oai:it.cnr:prodotti:462344");
		record.setTitle("Discriminating stress from cognitive load using contactless thermal imaging devices");

		record.getCreators().add(new Author("Gioia F."));
		record.getCreators().add(new Author("Pascali M. A."));

		record.setPublisher("IEEE, New York, USA");
		record.getDois().add("10.1109/embc46164.2021.9630860");
		record.setDate(2021);
		record.setSource(
				"EMBC 2021 - 43rd Annual International Conference of the IEEE Engineering in Medicine & Biology Society, pp. 608–611, Online Conference, 30/10/2021, 5/11/2021");
		record.setType("Conference article");

		final String bib = BibTexConverter.asBibTex(record);

		System.out.println(bib);

	}

	@Test
	@Ignore
	public void testAsBibTex_article_source_1() {

		final MdRecord record = new MdRecord();

		record.setId("1234");
		record.setType("Journal article");

		record.setSource("Internet of Things 13 (2020): 1–14");

		final String bib = BibTexConverter.asBibTex(record);

		System.out.println(bib);

	}

	@Test
	@Ignore
	public void testAsBibTex_file() throws JsonSyntaxException, IOException, JAXBException {

		final String xml = IOUtils.toString(getClass().getResourceAsStream("record.xml"));

		final MdRecord record = MdRecordConvertUtils.fromString(xml);

		final String bib = BibTexConverter.asBibTex(record);

		System.out.println(bib);

	}
}
