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
@RunWith(SpringJUnit4ClassRunner.class)
33
@SpringBootTest
34
@TestPropertySource(
35
		locations = "classpath:application-integrationtest.properties")
36
@Ignore
37
public class CatalogueRegistratorIntegrationTest {
38

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

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

    
47

    
48

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

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

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

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

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

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

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

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