1
|
package eu.dnetlib.parthenos.catalogue;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.InputStream;
|
5
|
import java.net.URISyntaxException;
|
6
|
|
7
|
import eu.dnetlib.parthenos.CRM;
|
8
|
import eu.dnetlib.parthenos.CRMdig;
|
9
|
import eu.dnetlib.parthenos.CRMpe;
|
10
|
import org.apache.jena.ontology.OntModel;
|
11
|
import org.apache.jena.ontology.OntModelSpec;
|
12
|
import org.apache.jena.rdf.model.InfModel;
|
13
|
import org.apache.jena.rdf.model.ModelFactory;
|
14
|
import org.apache.jena.rdf.model.ResIterator;
|
15
|
import org.apache.jena.rdf.model.Resource;
|
16
|
import org.apache.jena.vocabulary.RDF;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
import org.junit.runner.RunWith;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.boot.test.context.SpringBootTest;
|
23
|
import org.springframework.core.io.ClassPathResource;
|
24
|
import org.springframework.test.context.TestPropertySource;
|
25
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
26
|
|
27
|
/**
|
28
|
* Created by Alessia Bardi on 15/03/2018.
|
29
|
*
|
30
|
* @author Alessia Bardi
|
31
|
*/
|
32
|
//@Ignore
|
33
|
@RunWith(SpringJUnit4ClassRunner.class)
|
34
|
@SpringBootTest
|
35
|
@TestPropertySource(
|
36
|
locations = "classpath:application-integrationtest.properties")
|
37
|
@Ignore
|
38
|
public class CatalogueRegistratorIntegrationTest {
|
39
|
|
40
|
private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
|
41
|
private String resourceCatName = "nakalatest";
|
42
|
private String error500_1 = "eu/dnetlib/parthenos/registry/error500_1.rdf";
|
43
|
|
44
|
@Autowired
|
45
|
private CatalogueRegistrator reg;
|
46
|
private OntModel baseModel;
|
47
|
|
48
|
|
49
|
|
50
|
@Before
|
51
|
public void setup() {
|
52
|
baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
|
53
|
baseModel.read(getInputStream("eu/dnetlib/parthenos/rdfs/CRMpe.rdfs"), CRMpe.NS);
|
54
|
baseModel.read(getInputStream("eu/dnetlib/parthenos/rdfs/CRMdig.rdfs"), CRMdig.NS);
|
55
|
baseModel.read(getInputStream("eu/dnetlib/parthenos/rdfs/cidoc_crm_v6.2-draft-2015August.rdfs"), CRM.NS);
|
56
|
}
|
57
|
|
58
|
@Test
|
59
|
public void testRegistration() throws Exception{
|
60
|
InfModel model = loadBaseModel();
|
61
|
model.read(getStream(nakalaService), CRMpe.NS);
|
62
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
|
63
|
Resource nakala = subjects.nextResource();
|
64
|
String uuid = reg.register(nakala, CRMpe.PE1_Service, "Huma-Num - Nakala");
|
65
|
System.out.println(uuid);
|
66
|
purge(uuid);
|
67
|
}
|
68
|
|
69
|
@Test
|
70
|
public void testError500_1() throws Exception {
|
71
|
InfModel model = loadBaseModel();
|
72
|
model.read(getStream(error500_1), CRMpe.NS);
|
73
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E29_Design_or_Procedure);
|
74
|
Resource r = subjects.nextResource();
|
75
|
String uuid = reg.register(r, CRM.E29_Design_or_Procedure, "PARTHENOS");
|
76
|
System.out.println(uuid);
|
77
|
purge(uuid);
|
78
|
}
|
79
|
|
80
|
@Test
|
81
|
public void testPurge() throws IOException, URISyntaxException {
|
82
|
reg.purge(resourceCatName);
|
83
|
}
|
84
|
|
85
|
private void purge(final String uuid) throws IOException, URISyntaxException {
|
86
|
reg.purge(uuid);
|
87
|
}
|
88
|
|
89
|
private static InputStream getStream(final String classpath) throws IOException {
|
90
|
return new ClassPathResource(classpath).getInputStream();
|
91
|
}
|
92
|
|
93
|
protected InfModel loadBaseModel() {
|
94
|
return ModelFactory.createRDFSModel(baseModel);
|
95
|
}
|
96
|
|
97
|
private InputStream getInputStream(String classpath){
|
98
|
try {
|
99
|
final ClassPathResource resource = new ClassPathResource(classpath);
|
100
|
return resource.getInputStream();
|
101
|
}catch(IOException e){
|
102
|
return null;
|
103
|
}
|
104
|
}
|
105
|
}
|