Project

General

Profile

« Previous | Next » 

Revision 51045

ByPass QueryBuilder, otherwise the virtuoso pragma are not parsable

View differences:

modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoReadAPITest.java
1
package eu.dnetlib.parthenos.virtuoso;
2

  
3
import freemarker.template.Configuration;
4
import org.junit.Test;
5
import org.junit.runner.RunWith;
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
8
import org.springframework.boot.test.mock.mockito.MockBean;
9
import org.springframework.test.context.junit4.SpringRunner;
10
import org.springframework.test.web.servlet.MockMvc;
11

  
12
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
13
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
14

  
15
/**
16
 * Created by Alessia Bardi on 29/08/2017.
17
 *
18
 * @author Alessia Bardi
19
 */
20
@RunWith(SpringRunner.class)
21
@WebMvcTest(VirtuosoReadAPI.class)
22
public class VirtuosoReadAPITest {
23
	@Autowired
24
	private MockMvc mvc;
25

  
26
	@MockBean
27
	private Configuration freemarkerConfig;
28

  
29

  
30
	@Test
31
	public void testGetSubject() throws Exception {
32
		mvc.perform(get("/virtuoso/subject").param("subjectURL", "xxx")).andExpect(status().isOk());
33
	}
34

  
35
}
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/virtuoso/VirtuosoReadAPI.java
118 118
		//log.debug(describeQuery);
119 119
		//Can't use DESCRIBE query: server decides what to return (i.e. not all triples) and cannot find out if and how Virtuoso can be configured
120 120

  
121
		String q = "DEFINE input:inference 'parthenos_rules' CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
121
		String q = "DEFINE input:inference \'parthenos_rules\' CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o .}";
122 122
		//String q = "CONSTRUCT {<%s> ?p ?o . } WHERE { <%s> ?p ?o . }";
123 123
		String query = String.format(q, subjectURL, subjectURL, subjectURL, subjectURL);
124
		sendConstructResponse(QueryFactory.create(query), responseStream);
124
		sendConstructResponse(query, responseStream);
125 125

  
126 126
	}
127 127

  
......
137 137
		temp.process(values, sw);
138 138
		String q = sw.toString();
139 139
		log.debug("Running sparql query:\n"+q);
140
		sendConstructResponse(QueryFactory.create(q), responseStream);
140
		sendConstructResponse(q, responseStream);
141 141
	}
142 142

  
143 143

  
144
	protected void sendConstructResponse(final Query query, final OutputStream responseStream){
144
	protected void sendConstructResponse(final String query, final OutputStream responseStream){
145 145
		log.debug(query);
146 146
		final QueryEngineHTTP serviceRequest = new QueryEngineHTTP(sparqlUrl, query);
147 147
		Model resultModel = serviceRequest.execConstruct();
148 148
		RDFDataMgr.write(responseStream, resultModel, RDFFormat.RDFXML_PLAIN);
149
		resultModel.close();
149 150
		serviceRequest.close();
150

  
151 151
	}
152 152

  
153 153

  

Also available in: Unified diff