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 eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
|
11
|
import org.apache.jena.ontology.OntModel;
|
12
|
import org.apache.jena.ontology.OntModelSpec;
|
13
|
import org.apache.jena.rdf.model.InfModel;
|
14
|
import org.apache.jena.rdf.model.ModelFactory;
|
15
|
import org.apache.jena.rdf.model.ResIterator;
|
16
|
import org.apache.jena.rdf.model.Resource;
|
17
|
import org.apache.jena.vocabulary.RDF;
|
18
|
import org.junit.Before;
|
19
|
import org.junit.Ignore;
|
20
|
import org.junit.Test;
|
21
|
import org.junit.runner.RunWith;
|
22
|
import org.springframework.beans.factory.annotation.Autowired;
|
23
|
import org.springframework.boot.test.context.SpringBootTest;
|
24
|
import org.springframework.core.io.ClassPathResource;
|
25
|
import org.springframework.test.context.TestPropertySource;
|
26
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
27
|
|
28
|
import static org.junit.Assert.assertFalse;
|
29
|
import static org.junit.Assert.assertTrue;
|
30
|
|
31
|
/**
|
32
|
* Created by Alessia Bardi on 15/03/2018.
|
33
|
*
|
34
|
* @author Alessia Bardi
|
35
|
*/
|
36
|
@Ignore
|
37
|
@RunWith(SpringJUnit4ClassRunner.class)
|
38
|
@SpringBootTest
|
39
|
@TestPropertySource(
|
40
|
locations = "classpath:application-integrationtest.properties")
|
41
|
public class CatalogueRegistratorIntegrationTest {
|
42
|
|
43
|
private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
|
44
|
private String resourceCatName = "nakalatest";
|
45
|
|
46
|
private String rdfWithProviders = "eu/dnetlib/parthenos/registry/withProviders.rdf";
|
47
|
|
48
|
private String error500_1 = "eu/dnetlib/parthenos/registry/error500_1.rdf";
|
49
|
private String serviceSample = "eu/dnetlib/parthenos/registry/PE1_Service_sample.rdf";
|
50
|
private boolean doPurge=false;
|
51
|
|
52
|
@Autowired
|
53
|
private CatalogueRegistrator reg;
|
54
|
private OntModel baseModel;
|
55
|
|
56
|
|
57
|
|
58
|
@Before
|
59
|
public void setup() {
|
60
|
baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
|
61
|
baseModel.read(CRMpe.RDFS_URL);
|
62
|
baseModel.read(CRM.RDFS_URL);
|
63
|
baseModel.read(CRMdig.RDFS_URL);
|
64
|
}
|
65
|
|
66
|
@Test
|
67
|
public void testRegistration() throws Exception{
|
68
|
InfModel model = loadBaseModel();
|
69
|
model.read(getStream(nakalaService), CRMpe.NS);
|
70
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
|
71
|
Resource nakala = subjects.nextResource();
|
72
|
String uuid = reg.register(nakala, CRM.E7_Activity, "testGroup");
|
73
|
System.out.println(uuid);
|
74
|
purge(uuid);
|
75
|
}
|
76
|
|
77
|
@Test
|
78
|
public void testError500_1() throws Exception{
|
79
|
InfModel model = loadBaseModel();
|
80
|
model.read(getStream(error500_1), CRMpe.NS);
|
81
|
ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E29_Design_or_Procedure);
|
82
|
Resource r = subjects.nextResource();
|
83
|
String uuid = reg.register(r, CRM.E29_Design_or_Procedure, "testGroup");
|
84
|
System.out.println(uuid);
|
85
|
purge(uuid);
|
86
|
}
|
87
|
|
88
|
@Test
|
89
|
public void testPurge() throws IOException, URISyntaxException {
|
90
|
reg.purge(resourceCatName);
|
91
|
}
|
92
|
|
93
|
// @Test
|
94
|
// public void testAddGroup() throws IOException, URISyntaxException, ParthenosPublisherException {
|
95
|
// InfModel model = loadBaseModel();
|
96
|
// model.read(getStream(rdfWithProviders), CRMpe.NS);
|
97
|
// ResIterator it = model.listSubjectsWithProperty(CRMpe.PP2_provided_by);
|
98
|
// while(it.hasNext()){
|
99
|
// Resource withProvider = it.nextResource();
|
100
|
// reg.ensureGroups(withProvider);
|
101
|
// }
|
102
|
// reg.getCatalogueAPIClient().purgeGroup("SISMEL");
|
103
|
// reg.getCatalogueAPIClient().purgeGroup("EHRI Consortium");
|
104
|
// }
|
105
|
//
|
106
|
// @Test
|
107
|
// public void testAddGroup2() throws IOException, URISyntaxException, ParthenosPublisherException {
|
108
|
// InfModel model = loadBaseModel();
|
109
|
// model.read(getStream(serviceSample), CRMpe.NS);
|
110
|
// Resource subject = model.getResource("http://parthenos.d4science.org/handle/CP/Service/TEST");
|
111
|
// Iterator<String> providers = reg.getResourceReader().getProviderNames(subject);
|
112
|
// reg.ensureGroups(subject);
|
113
|
// while(providers.hasNext()){
|
114
|
// String p = providers.next();
|
115
|
// System.out.println("purging group "+p);
|
116
|
// reg.getCatalogueAPIClient().purgeGroup(p);
|
117
|
// }
|
118
|
// }
|
119
|
|
120
|
@Test
|
121
|
public void testGroup() throws ParthenosPublisherException, IOException, URISyntaxException {
|
122
|
assertFalse(reg.getCatalogueAPIClient().groupExist("sismeltest"));
|
123
|
String sismelJson = "{"
|
124
|
+ " \"name\":\"sismeltest\","
|
125
|
+ " \"id\":\"sismeltest\","
|
126
|
+ " \"title\": \"SISMEL TEST GROUP TITLE\""
|
127
|
//+ " \"description\": \"%s\""
|
128
|
+ "}";
|
129
|
reg.getCatalogueAPIClient().registerGroup(sismelJson, "sismeltest");
|
130
|
assertTrue(reg.getCatalogueAPIClient().groupExist("sismeltest"));
|
131
|
reg.getCatalogueAPIClient().purgeGroup("sismeltest");
|
132
|
assertFalse(reg.getCatalogueAPIClient().groupExist("sismeltest"));
|
133
|
}
|
134
|
|
135
|
private void purge(final String uuid) throws IOException, URISyntaxException {
|
136
|
reg.purge(uuid);
|
137
|
}
|
138
|
|
139
|
private static InputStream getStream(final String classpath) throws IOException {
|
140
|
return new ClassPathResource(classpath).getInputStream();
|
141
|
}
|
142
|
|
143
|
protected InfModel loadBaseModel() {
|
144
|
return ModelFactory.createRDFSModel(baseModel);
|
145
|
}
|
146
|
|
147
|
}
|