View Javadoc

    1   /*
    2    * $Id: BaseTemplateEngineTest.java 471756 2006-11-06 15:01:43Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts2.components.template;
    22
    23  import java.io.File;
    24  import java.net.URL;
    25  import java.util.Map;
    26
    27  import junit.framework.TestCase;
    28
    29  /***
    30   * Test case for BaseTemplateEngine
    31   */
    32  public class BaseTemplateEngineTest extends TestCase {
    33
    34  public void testGetThemePropsThroughFileSystem() throws Exception {
    35
    36          URL dummyResourceUrl = getClass().getResource("dummy.properties");
    37          File dummyResourceFile = new File(dummyResourceUrl.getFile());
    38          String themePropertiesDir = dummyResourceFile.getParent();
    39
    40          System.out.println("dummy resource url="+dummyResourceUrl);
    41          System.out.println("resource file="+dummyResourceFile);
    42          System.out.println("theme properties dir="+themePropertiesDir);
    43
    44          assertTrue(dummyResourceFile.exists());
    45          assertNotNull(themePropertiesDir);
    46
    47          Template template = new Template(themePropertiesDir, "theme1", "template1");
    48
    49          TemplateEngine templateEngine = new InnerBaseTemplateEngine("themeThroughFileSystem.properties");
    50          Map propertiesMap = templateEngine.getThemeProps(template);
    51
    52          assertNotNull(propertiesMap);
    53          assertTrue(propertiesMap.size() > 0);
    54
    55      }
    56
    57      public void testGetThemePropsThroughClasspath() throws Exception {
    58
    59          Template template = new Template("org/apache/struts2/components/template", "theme1", "template2");
    60          TemplateEngine templateEngine = new InnerBaseTemplateEngine("themeThroughClassPath.properties");
    61          Map propertiesMap = templateEngine.getThemeProps(template);
    62
    63          assertNotNull(propertiesMap);
    64          assertTrue(propertiesMap.size() > 0);
    65      }
    66
    67      public class InnerBaseTemplateEngine extends BaseTemplateEngine {
    68
    69          private String themePropertiesFileName;
    70
    71          public InnerBaseTemplateEngine(String themePropertiesFileName) {
    72              this.themePropertiesFileName = themePropertiesFileName;
    73          }
    74
    75          protected String getSuffix() {
    76              return "ftl";
    77          }
    78
    79          public void renderTemplate(TemplateRenderingContext templateContext) throws Exception {
    80          }
    81
    82          protected String getThemePropertiesFileName() {
    83              return this.themePropertiesFileName;
    84          }
    85      }
    86  }