package eu.dnetlib.ariadneplus.workflows.nodes;
import eu.dnetlib.miscutils.functional.xml.SaxonHelper;
import net.sf.saxon.s9api.SaxonApiException;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
/**
* Created by Alessia Bardi on 13/04/2017.
*
* @author Alessia Bardi
*/
public class X3MTransformAriadnePlusJobNodeTest {
private X3MTransformAriadnePlusJobNode transformJob;
private String header = "\n"
+ " ariadne_mock::0000023f507999464aa2b78875b7e5d6\n"
+ " 2420500\n"
+ " 2017-04-10T18:44:46.85+02:00\n"
+ " ariadne_mock\n"
+ " Ariadne Mock\n"
+ " 2017-04-12T16:31:45.766\n"
+ " \n"
+ " \n"
+ " \n"
+ " ";
private String footer = "\n"
+ " \n"
+ " \n"
+ " sftp%3A%2F%2Fariadne2.isti.cnr.it%2F..%2F..%2Fdata%2Ftransform%2Facdm_correct\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " ";
private String metadata=" \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " CAIRN\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " HUT CIRCLE\n"
+ " \n"
+ " \n"
+ " ADS Terms and Conditions\n"
+ " \n"
+ " \n"
+ " SHEEPFOLD\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " FIELD SYSTEM\n"
+ " \n"
+ " \n"
+ " MID GLEN CROE\n"
+ " \n"
+ " \n"
+ " en\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " Sites and monuments databases or\n"
+ " inventories\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " 2013-12-09\n"
+ " 00:00:00.0\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " 2013-12-09\n"
+ " 00:00:00.0\n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " \n"
+ " BUILDING\n"
+ " \n"
+ " \n"
+ " 2420500\n"
+ " http://registry.ariadne-infrastructure.eu/collection/22721290\n"
+ " Multiple instances of: SHEEPFOLD<br /><br />Multiple\n"
+ " instances of: BUILDING<br />Multiple instances of: FIELD SYSTEM<br\n"
+ " />Possible instance of: CAIRN<br />Multiple instances of: HUT\n"
+ " CIRCLE<br />Possible instance of: HUT CIRCLE\n"
+ " \n"
+ " ";
@Before
public void setup() throws SaxonApiException {
transformJob = new X3MTransformAriadnePlusJobNode();
SaxonHelper saxonHelper = new SaxonHelper();
transformJob.setSaxonHelper(saxonHelper);
transformJob.prepareXpathSelectors();
}
@Test
public void testBuildXML(){
LocalDateTime now = LocalDateTime.now();
String res = transformJob.buildXML(header, now.toString(), metadata, footer);
LocalDateTime end = LocalDateTime.now();
System.out.println("Building XML took:"+ Duration.between(now, end).toMillis());
System.out.println(res);
}
@Test
public void testGetMetadataBlock() throws IOException, SaxonApiException {
String record = getString("/eu/dnetlib/x3m/dime-full.xml");
String md = transformJob.extractFromRecord(record, transformJob.getXpathSelectorMetadata());
System.out.println(md);
}
private String getString(final String classpath) throws IOException {
final ClassPathResource resource = new ClassPathResource(classpath);
return IOUtils.toString(resource.getInputStream(), "UTF-8");
}
}