AriadnePlus/dnet-ariadneplus-publisher/test/main/java/eu/dnetlib/ariadneplus/virtuoso/FreeMarkerTest.java

44 lines
1.4 KiB
Java

package eu.dnetlib.ariadneplus.virtuoso;
import java.io.IOException;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Template;
import freemarker.template.TemplateExceptionHandler;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import static org.junit.Assert.assertNotNull;
/**
* Created by Alessia Bardi on 14/03/2018.
*
* @author Alessia Bardi
*/
@RunWith(JUnit4.class)
public class FreeMarkerTest {
@Test
public void testFreemarkTemplateLoading() throws IOException {
freemarker.template.Configuration config = new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_27);
ClassTemplateLoader ctl = new ClassTemplateLoader(getClass(), "/eu/dnetlib/ariadneplus/sparql");
config.setTemplateLoader(ctl);
config.setDefaultEncoding("UTF-8");
// Sets how errors will appear.
// During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER is better.
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// Don't log exceptions inside FreeMarker that it will thrown at you anyway:
config.setLogTemplateExceptions(false);
// Wrap unchecked exceptions thrown during template processing into TemplateException-s.
config.setWrapUncheckedExceptions(true);
String templateName = "E39_Actor.sparql";
Template temp = config.getTemplate(templateName);
assertNotNull(temp);
}
}