/*
 * =============================================================================
 * 
 *   Copyright (c) 2011-2014, The THYMELEAF team (http://www.thymeleaf.org)
 * 
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * 
 * =============================================================================
 */
package org.thymeleaf.templateparser.decoupled.gtvg;

import java.util.Calendar;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.context.IExpressionContext;
import org.thymeleaf.linkbuilder.StandardLinkBuilder;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
import org.thymeleaf.testing.templateengine.util.ResourceUtils;
import org.thymeleaf.util.ClassLoaderUtils;


public class DecoupledGTVGTest {



    public DecoupledGTVGTest() {
        super();
    }
    


    
    @Test
    public void testDecoupledGTVG() throws Exception {


        final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();

        templateResolver.setTemplateMode("HTML");
        templateResolver.setPrefix("templateparser/decoupled/gtvg/templates/");
        templateResolver.setSuffix(".html");
        templateResolver.setUseDecoupledLogic(true);


        final TemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);
        templateEngine.setLinkBuilder(new StandardLinkBuilder() {
            @Override
            protected String computeContextPath(final IExpressionContext context, final String base, final Map<String, Object> parameters) {
                return "";
            }
        });



        final Context ctx = new Context();
        ctx.setVariable("user", new User("John", "Apricot", "Antarctica", null));
        ctx.setVariable("today", Calendar.getInstance());


        final String result = templateEngine.process("home", ctx);


        final String expected =
                ResourceUtils.read(
                        ClassLoaderUtils.getClassLoader(DecoupledGTVGTest.class).getResourceAsStream("templateparser/decoupled/gtvg/result/home.html"),
                        "ISO-8859-1",
                        true);

        Assert.assertEquals(ResourceUtils.normalize(expected), ResourceUtils.normalize(result));


    }







}

@@ -883,35 +883,8 @@
 g;%0A%0A
-import java.util.Calendar;%0A
 impo
@@ -1017,32 +1017,71 @@
 ontext.Context;%0A
+import org.thymeleaf.context.IContext;%0A
 import org.thyme
@@ -1342,16 +1342,53 @@
 rUtils;%0A
+import org.thymeleaf.util.DateUtils;%0A
 %0A%0Apublic
@@ -1477,64 +1477,643 @@
   %7D%0A
-    %0A%0A%0A    %0A    @Test%0A    public void testDecoupledGTVG(
+%0A%0A%0A%0A    @Test%0A    public void testGTVGHome() throws Exception %7B%0A%0A        final Context ctx = new Context();%0A        ctx.setVariable(%22user%22, new User(%22John%22, %22Apricot%22, %22Antarctica%22, null));%0A        ctx.setVariable(%22today%22, DateUtils.create(2016, 02, 18));%0A%0A        test(%22home%22, %22templateparser/decoupled/gtvg/result/home.html%22, ctx);%0A%0A    %7D%0A%0A%0A%0A    @Test%0A    public void testGTVGSubscribe() throws Exception %7B%0A%0A        test(%22subscribe%22, %22templateparser/decoupled/gtvg/result/subscribe.html%22, new Context());%0A%0A    %7D%0A%0A%0A%0A%0A%0A%0A    private static void test(final String templateName, final String expectedResultLocation, final IContext context
 ) th
@@ -2872,17 +2872,16 @@
   %7D);%0A%0A%0A
-%0A
         
@@ -2890,248 +2890,108 @@
 nal 
-Context ctx = new Context();%0A        ctx.setVariable(%22user%22, new User(%22John%22, %22Apricot%22, %22Antarctica%22, null));%0A        ctx.setVariable(%22today%22, Calendar.getInstance());%0A%0A%0A        final String result = templateEngine.process(%22home%22, ctx
+String result = templateEngine.process(templateName, context);%0A        System.out.println(result
 );%0A%0A
-%0A
     
@@ -3159,56 +3159,30 @@
 eam(
-%22templateparser/decoupled/gtvg/result/home.html%22
+expectedResultLocation
 ),%0A 
@@ -3358,14 +3358,10 @@
    %7D%0A%0A%0A%0A
-%0A%0A%0A%0A
 %7D%0A

Set fixed date in GTVG Home test