001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.cocoon.transformation;
019:
020: import junit.framework.Test;
021: import junit.framework.TestSuite;
022: import junit.textui.TestRunner;
023:
024: import org.apache.avalon.framework.component.WrapperComponentManager;
025: import org.apache.avalon.framework.parameters.Parameters;
026: import org.apache.cocoon.Processor;
027: import org.apache.cocoon.SitemapComponentTestCase;
028: import org.apache.cocoon.components.CocoonComponentManager;
029: import org.apache.cocoon.environment.mock.MockEnvironment;
030:
031: /**
032: * A simple testcase for FilterTransformer.
033: *
034: * @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
035: * @version SVN $Id: XIncludeTransformerTestCase.java 433543 2006-08-22 06:22:54Z crossley $
036: */
037: public class XIncludeTransformerTestCase extends
038: SitemapComponentTestCase {
039:
040: /**
041: * Run this test suite from commandline
042: *
043: * @param args commandline arguments (ignored)
044: */
045: public static void main(String[] args) {
046: TestRunner.run(suite());
047: }
048:
049: /** Create a test suite.
050: * This test suite contains all test cases of this class.
051: * @return the Test object containing all test cases.
052: */
053: public static Test suite() {
054: TestSuite suite = new TestSuite(
055: XIncludeTransformerTestCase.class);
056: return suite;
057: }
058:
059: private void xincludeTest(String input, String result)
060: throws Exception {
061: Parameters parameters = new Parameters();
062:
063: String src = null;
064:
065: // enter & leave environment, as a manager is looked up using
066: // the processing context stack
067: MockEnvironment env = new MockEnvironment(null);
068: Processor processor = (Processor) this .lookup(Processor.ROLE);
069:
070: CocoonComponentManager.enterEnvironment(env,
071: new WrapperComponentManager(this .getManager()),
072: processor);
073:
074: assertEqual(load(result), transform("xinclude", src,
075: parameters, load(input)));
076:
077: CocoonComponentManager.leaveEnvironment();
078: }
079:
080: /** Testcase for xinclude simple include
081: *
082: * @throws Exception if ComponentManager enterEnvironment fails
083: */
084: public void testXInclude1() throws Exception {
085: getLogger().debug("testXInclude1");
086: xincludeTest(
087: "resource://org/apache/cocoon/transformation/xinclude-input-1.xml",
088: "resource://org/apache/cocoon/transformation/xinclude-result-1.xml");
089: }
090:
091: /** Testcase for xinclude simple text include
092: *
093: * @throws Exception if ComponentManager enterEnvironment fails
094: */
095: public void testXInclude2() throws Exception {
096: getLogger().debug("testXInclude2");
097: xincludeTest(
098: "resource://org/apache/cocoon/transformation/xinclude-input-2.xml",
099: "resource://org/apache/cocoon/transformation/xinclude-result-2.xml");
100: }
101:
102: /** Testcase for xinclude simple fallback
103: * Check issue: COCOON-1489
104: *
105: * @throws Exception if ComponentManager enterEnvironment fails
106: */
107: public void testXIncludeSimpleFallback() throws Exception {
108: getLogger().debug("testXIncludeSimpleFallback");
109: xincludeTest(
110: "resource://org/apache/cocoon/transformation/xinclude-input-fallbackTest.xml",
111: "resource://org/apache/cocoon/transformation/xinclude-result-fallbackTest.xml");
112: }
113:
114: /** Testcase for xinclude with a nested xinclude elemento into the fallback
115: * Check issue: COCOON-1489
116: *
117: * @throws Exception if ComponentManager enterEnvironment fails
118: */
119: public void testXIncludeNestedXincludeElementInAFallback()
120: throws Exception {
121: getLogger().debug(
122: "testXIncludeNestedXincludeElementInAFallback");
123: xincludeTest(
124: "resource://org/apache/cocoon/transformation/xinclude-input-nestedXincludeFallbackTest.xml",
125: "resource://org/apache/cocoon/transformation/xinclude-result-1.xml");
126: }
127:
128: /**
129: * Testcase for xinclude with multiple nested fallbacks
130: */
131: public void testXIncludeMultipleNestedFallback() throws Exception {
132: getLogger().debug("testXIncludeMultipleNestedFallback");
133: xincludeTest(
134: "resource://org/apache/cocoon/transformation/xinclude-input-multipleNestedFallbackTest.xml",
135: "resource://org/apache/cocoon/transformation/xinclude-result-fallbackTest.xml");
136: }
137:
138: /** Testcase for xinclude simple fallback when parse attribute is 'text'
139: * Check issue: COCOON-1110
140: *
141: * @throws Exception if ComponentManager enterEnvironment fails
142: */
143: public void testXIncludeSimpleFallbackForTextParse()
144: throws Exception {
145: getLogger().debug("testXIncludeSimpleFallbackForTextParse");
146: xincludeTest(
147: "resource://org/apache/cocoon/transformation/xinclude-input-simpleFallbackForTextParseTest.xml",
148: "resource://org/apache/cocoon/transformation/xinclude-result-fallbackTest.xml");
149: }
150: }
|