use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.
the class WebEngineContextTest method test14.
@Test
public void test14() {
final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
final Map<String, Object> requestAttributes = new LinkedHashMap<String, Object>();
final Map<String, Object[]> requestParameters = new LinkedHashMap<String, Object[]>();
final HttpServletRequest mockRequest = TestMockServletUtil.createHttpServletRequest("WebVariablesMap", null, requestAttributes, requestParameters, LOCALE);
final HttpServletResponse mockResponse = TestMockServletUtil.createHttpServletResponse();
final Map<String, Object> servletContextAttributes = new LinkedHashMap<String, Object>();
final ServletContext mockServletContext = TestMockServletUtil.createServletContext(servletContextAttributes);
final WebEngineContext vm = new WebEngineContext(configuration, templateData1, null, mockRequest, mockResponse, mockServletContext, LOCALE, null);
/*
* Note WebEngineContext works in a different way to EngineContext because it is based on the
* HttpServletRequest, and the request considers setting an attribute to null the exact same thing as
* removing it.
*/
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertNull(vm.getVariable("one"));
vm.setVariable("one", null);
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertNull(vm.getVariable("one"));
vm.setVariable("one", "a value");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("a value", vm.getVariable("one"));
vm.increaseLevel();
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("a value", vm.getVariable("one"));
vm.setVariable("one", null);
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertNull(vm.getVariable("one"));
vm.decreaseLevel();
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("a value", vm.getVariable("one"));
}
use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.
the class WebEngineContextTest method test05.
@Test
public void test05() {
final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
final Map<String, Object> starting = new LinkedHashMap<String, Object>();
starting.put("one", "ha");
starting.put("ten", "tieen");
final Map<String, Object> requestAttributes = new LinkedHashMap<String, Object>();
final Map<String, Object[]> requestParameters = new LinkedHashMap<String, Object[]>();
final HttpServletRequest mockRequest = TestMockServletUtil.createHttpServletRequest("WebVariablesMap", null, requestAttributes, requestParameters, LOCALE);
final HttpServletResponse mockResponse = TestMockServletUtil.createHttpServletResponse();
final Map<String, Object> servletContextAttributes = new LinkedHashMap<String, Object>();
final ServletContext mockServletContext = TestMockServletUtil.createServletContext(servletContextAttributes);
final WebEngineContext vm = new WebEngineContext(configuration, templateData1, null, mockRequest, mockResponse, mockServletContext, LOCALE, starting);
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertEquals("ha", vm.getVariable("one"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
vm.setVariable("one", "a value");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertEquals("a value", vm.getVariable("one"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
vm.increaseLevel();
vm.setVariable("one", "hello");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertEquals("hello", vm.getVariable("one"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
vm.setVariable("two", "twello");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertEquals("hello", vm.getVariable("one"));
Assert.assertEquals("twello", vm.getVariable("two"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
mockRequest.removeAttribute("one");
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertNull(vm.getVariable("one"));
Assert.assertEquals("twello", vm.getVariable("two"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
Assert.assertNull(mockRequest.getAttribute("one"));
Assert.assertEquals("twello", mockRequest.getAttribute("two"));
Assert.assertEquals("tieen", mockRequest.getAttribute("ten"));
Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "one"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "two"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "ten"));
vm.increaseLevel();
vm.setVariable("one", "helloz");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertEquals("helloz", vm.getVariable("one"));
Assert.assertEquals("twello", vm.getVariable("two"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
Assert.assertEquals("helloz", mockRequest.getAttribute("one"));
Assert.assertEquals("twello", mockRequest.getAttribute("two"));
Assert.assertEquals("tieen", mockRequest.getAttribute("ten"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "two"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "ten"));
vm.decreaseLevel();
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertNull(vm.getVariable("one"));
Assert.assertEquals("twello", vm.getVariable("two"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
Assert.assertNull(mockRequest.getAttribute("one"));
Assert.assertEquals("twello", mockRequest.getAttribute("two"));
Assert.assertEquals("tieen", mockRequest.getAttribute("ten"));
Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "one"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "two"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "ten"));
vm.decreaseLevel();
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("ten"));
Assert.assertNull(vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("tieen", vm.getVariable("ten"));
Assert.assertNull(mockRequest.getAttribute("one"));
Assert.assertNull(mockRequest.getAttribute("two"));
Assert.assertEquals("tieen", mockRequest.getAttribute("ten"));
Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "one"));
Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "two"));
Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "ten"));
}
use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.
the class WebEngineContextTest method test06.
@Test
public void test06() {
final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
final Map<String, Object> requestAttributes = new LinkedHashMap<String, Object>();
final Map<String, Object[]> requestParameters = new LinkedHashMap<String, Object[]>();
final HttpServletRequest mockRequest = TestMockServletUtil.createHttpServletRequest("WebVariablesMap", null, requestAttributes, requestParameters, LOCALE);
final HttpServletResponse mockResponse = TestMockServletUtil.createHttpServletResponse();
final Map<String, Object> servletContextAttributes = new LinkedHashMap<String, Object>();
final ServletContext mockServletContext = TestMockServletUtil.createServletContext(servletContextAttributes);
final WebEngineContext vm = new WebEngineContext(configuration, templateData1, null, mockRequest, mockResponse, mockServletContext, LOCALE, null);
vm.setVariable("one", "a value");
Assert.assertEquals("{0:{one=a value}(test01)}[0]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=a value}(test01)", vm.toString());
vm.setVariable("one", "two values");
Assert.assertEquals("{0:{one=two values}(test01)}[0]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=two values}(test01)", vm.toString());
vm.increaseLevel();
vm.setVariable("one", "hello");
Assert.assertEquals("{1:{one=hello},0:{one=two values}(test01)}[1]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=hello}(test01)", vm.toString());
vm.setVariable("two", "twello");
Assert.assertEquals("{1:{one=hello, two=twello},0:{one=two values}(test01)}[1]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=hello, two=twello}(test01)", vm.toString());
vm.decreaseLevel();
Assert.assertEquals("{0:{one=two values}(test01)}[0]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=two values}(test01)", vm.toString());
vm.increaseLevel();
vm.setVariable("two", "twellor");
vm.setInliner(new StandardTextInliner(configuration));
Assert.assertEquals("{1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[1]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=two values, two=twellor}[StandardTextInliner](test01)", vm.toString());
vm.increaseLevel();
vm.setVariable("three", "twelloree");
Assert.assertEquals("{2:{three=twelloree},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[2]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=two values, two=twellor, three=twelloree}[StandardTextInliner](test01)", vm.toString());
vm.setVariable("one", "atwe");
Assert.assertEquals("{2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[2]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=twellor, three=twelloree}[StandardTextInliner](test01)", vm.toString());
vm.increaseLevel();
vm.increaseLevel();
vm.increaseLevel();
Assert.assertEquals("{2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[5]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=twellor, three=twelloree}[StandardTextInliner](test01)", vm.toString());
vm.setVariable("four", "lotwss");
Assert.assertEquals("{5:{four=lotwss},2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[5]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=twellor, three=twelloree, four=lotwss}[StandardTextInliner](test01)", vm.toString());
vm.setVariable("two", "itwiii");
Assert.assertEquals("{5:{four=lotwss, two=itwiii},2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[5]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=itwiii, three=twelloree, four=lotwss}[StandardTextInliner](test01)", vm.toString());
vm.decreaseLevel();
Assert.assertEquals("{2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[4]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=twellor, three=twelloree}[StandardTextInliner](test01)", vm.toString());
vm.decreaseLevel();
Assert.assertEquals("{2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[3]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=twellor, three=twelloree}[StandardTextInliner](test01)", vm.toString());
vm.decreaseLevel();
Assert.assertEquals("{2:{three=twelloree, one=atwe},1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[2]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=atwe, two=twellor, three=twelloree}[StandardTextInliner](test01)", vm.toString());
vm.decreaseLevel();
Assert.assertEquals("{1:{two=twellor}[StandardTextInliner],0:{one=two values}(test01)}[1]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=two values, two=twellor}[StandardTextInliner](test01)", vm.toString());
vm.decreaseLevel();
Assert.assertEquals("{0:{one=two values}(test01)}[0]", vm.getStringRepresentationByLevel());
Assert.assertEquals("{one=two values}(test01)", vm.toString());
}
use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.
the class WebEngineContextTest method test13.
@Test
public void test13() {
final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
final TemplateData templateData2 = TestTemplateDataConfigurationBuilder.build("test02", TemplateMode.HTML);
final TemplateData templateData3 = TestTemplateDataConfigurationBuilder.build("test03", TemplateMode.XML);
final TemplateData templateData4 = TestTemplateDataConfigurationBuilder.build("test04", TemplateMode.TEXT);
final Map<String, Object> requestAttributes = new LinkedHashMap<String, Object>();
final Map<String, Object[]> requestParameters = new LinkedHashMap<String, Object[]>();
final HttpServletRequest mockRequest = TestMockServletUtil.createHttpServletRequest("WebVariablesMap", null, requestAttributes, requestParameters, LOCALE);
final HttpServletResponse mockResponse = TestMockServletUtil.createHttpServletResponse();
final Map<String, Object> servletContextAttributes = new LinkedHashMap<String, Object>();
final ServletContext mockServletContext = TestMockServletUtil.createServletContext(servletContextAttributes);
final WebEngineContext vm = new WebEngineContext(configuration, templateData1, null, mockRequest, mockResponse, mockServletContext, LOCALE, null);
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData1, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1), vm.getTemplateStack());
vm.setVariable("one", "a value");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("a value", vm.getVariable("one"));
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData1, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1), vm.getTemplateStack());
vm.setVariable("one", "two values");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("two values", vm.getVariable("one"));
vm.removeVariable("one");
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertNull(vm.getVariable("one"));
vm.setVariable("one", "two values");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("two values", vm.getVariable("one"));
vm.increaseLevel();
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData1, vm.getTemplateData());
vm.setTemplateData(templateData2);
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData2, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2), vm.getTemplateStack());
vm.setVariable("one", "hello");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("hello", vm.getVariable("one"));
vm.removeVariable("one");
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData2, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2), vm.getTemplateStack());
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertNull(vm.getVariable("one"));
vm.setVariable("one", "hello");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertEquals("hello", vm.getVariable("one"));
vm.removeVariable("two");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertEquals("hello", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("twello"));
vm.setVariable("two", "twello");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertEquals("hello", vm.getVariable("one"));
Assert.assertEquals("twello", vm.getVariable("two"));
vm.removeVariable("two");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertEquals("hello", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("twello"));
vm.removeVariable("one");
Assert.assertFalse(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertNull(vm.getVariable("one"));
Assert.assertNull(vm.getVariable("twello"));
vm.decreaseLevel();
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertEquals("two values", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
vm.increaseLevel();
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData1, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1), vm.getTemplateStack());
vm.setVariable("two", "twellor");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertEquals("two values", vm.getVariable("one"));
Assert.assertEquals("twellor", vm.getVariable("two"));
vm.setTemplateData(templateData2);
vm.increaseLevel();
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData2, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2), vm.getTemplateStack());
vm.setTemplateData(templateData3);
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
vm.setVariable("three", "twelloree");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertEquals("two values", vm.getVariable("one"));
Assert.assertEquals("twellor", vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
vm.setVariable("one", "atwe");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertEquals("twellor", vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
vm.increaseLevel();
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
vm.removeVariable("two");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
vm.increaseLevel();
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
vm.removeVariable("two");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
vm.increaseLevel();
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
vm.setVariable("four", "lotwss");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertTrue(vm.containsVariable("four"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
Assert.assertEquals("lotwss", vm.getVariable("four"));
vm.setVariable("two", "itwiii");
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertTrue(vm.containsVariable("four"));
Assert.assertFalse(vm.containsVariable("five"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertEquals("itwiii", vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
Assert.assertEquals("lotwss", vm.getVariable("four"));
vm.decreaseLevel();
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertFalse(vm.containsVariable("four"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
Assert.assertNull(vm.getVariable("four"));
vm.decreaseLevel();
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertFalse(vm.containsVariable("four"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
Assert.assertNull(vm.getVariable("four"));
vm.decreaseLevel();
Assert.assertEquals(TemplateMode.XML, vm.getTemplateMode());
Assert.assertSame(templateData3, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2, templateData3), vm.getTemplateStack());
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertTrue(vm.containsVariable("three"));
Assert.assertFalse(vm.containsVariable("four"));
Assert.assertEquals("atwe", vm.getVariable("one"));
Assert.assertEquals("twellor", vm.getVariable("two"));
Assert.assertEquals("twelloree", vm.getVariable("three"));
Assert.assertNull(vm.getVariable("four"));
vm.decreaseLevel();
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData2, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData2), vm.getTemplateStack());
vm.setTemplateData(templateData4);
Assert.assertEquals(TemplateMode.TEXT, vm.getTemplateMode());
Assert.assertSame(templateData4, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1, templateData4), vm.getTemplateStack());
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertTrue(vm.containsVariable("two"));
Assert.assertFalse(vm.containsVariable("three"));
Assert.assertFalse(vm.containsVariable("four"));
Assert.assertEquals("two values", vm.getVariable("one"));
Assert.assertEquals("twellor", vm.getVariable("two"));
Assert.assertNull(vm.getVariable("three"));
Assert.assertNull(vm.getVariable("four"));
vm.decreaseLevel();
Assert.assertEquals(TemplateMode.HTML, vm.getTemplateMode());
Assert.assertSame(templateData1, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData1), vm.getTemplateStack());
vm.setTemplateData(templateData4);
Assert.assertEquals(TemplateMode.TEXT, vm.getTemplateMode());
Assert.assertSame(templateData4, vm.getTemplateData());
Assert.assertEquals(Arrays.asList(templateData4), vm.getTemplateStack());
Assert.assertTrue(vm.containsVariable("one"));
Assert.assertFalse(vm.containsVariable("two"));
Assert.assertFalse(vm.containsVariable("three"));
Assert.assertFalse(vm.containsVariable("four"));
Assert.assertEquals("two values", vm.getVariable("one"));
Assert.assertNull(vm.getVariable("two"));
Assert.assertNull(vm.getVariable("three"));
Assert.assertNull(vm.getVariable("four"));
}
use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.
the class HtmlBlockSelectorMarkupHandlerTest method test.
public void test() throws Exception {
final HTMLTemplateParser parser = new HTMLTemplateParser(2, 4096);
final IEngineConfiguration templateEngineContext = TestTemplateEngineConfigurationBuilder.build();
final URL resourcesFolderURL = Thread.currentThread().getContextClassLoader().getResource(RESOURCES_FOLDER);
assertNotNull(resourcesFolderURL);
final File resourcesFolder = new File(resourcesFolderURL.toURI());
assertTrue(resourcesFolder.isDirectory());
final List<File> resourceFolderFiles = new ArrayList<File>(Arrays.asList(resourcesFolder.listFiles()));
Collections.sort(resourceFolderFiles, new Comparator<File>() {
public int compare(final File o1, final File o2) {
return o1.getName().compareTo(o2.getName());
}
});
final List<File> testFiles = new ArrayList<File>();
final List<File> resultFiles = new ArrayList<File>();
for (final File resourceFolderFile : resourceFolderFiles) {
if (resourceFolderFile.getName().startsWith("test") && resourceFolderFile.getName().endsWith(".html")) {
testFiles.add(resourceFolderFile);
} else if (resourceFolderFile.getName().startsWith("result") && resourceFolderFile.getName().endsWith(".html")) {
resultFiles.add(resourceFolderFile);
}
}
for (int i = 0; i < testFiles.size(); i++) {
final File testFile = testFiles.get(i);
final File resultFile = resultFiles.get(i);
final List<String> testFileLines = IOUtils.readLines(new InputStreamReader(new FileInputStream(testFile), "UTF-8"));
final String testFileContents = StringUtils.join(testFileLines, '\n');
final List<String> resultFileLines = IOUtils.readLines(new InputStreamReader(new FileInputStream(resultFile), "UTF-8"));
final String blockSelector = resultFileLines.get(0);
resultFileLines.remove(0);
final String resultFileContents = StringUtils.join(resultFileLines, '\n');
final Set<String> blockSelectors = new HashSet<String>(Arrays.asList(StringUtils.split(blockSelector, ",")));
check(parser, templateEngineContext, testFile.getName(), testFileContents, resultFileContents, blockSelectors);
}
}
Aggregations