Project

General

Profile

« Previous | Next » 

Revision 51432

Registering providers as catalogue groups

View differences:

CatalogueRegistratorIntegrationTest.java
7 7
import eu.dnetlib.parthenos.CRM;
8 8
import eu.dnetlib.parthenos.CRMdig;
9 9
import eu.dnetlib.parthenos.CRMpe;
10
import org.apache.commons.io.IOUtils;
10
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
11 11
import org.apache.commons.lang3.StringUtils;
12 12
import org.apache.jena.ontology.OntModel;
13 13
import org.apache.jena.ontology.OntModelSpec;
......
27 27
import org.springframework.test.context.TestPropertySource;
28 28
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
29 29

  
30
import static org.junit.Assert.assertFalse;
31
import static org.junit.Assert.assertTrue;
32

  
30 33
/**
31 34
 * Created by Alessia Bardi on 15/03/2018.
32 35
 *
......
41 44

  
42 45
	private String nakalaService = "eu/dnetlib/parthenos/registry/nakala.rdf";
43 46
	private String resourceCatName = "nakalatest";
47

  
48
	private String rdfWithProviders = "eu/dnetlib/parthenos/registry/withProviders.rdf";
44 49
	private boolean doPurge=false;
45 50

  
46 51
	@Autowired
......
66 71

  
67 72
	@Test
68 73
	public void testRegistration() throws Exception{
69
		String resource = getString(nakalaService);
70 74
		InfModel model = loadBaseModel();
71
		model.read(IOUtils.toInputStream(resource, "UTF-8"), CRMpe.NS);
75
		model.read(getStream(nakalaService), CRMpe.NS);
72 76
		ResIterator subjects = model.listSubjectsWithProperty(RDF.type, CRM.E7_Activity);
73 77
		Resource nakala = subjects.nextResource();
74 78
		String uuid = reg.register(nakala, CRM.E7_Activity);
......
82 86
		doPurge = false;
83 87
	}
84 88

  
89
	@Test
90
	public void testAddGroup() throws IOException, URISyntaxException, ParthenosPublisherException {
91
		InfModel model = loadBaseModel();
92
		model.read(getStream(rdfWithProviders), CRMpe.NS);
93
		ResIterator it = model.listSubjectsWithProperty(CRMpe.PP2_provided_by);
94
		while(it.hasNext()){
95
			Resource withProvider = it.nextResource();
96
			reg.ensureGroups(withProvider);
97
		}
98
		doPurge = false;
85 99

  
86
	private String getString(final String classpath) {
87
		try {
88
			final ClassPathResource resource = new ClassPathResource(classpath);
89
			return IOUtils.toString(resource.getInputStream(), "UTF-8");
90
		}catch(IOException e){
91
			return null;
92
		}
93 100
	}
94 101

  
102
	@Test
103
	public void testGroup() throws ParthenosPublisherException, IOException, URISyntaxException {
104
		assertFalse(reg.getCatalogueAPIClient().groupExist("sismeltest"));
105
		String sismelJson = "{"
106
				+ "  \"name\":\"sismeltest\","
107
				+ "  \"id\":\"sismeltest\","
108
				+ "  \"title\": \"SISMEL TEST GROUP TITLE\""
109
				//+ "  \"description\": \"%s\""
110
				+ "}";
111
		reg.getCatalogueAPIClient().registerGroup(sismelJson, "sismeltest");
112
		assertTrue(reg.getCatalogueAPIClient().groupExist("sismeltest"));
113
		reg.getCatalogueAPIClient().purgeGroup("sismeltest");
114
		assertFalse(reg.getCatalogueAPIClient().groupExist("sismeltest"));
115
	}
116

  
95 117
	private static InputStream getStream(final String classpath) throws IOException {
96 118
		return new ClassPathResource(classpath).getInputStream();
97 119
	}

Also available in: Unified diff