Project

General

Profile

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
public class CatalogueRegistratorIntegrationTest {
38

    
39
	private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
40
	private String resourceCatName = "nakalatest";
41

    
42
	//private String rdfWithProviders = "eu/dnetlib/parthenos/registry/withProviders.rdf";
43

    
44
	private String error500_1 = "eu/dnetlib/parthenos/registry/error500_1.rdf";
45
	//private String serviceSample = "eu/dnetlib/parthenos/registry/PE1_Service_sample.rdf";
46

    
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
		model.read(getStream(nakalaService), CRMpe.NS);
65
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
66
		Resource nakala = subjects.nextResource();
67
		String uuid = reg.register(nakala, CRM.E7_Activity, CKANUtils.nakala_org);
68
		System.out.println(uuid);
69
		purge(uuid);
70
	}
71

    
72
	@Test
73
	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
		String uuid = reg.register(r, CRM.E29_Design_or_Procedure, CKANUtils.Parthenos_org);
79
		System.out.println(uuid);
80
		purge(uuid);
81
	}
82

    
83
	@Test
84
	public void testPurge() throws IOException, URISyntaxException {
85
		reg.purge(resourceCatName);
86
	}
87

    
88
	private void purge(final String uuid) throws IOException, URISyntaxException {
89
		reg.purge(uuid);
90
	}
91

    
92
	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
}
(2-2/3)