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.Test;
19
import org.junit.runner.RunWith;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.boot.test.context.SpringBootTest;
22
import org.springframework.core.io.ClassPathResource;
23
import org.springframework.test.context.TestPropertySource;
24
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
25

    
26
/**
27
 * Created by Alessia Bardi on 15/03/2018.
28
 *
29
 * @author Alessia Bardi
30
 */
31
//@Ignore
32
@RunWith(SpringJUnit4ClassRunner.class)
33
@SpringBootTest
34
@TestPropertySource(
35
		locations = "classpath:application-integrationtest.properties")
36
public class CatalogueRegistratorIntegrationTest {
37

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

    
42
	@Autowired
43
	private CatalogueRegistrator reg;
44
	private OntModel baseModel;
45

    
46

    
47

    
48
	@Before
49
	public void setup() {
50
		baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
51
		baseModel.read(getInputStream("eu/dnetlib/parthenos/rdfs/CRMpe.rdfs"), CRMpe.NS);
52
		baseModel.read(getInputStream("eu/dnetlib/parthenos/rdfs/CRMdig.rdfs"), CRMdig.NS);
53
		baseModel.read(getInputStream("eu/dnetlib/parthenos/rdfs/cidoc_crm_v6.2-draft-2015August.rdfs"), CRM.NS);
54
	}
55

    
56
	@Test
57
	public void testRegistration() throws Exception{
58
		InfModel model = loadBaseModel();
59
		model.read(getStream(nakalaService), CRMpe.NS);
60
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
61
		Resource nakala = subjects.nextResource();
62
		String uuid = reg.register(nakala, CRMpe.PE1_Service, "Huma-Num - Nakala");
63
		System.out.println(uuid);
64
		purge(uuid);
65
	}
66

    
67
	@Test
68
	public void testError500_1() throws Exception{
69
		InfModel model = loadBaseModel();
70
		model.read(getStream(error500_1), CRMpe.NS);
71
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E29_Design_or_Procedure);
72
		Resource r = subjects.nextResource();
73
		String uuid = reg.register(r, CRM.E29_Design_or_Procedure, "PARTHENOS");
74
		System.out.println(uuid);
75
		purge(uuid);
76
	}
77

    
78
	@Test
79
	public void testPurge() throws IOException, URISyntaxException {
80
		reg.purge(resourceCatName);
81
	}
82

    
83
	private void purge(final String uuid) throws IOException, URISyntaxException {
84
		reg.purge(uuid);
85
	}
86

    
87
	private static InputStream getStream(final String classpath) throws IOException {
88
		return new ClassPathResource(classpath).getInputStream();
89
	}
90

    
91
	protected InfModel loadBaseModel() {
92
		return ModelFactory.createRDFSModel(baseModel);
93
	}
94

    
95
	private InputStream getInputStream(String classpath){
96
		try {
97
			final ClassPathResource resource = new ClassPathResource(classpath);
98
			return resource.getInputStream();
99
		}catch(IOException e){
100
			return null;
101
		}
102
	}
103
}
(2-2/3)