77 lines
2.9 KiB
Java
77 lines
2.9 KiB
Java
package eu.dnetlib.ariadneplus.reader.json;
|
|
|
|
import eu.dnetlib.ariadneplus.reader.ResourceManager;
|
|
import eu.dnetlib.ariadneplus.reader.utils.PropertiesMap;
|
|
import net.minidev.json.parser.ParseException;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.junit.Assert;
|
|
import org.junit.Before;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import java.io.IOException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
public class ParseRDFJsonTest {
|
|
|
|
ParseRDFJSON parser;
|
|
ResourceManager mng;
|
|
String spec = getFromClasspath("eu/dnetlib/ariadneplus/reader/json/spec.json");
|
|
|
|
@Before
|
|
public void setup(){
|
|
parser = new ParseRDFJSON();
|
|
parser.setCatalogEntryCollectionJsonPath("$[*][?(@['https://www.ariadne-infrastructure.eu/property/resourceType'][0]['value']=='Dataset Collection')]");
|
|
parser.setCatalogEntryJsonPath("$[*][?(@['https://www.ariadne-infrastructure.eu/property/resourceType'][0]['value']=='provided record')]");
|
|
mng = new ResourceManager();
|
|
mng.setup("https://www.ariadne-infrastructure.eu/property/resourceType", "eu.dnetlib.ariadneplus.elasticsearch.model.",
|
|
"[\"https://www.ariadne-infrastructure.eu/property/resourceType\", \"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\"]",
|
|
spec);
|
|
}
|
|
|
|
@Test
|
|
public void testParseCollectionJson() throws ParseException {
|
|
String collectionJson = getFromClasspath("eu/dnetlib/ariadneplus/reader/json/collection.json");
|
|
parser.setCollection(true);
|
|
int res = parser.parse(collectionJson);
|
|
Assert.assertNotEquals(-1, res);
|
|
while(parser.hasNextElement()){
|
|
System.out.println(parser.getNextElement());
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testParseEmptyJson() throws ParseException {
|
|
String collectionJson = "{}";
|
|
parser.setCollection(true);
|
|
parser.parse(collectionJson);
|
|
int res = parser.parse(collectionJson);
|
|
Assert.assertEquals(-1, res);
|
|
while(parser.hasNextElement()){
|
|
System.out.println(parser.getNextElement());
|
|
}
|
|
}
|
|
|
|
@Test
|
|
|
|
public void testResourceManager() throws ParseException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
|
String collectionJson = getFromClasspath("eu/dnetlib/ariadneplus/reader/json/collection.json");
|
|
parser.setCollection(true);
|
|
int res = parser.parse(collectionJson);
|
|
Assert.assertNotEquals(-1, res);
|
|
mng.manage(parser);
|
|
if(mng.hasNext())
|
|
System.out.println(mng.next());
|
|
}
|
|
|
|
private String getFromClasspath(String s) {
|
|
try {
|
|
final ClassPathResource resource = new ClassPathResource(s);
|
|
return IOUtils.toString(resource.getInputStream(), "UTF-8");
|
|
}catch(IOException e){
|
|
return null;
|
|
}
|
|
}
|
|
}
|