1 |
51291
|
alessia.ba
|
package eu.dnetlib.parthenos.catalogue;
|
2 |
|
|
|
3 |
|
|
import java.io.IOException;
|
4 |
|
|
import java.io.InputStream;
|
5 |
51319
|
alessia.ba
|
import java.net.URISyntaxException;
|
6 |
51291
|
alessia.ba
|
|
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 |
51619
|
alessia.ba
|
import org.junit.Ignore;
|
19 |
51291
|
alessia.ba
|
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 |
51619
|
alessia.ba
|
@Ignore
|
33 |
51291
|
alessia.ba
|
@RunWith(SpringJUnit4ClassRunner.class)
|
34 |
|
|
@SpringBootTest
|
35 |
|
|
@TestPropertySource(
|
36 |
|
|
locations = "classpath:application-integrationtest.properties")
|
37 |
|
|
public class CatalogueRegistratorIntegrationTest {
|
38 |
|
|
|
39 |
|
|
private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
|
40 |
51319
|
alessia.ba
|
private String resourceCatName = "nakalatest";
|
41 |
51432
|
alessia.ba
|
|
42 |
52851
|
alessia.ba
|
//private String rdfWithProviders = "eu/dnetlib/parthenos/registry/withProviders.rdf";
|
43 |
51502
|
alessia.ba
|
|
44 |
|
|
private String error500_1 = "eu/dnetlib/parthenos/registry/error500_1.rdf";
|
45 |
52851
|
alessia.ba
|
//private String serviceSample = "eu/dnetlib/parthenos/registry/PE1_Service_sample.rdf";
|
46 |
51291
|
alessia.ba
|
|
47 |
|
|
@Autowired
|
48 |
|
|
private CatalogueRegistrator reg;
|
49 |
|
|
private OntModel baseModel;
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
@Before
|
54 |
|
|
public void setup() {
|
55 |
|
|
baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
|
56 |
|
|
baseModel.read(CRMpe.RDFS_URL);
|
57 |
|
|
baseModel.read(CRM.RDFS_URL);
|
58 |
|
|
baseModel.read(CRMdig.RDFS_URL);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
@Test
|
62 |
|
|
public void testRegistration() throws Exception{
|
63 |
|
|
InfModel model = loadBaseModel();
|
64 |
51432
|
alessia.ba
|
model.read(getStream(nakalaService), CRMpe.NS);
|
65 |
51291
|
alessia.ba
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
|
66 |
|
|
Resource nakala = subjects.nextResource();
|
67 |
52851
|
alessia.ba
|
String uuid = reg.register(nakala, CRM.E7_Activity, CKANUtils.nakala_org);
|
68 |
51291
|
alessia.ba
|
System.out.println(uuid);
|
69 |
51502
|
alessia.ba
|
purge(uuid);
|
70 |
51291
|
alessia.ba
|
}
|
71 |
|
|
|
72 |
51321
|
alessia.ba
|
@Test
|
73 |
51502
|
alessia.ba
|
public void testError500_1() throws Exception{
|
74 |
|
|
InfModel model = loadBaseModel();
|
75 |
|
|
model.read(getStream(error500_1), CRMpe.NS);
|
76 |
|
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E29_Design_or_Procedure);
|
77 |
|
|
Resource r = subjects.nextResource();
|
78 |
52851
|
alessia.ba
|
String uuid = reg.register(r, CRM.E29_Design_or_Procedure, CKANUtils.Parthenos_org);
|
79 |
51502
|
alessia.ba
|
System.out.println(uuid);
|
80 |
|
|
purge(uuid);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
@Test
|
84 |
51321
|
alessia.ba
|
public void testPurge() throws IOException, URISyntaxException {
|
85 |
|
|
reg.purge(resourceCatName);
|
86 |
|
|
}
|
87 |
51319
|
alessia.ba
|
|
88 |
51502
|
alessia.ba
|
private void purge(final String uuid) throws IOException, URISyntaxException {
|
89 |
|
|
reg.purge(uuid);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
51291
|
alessia.ba
|
private static InputStream getStream(final String classpath) throws IOException {
|
93 |
|
|
return new ClassPathResource(classpath).getInputStream();
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
protected InfModel loadBaseModel() {
|
97 |
|
|
return ModelFactory.createRDFSModel(baseModel);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
}
|