Search in sources :

Example 26 with IEngineConfiguration

use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.

the class EngineContextTest method test03.

@Test
public void test03() {
    final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
    final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
    final EngineContext vm = new EngineContext(configuration, templateData1, null, LOCALE, null);
    vm.setVariable("one", "a value");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("a value", vm.getVariable("one"));
    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();
    vm.setVariable("one", "hello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    vm.removeVariable("one");
    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();
    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.increaseLevel();
    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"));
    vm.increaseLevel();
    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();
    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.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.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.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.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.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.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"));
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) EngineContext(org.thymeleaf.context.EngineContext) Test(org.junit.Test)

Example 27 with IEngineConfiguration

use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.

the class EngineContextTest method test06.

@Test
public void test06() {
    final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
    final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
    final EngineContext vm = new EngineContext(configuration, templateData1, null, LOCALE, null);
    vm.setVariable("one", "a value");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("a value", vm.getVariable("one"));
    vm.increaseLevel();
    vm.setVariable("one", "hello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    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.setVariable("three", "trwello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("two"));
    Assert.assertTrue(vm.containsVariable("three"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("twello", vm.getVariable("two"));
    Assert.assertEquals("trwello", vm.getVariable("three"));
    vm.setVariable("four", "fwello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("two"));
    Assert.assertTrue(vm.containsVariable("three"));
    Assert.assertTrue(vm.containsVariable("four"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("twello", vm.getVariable("two"));
    Assert.assertEquals("trwello", vm.getVariable("three"));
    Assert.assertEquals("fwello", vm.getVariable("four"));
    vm.setVariable("five", "vwello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("two"));
    Assert.assertTrue(vm.containsVariable("three"));
    Assert.assertTrue(vm.containsVariable("four"));
    Assert.assertTrue(vm.containsVariable("five"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("twello", vm.getVariable("two"));
    Assert.assertEquals("trwello", vm.getVariable("three"));
    Assert.assertEquals("fwello", vm.getVariable("four"));
    Assert.assertEquals("vwello", vm.getVariable("five"));
    vm.setVariable("six", "swello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("two"));
    Assert.assertTrue(vm.containsVariable("three"));
    Assert.assertTrue(vm.containsVariable("four"));
    Assert.assertTrue(vm.containsVariable("five"));
    Assert.assertTrue(vm.containsVariable("six"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("twello", vm.getVariable("two"));
    Assert.assertEquals("trwello", vm.getVariable("three"));
    Assert.assertEquals("fwello", vm.getVariable("four"));
    Assert.assertEquals("vwello", vm.getVariable("five"));
    Assert.assertEquals("swello", vm.getVariable("six"));
    vm.setVariable("seven", "svwello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("two"));
    Assert.assertTrue(vm.containsVariable("three"));
    Assert.assertTrue(vm.containsVariable("four"));
    Assert.assertTrue(vm.containsVariable("five"));
    Assert.assertTrue(vm.containsVariable("six"));
    Assert.assertTrue(vm.containsVariable("seven"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("twello", vm.getVariable("two"));
    Assert.assertEquals("trwello", vm.getVariable("three"));
    Assert.assertEquals("fwello", vm.getVariable("four"));
    Assert.assertEquals("vwello", vm.getVariable("five"));
    Assert.assertEquals("swello", vm.getVariable("six"));
    Assert.assertEquals("svwello", vm.getVariable("seven"));
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) EngineContext(org.thymeleaf.context.EngineContext) Test(org.junit.Test)

Example 28 with IEngineConfiguration

use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.

the class EngineContextTest method test09.

@Test
public void test09() {
    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 EngineContext vm = new EngineContext(configuration, templateData1, null, 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"));
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) EngineContext(org.thymeleaf.context.EngineContext) Test(org.junit.Test)

Example 29 with IEngineConfiguration

use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.

the class EngineContextTest method test10.

@Test
public void test10() {
    final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
    final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
    final EngineContext vm = new EngineContext(configuration, templateData1, null, LOCALE, null);
    Assert.assertFalse(vm.containsVariable("one"));
    Assert.assertNull(vm.getVariable("one"));
    vm.setVariable("one", null);
    Assert.assertTrue(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.assertTrue(vm.containsVariable("one"));
    Assert.assertNull(vm.getVariable("one"));
    vm.decreaseLevel();
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("a value", vm.getVariable("one"));
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) EngineContext(org.thymeleaf.context.EngineContext) Test(org.junit.Test)

Example 30 with IEngineConfiguration

use of org.thymeleaf.IEngineConfiguration in project thymeleaf-tests by thymeleaf.

the class EngineContextTest method test01.

@Test
public void test01() {
    final IEngineConfiguration configuration = TestTemplateEngineConfigurationBuilder.build();
    final TemplateData templateData1 = TestTemplateDataConfigurationBuilder.build("test01", TemplateMode.HTML);
    final EngineContext vm = new EngineContext(configuration, templateData1, null, LOCALE, null);
    vm.setVariable("one", "a value");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("a value", vm.getVariable("one"));
    vm.setVariable("one", "two values");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("two values", vm.getVariable("one"));
    vm.increaseLevel();
    vm.setVariable("one", "hello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    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.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();
    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.increaseLevel();
    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"));
    vm.increaseLevel();
    vm.increaseLevel();
    vm.increaseLevel();
    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"));
    vm.setVariable("four", "lotwss");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("two"));
    Assert.assertTrue(vm.containsVariable("three"));
    Assert.assertTrue(vm.containsVariable("four"));
    Assert.assertEquals("atwe", vm.getVariable("one"));
    Assert.assertEquals("twellor", 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.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.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.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.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.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"));
}
Also used : IEngineConfiguration(org.thymeleaf.IEngineConfiguration) EngineContext(org.thymeleaf.context.EngineContext) Test(org.junit.Test)

Aggregations

IEngineConfiguration (org.thymeleaf.IEngineConfiguration)45 Test (org.junit.Test)26 LinkedHashMap (java.util.LinkedHashMap)15 ServletContext (javax.servlet.ServletContext)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 WebEngineContext (org.thymeleaf.context.WebEngineContext)14 EngineContext (org.thymeleaf.context.EngineContext)10 TemplateProcessingException (org.thymeleaf.exceptions.TemplateProcessingException)8 TemplateInputException (org.thymeleaf.exceptions.TemplateInputException)6 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 EngineConfiguration (org.thymeleaf.EngineConfiguration)3 TemplateModel (org.thymeleaf.engine.TemplateModel)3 IPostProcessor (org.thymeleaf.postprocessor.IPostProcessor)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2