Search in sources :

Example 1 with WebEngineContext

use of org.thymeleaf.context.WebEngineContext in project thymeleaf-tests by thymeleaf.

the class WebEngineContextTest method test10.

@Test
public void test10() {
    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.assertEquals("{0:{one=ha, ten=tieen}(test01)}[0]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=ha, ten=tieen}(test01)", vm.toString());
    Assert.assertEquals(createSet("ten", "one"), vm.getVariableNames());
    Assert.assertFalse(vm.isVariableLocal("ten"));
    vm.setVariable("one", "a value");
    Assert.assertFalse(vm.isVariableLocal("one"));
    Assert.assertEquals("{0:{one=a value, ten=tieen}(test01)}[0]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=a value, ten=tieen}(test01)", vm.toString());
    Assert.assertEquals(createSet("ten", "one"), vm.getVariableNames());
    vm.increaseLevel();
    vm.setVariable("one", "hello");
    Assert.assertTrue(vm.isVariableLocal("one"));
    Assert.assertEquals("{1:{one=hello},0:{one=a value, ten=tieen}(test01)}[1]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=hello, ten=tieen}(test01)", vm.toString());
    Assert.assertEquals(createSet("ten", "one"), vm.getVariableNames());
    vm.setVariable("two", "twello");
    Assert.assertTrue(vm.isVariableLocal("two"));
    Assert.assertEquals("{1:{one=hello, two=twello},0:{one=a value, ten=tieen}(test01)}[1]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=hello, ten=tieen, two=twello}(test01)", vm.toString());
    Assert.assertEquals(createSet("two", "ten", "one"), vm.getVariableNames());
    // This are directly set into the request, so they should only be affected by higher levels, never by decreasing levels
    mockRequest.setAttribute("one", "outer1");
    mockRequest.setAttribute("six", "outer6");
    Assert.assertEquals("{1:{two=twello},0:{one=outer1, ten=tieen, six=outer6}(test01)}[1]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=outer1, ten=tieen, two=twello, six=outer6}(test01)", vm.toString());
    Assert.assertEquals(createSet("two", "ten", "one", "six"), vm.getVariableNames());
    vm.increaseLevel();
    vm.setVariable("one", "helloz");
    Assert.assertEquals("{2:{one=helloz},1:{two=twello},0:{one=outer1, ten=tieen, six=outer6}(test01)}[2]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=helloz, ten=tieen, two=twello, six=outer6}(test01)", vm.toString());
    Assert.assertEquals(createSet("two", "ten", "one", "six"), vm.getVariableNames());
    vm.decreaseLevel();
    Assert.assertEquals("{1:{two=twello},0:{one=outer1, ten=tieen, six=outer6}(test01)}[1]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=outer1, ten=tieen, two=twello, six=outer6}(test01)", vm.toString());
    Assert.assertEquals(createSet("two", "ten", "one", "six"), vm.getVariableNames());
    vm.decreaseLevel();
    Assert.assertEquals("{0:{one=outer1, ten=tieen, six=outer6}(test01)}[0]", vm.getStringRepresentationByLevel());
    Assert.assertEquals("{one=outer1, ten=tieen, six=outer6}(test01)", vm.toString());
    Assert.assertEquals(createSet("ten", "one", "six"), vm.getVariableNames());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) WebEngineContext(org.thymeleaf.context.WebEngineContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with WebEngineContext

use of org.thymeleaf.context.WebEngineContext in project thymeleaf-tests by thymeleaf.

the class WebEngineContextTest method test01.

@Test
public void test01() {
    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.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 : HttpServletRequest(javax.servlet.http.HttpServletRequest) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) WebEngineContext(org.thymeleaf.context.WebEngineContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with WebEngineContext

use of org.thymeleaf.context.WebEngineContext in project thymeleaf-tests by thymeleaf.

the class WebEngineContextTest method test12.

@Test
public void test12() {
    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 val1");
    vm.increaseLevel();
    vm.setVariable("one", "a val2");
    vm.setSelectionTarget("FORM");
    Assert.assertTrue(vm.hasSelectionTarget());
    Assert.assertEquals("FORM", vm.getSelectionTarget());
    vm.decreaseLevel();
    vm.setVariable("one", "a val3");
    Assert.assertFalse(vm.hasSelectionTarget());
    Assert.assertNull(vm.getSelectionTarget());
    vm.increaseLevel();
    vm.setVariable("one", "a val4");
    Assert.assertFalse(vm.hasSelectionTarget());
    Assert.assertNull(vm.getSelectionTarget());
    vm.increaseLevel();
    vm.setVariable("one", "a val5");
    Assert.assertFalse(vm.hasSelectionTarget());
    Assert.assertNull(vm.getSelectionTarget());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) WebEngineContext(org.thymeleaf.context.WebEngineContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with WebEngineContext

use of org.thymeleaf.context.WebEngineContext in project thymeleaf-tests by thymeleaf.

the class WebEngineContextTest method test02.

@Test
public void test02() {
    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.decreaseLevel();
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertTrue(vm.containsVariable("ten"));
    Assert.assertEquals("a value", vm.getVariable("one"));
    Assert.assertEquals("tieen", vm.getVariable("ten"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) WebEngineContext(org.thymeleaf.context.WebEngineContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with WebEngineContext

use of org.thymeleaf.context.WebEngineContext in project thymeleaf-tests by thymeleaf.

the class WebEngineContextTest method test03.

@Test
public void test03() {
    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.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("a value", vm.getVariable("one"));
    Assert.assertEquals("a value", mockRequest.getAttribute("one"));
    vm.setVariable("one", "two values");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("two values", vm.getVariable("one"));
    Assert.assertEquals("two values", mockRequest.getAttribute("one"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
    vm.removeVariable("one");
    Assert.assertFalse(vm.containsVariable("one"));
    Assert.assertNull(vm.getVariable("one"));
    Assert.assertNull(mockRequest.getAttribute("one"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "one"));
    vm.setVariable("one", "two values");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("two values", vm.getVariable("one"));
    Assert.assertEquals("two values", mockRequest.getAttribute("one"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
    vm.increaseLevel();
    vm.setVariable("one", "hello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("hello", mockRequest.getAttribute("one"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
    vm.removeVariable("one");
    Assert.assertFalse(vm.containsVariable("one"));
    Assert.assertNull(vm.getVariable("one"));
    Assert.assertNull(mockRequest.getAttribute("one"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "one"));
    vm.setVariable("one", "hello");
    Assert.assertTrue(vm.containsVariable("one"));
    Assert.assertEquals("hello", vm.getVariable("one"));
    Assert.assertEquals("hello", mockRequest.getAttribute("one"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "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"));
    Assert.assertNull(mockRequest.getAttribute("two"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "two"));
    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"));
    Assert.assertEquals("twello", mockRequest.getAttribute("two"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "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"));
    Assert.assertEquals("twellor", mockRequest.getAttribute("two"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "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"));
    Assert.assertEquals("atwe", mockRequest.getAttribute("one"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
    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"));
    Assert.assertNull(mockRequest.getAttribute("two"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "two"));
    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"));
    Assert.assertNull(mockRequest.getAttribute("two"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "two"));
    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"));
    Assert.assertEquals("itwiii", mockRequest.getAttribute("two"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "two"));
    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"));
    Assert.assertNull(mockRequest.getAttribute("two"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "two"));
    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"));
    Assert.assertEquals("atwe", mockRequest.getAttribute("one"));
    Assert.assertEquals("twellor", mockRequest.getAttribute("two"));
    Assert.assertEquals("twelloree", mockRequest.getAttribute("three"));
    Assert.assertNull(mockRequest.getAttribute("four"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "two"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "three"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "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"));
    Assert.assertEquals("two values", mockRequest.getAttribute("one"));
    Assert.assertNull(mockRequest.getAttribute("two"));
    Assert.assertNull(mockRequest.getAttribute("three"));
    Assert.assertNull(mockRequest.getAttribute("four"));
    Assert.assertTrue(enumerationContains(mockRequest.getAttributeNames(), "one"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "two"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "three"));
    Assert.assertFalse(enumerationContains(mockRequest.getAttributeNames(), "four"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IEngineConfiguration(org.thymeleaf.IEngineConfiguration) WebEngineContext(org.thymeleaf.context.WebEngineContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)14 ServletContext (javax.servlet.ServletContext)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)14 Test (org.junit.Test)14 IEngineConfiguration (org.thymeleaf.IEngineConfiguration)14 WebEngineContext (org.thymeleaf.context.WebEngineContext)14 StandardTextInliner (org.thymeleaf.standard.inline.StandardTextInliner)1