001: package org.apache.velocity.test;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.apache.velocity.app.Velocity;
026: import org.apache.velocity.runtime.RuntimeConstants;
027: import org.apache.velocity.test.misc.TestLogChute;
028:
029: /**
030: * Make sure that a forward referenced macro inside another macro definition does
031: * not report an error in the log.
032: * (VELOCITY-71).
033: *
034: * @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
035: * @version $Id: MacroForwardDefineTestCase.java 491369 2006-12-31 02:52:05Z wglass $
036: */
037: public class MacroForwardDefineTestCase extends BaseTestCase {
038: /**
039: * Path for templates. This property will override the
040: * value in the default velocity properties file.
041: */
042: private final static String FILE_RESOURCE_LOADER_PATH = TEST_COMPARE_DIR
043: + "/macroforwarddefine";
044:
045: /**
046: * Results relative to the build directory.
047: */
048: private static final String RESULTS_DIR = TEST_RESULT_DIR
049: + "/macroforwarddefine";
050:
051: /**
052: * Results relative to the build directory.
053: */
054: private static final String COMPARE_DIR = TEST_COMPARE_DIR
055: + "/macroforwarddefine/compare";
056:
057: /**
058: * Collects the log messages.
059: */
060: private TestLogChute logger = new TestLogChute();
061:
062: /**
063: * Default constructor.
064: */
065: public MacroForwardDefineTestCase(String name) {
066: super (name);
067: }
068:
069: public void setUp() throws Exception {
070: assureResultsDirectoryExists(RESULTS_DIR);
071:
072: // use Velocity.setProperty (instead of properties file) so that we can use actual instance of log
073: Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "file");
074: Velocity.setProperty(
075: RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
076: FILE_RESOURCE_LOADER_PATH);
077: Velocity.setProperty(
078: RuntimeConstants.RUNTIME_LOG_REFERENCE_LOG_INVALID,
079: "true");
080: Velocity.setProperty(RuntimeConstants.VM_LIBRARY, "macros.vm");
081:
082: // actual instance of logger
083: logger = new TestLogChute();
084: Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,
085: logger);
086: Velocity.setProperty("runtime.log.logsystem.test.level",
087: "error");
088:
089: Velocity.init();
090: }
091:
092: public static Test suite() {
093: return new TestSuite(MacroForwardDefineTestCase.class);
094: }
095:
096: public void testLogResult() throws Exception {
097: if (!isMatch(logger.getLog(), COMPARE_DIR, "velocity.log",
098: "cmp")) {
099: fail("Output incorrect.");
100: }
101: }
102: }
|