Revision 51244
Added by Alessia Bardi about 6 years ago
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/virtuoso/FreeMarkerTest.java | ||
---|---|---|
1 |
package eu.dnetlib.parthenos.virtuoso; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import freemarker.cache.ClassTemplateLoader; |
|
6 |
import freemarker.template.Template; |
|
7 |
import freemarker.template.TemplateExceptionHandler; |
|
8 |
import org.junit.Test; |
|
9 |
|
|
10 |
import static org.junit.Assert.assertNotNull; |
|
11 |
|
|
12 |
/** |
|
13 |
* Created by Alessia Bardi on 14/03/2018. |
|
14 |
* |
|
15 |
* @author Alessia Bardi |
|
16 |
*/ |
|
17 |
public class FreeMarkerTest { |
|
18 |
|
|
19 |
@Test |
|
20 |
public void testFreemarkTemplateLoading() throws IOException { |
|
21 |
|
|
22 |
freemarker.template.Configuration config = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_27); |
|
23 |
ClassTemplateLoader ctl = new ClassTemplateLoader(getClass(), "/eu/dnetlib/parthenos/sparql"); |
|
24 |
config.setTemplateLoader(ctl); |
|
25 |
config.setDefaultEncoding("UTF-8"); |
|
26 |
// Sets how errors will appear. |
|
27 |
// During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER is better. |
|
28 |
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); |
|
29 |
|
|
30 |
// Don't log exceptions inside FreeMarker that it will thrown at you anyway: |
|
31 |
config.setLogTemplateExceptions(false); |
|
32 |
|
|
33 |
// Wrap unchecked exceptions thrown during template processing into TemplateException-s. |
|
34 |
config.setWrapUncheckedExceptions(true); |
|
35 |
|
|
36 |
|
|
37 |
String templateName = "E39_Actor_test.sparql"; |
|
38 |
Template temp = config.getTemplate(templateName); |
|
39 |
assertNotNull(temp); |
|
40 |
} |
|
41 |
} |
modules/dnet-parthenos-publisher/trunk/test/main/resources/eu/dnetlib/parthenos/sparql/E39_Actor_test.sparql | ||
---|---|---|
1 |
# TODO: |
|
2 |
# 1. Complete retrieved information |
|
3 |
# 2. Title can be a literal |
|
4 |
|
|
5 |
DEFINE input:inference 'parthenos_rules' |
|
6 |
|
|
7 |
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> |
|
8 |
PREFIX crmdig: <http://www.ics.forth.gr/isl/CRMdig/> |
|
9 |
PREFIX crmpe: <http://parthenos.d4science.org/CRMext/CRMpe.rdfs/> |
|
10 |
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
|
11 |
|
|
12 |
CONSTRUCT { |
|
13 |
<${subjectURL}> crm:P1_is_identified_by ?title . |
|
14 |
<${subjectURL}> crm:P3_has_note ?description . |
|
15 |
<${subjectURL}> a ?type . |
|
16 |
<${subjectURL}> crm:P76_has_contact_point ?contactpoint . |
|
17 |
?contactpoint crm:P2_has_type ?contactpointType . |
|
18 |
?contactpoint rdfs:label ?contactpointLabel . |
|
19 |
?contactpointType rdfs:label ?contactpointTypeLabel . |
|
20 |
} |
|
21 |
WHERE { |
|
22 |
<${subjectURL}> a crm:E39_Actor . |
|
23 |
<${subjectURL}> a ?type . |
|
24 |
OPTIONAL{ |
|
25 |
<${subjectURL}> crm:P1_is_identified_by ?titleRes . |
|
26 |
?titleRes rdfs:label ?title . |
|
27 |
} |
|
28 |
OPTIONAL{ |
|
29 |
<${subjectURL}> crm:P3_has_note ?description . |
|
30 |
} |
|
31 |
OPTIONAL{ |
|
32 |
<${subjectURL}> crm:P76_has_contact_point ?contactpoint . |
|
33 |
?contactpoint rdfs:label ?contactpointLabel . |
|
34 |
} |
|
35 |
OPTIONAL{ |
|
36 |
<${subjectURL}> crm:P76_has_contact_point ?contactpoint . |
|
37 |
?contactpoint crm:P2_has_type ?contactpointType . |
|
38 |
?contactpointType rdfs:label ?contactpointTypeLabel . |
|
39 |
} |
|
40 |
} |
Also available in: Unified diff
testing template loading