1
|
package eu.dnetlib.parthenos.registry;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.InputStream;
|
5
|
import java.io.StringWriter;
|
6
|
|
7
|
import com.fasterxml.jackson.core.JsonFactory;
|
8
|
import com.fasterxml.jackson.core.JsonGenerator;
|
9
|
import eu.dnetlib.parthenos.CRMpe;
|
10
|
import org.apache.jena.rdf.model.Model;
|
11
|
import org.apache.jena.rdf.model.ResIterator;
|
12
|
import org.apache.jena.rdf.model.Resource;
|
13
|
import org.apache.jena.vocabulary.RDF;
|
14
|
import org.junit.Assert;
|
15
|
import org.junit.Test;
|
16
|
import org.springframework.core.io.ClassPathResource;
|
17
|
|
18
|
/**
|
19
|
* Created by Alessia Bardi on 02/10/2017.
|
20
|
*
|
21
|
* @author Alessia Bardi
|
22
|
*/
|
23
|
public class FacetWriterTest {
|
24
|
|
25
|
private FacetWriter facetWriter = new FacetWriter();
|
26
|
private static String baseURI = "http://parthenos.d4science.org/CRMext/CRMpe.rdfs/";
|
27
|
/**
|
28
|
*
|
29
|
* Method: writeIdentifierFacet(final JsonGenerator jg, final String identifier)
|
30
|
*
|
31
|
*/
|
32
|
@Test
|
33
|
public void testWriteIdentifierFacet() throws Exception {
|
34
|
JsonFactory jsonFactory = new JsonFactory();
|
35
|
StringWriter sw = new StringWriter();
|
36
|
JsonGenerator jg = jsonFactory.createGenerator(sw);
|
37
|
facetWriter.writeIdentifierFacet(jg, "thisIsAnIDentifier");
|
38
|
jg.close();
|
39
|
System.out.println(sw.toString());
|
40
|
Assert.assertEquals("{\"@class\":\"P1_is_identified_by\",\"target\":{\"@class\":\"IdentifierFacet\",\"value\":\"thisIsAnIDentifier\",\"type\":\"URI\"}}", sw.toString());
|
41
|
}
|
42
|
|
43
|
|
44
|
/**
|
45
|
*
|
46
|
* Method: writeContactReferenceFacet(final JsonGenerator jg, final Resource resource)
|
47
|
*
|
48
|
*/
|
49
|
@Test
|
50
|
public void testWriteContactReferenceFacet() throws Exception {
|
51
|
GCubeResourceGenerator generator = new GCubeResourceGenerator();
|
52
|
JsonFactory jsonFactory = new JsonFactory();
|
53
|
StringWriter sw = new StringWriter();
|
54
|
JsonGenerator jg = jsonFactory.createGenerator(sw);
|
55
|
Model model = generator.loadBaseModel();
|
56
|
model.read(getStream("eu/dnetlib/parthenos/registry/test.rdf"), baseURI);
|
57
|
ResIterator iter = model.listResourcesWithProperty(RDF.type, CRMpe.PE1_Service);
|
58
|
if(iter.hasNext()){
|
59
|
Resource r = iter.nextResource();
|
60
|
System.out.println("Found service "+r.getURI());
|
61
|
facetWriter.writeContactReferenceFacet(jg, r);
|
62
|
jg.close();
|
63
|
System.out.println(sw.toString());
|
64
|
}
|
65
|
else {
|
66
|
System.out.println("Could not find any service");
|
67
|
throw new Exception("I was expecting some PE1_Service or subclass instances!");
|
68
|
}
|
69
|
}
|
70
|
|
71
|
|
72
|
private InputStream getStream(final String classpath) throws IOException {
|
73
|
return new ClassPathResource(classpath).getInputStream();
|
74
|
}
|
75
|
|
76
|
}
|