001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.container;
021:
022: import java.io.File;
023: import java.io.Reader;
024: import java.io.StringReader;
025: import java.util.Vector;
026:
027: import junit.framework.TestCase;
028:
029: import org.apache.cactus.integration.ant.deployment.EarParser;
030: import org.apache.tools.ant.filters.util.ChainReaderHelper;
031: import org.apache.tools.ant.types.FilterChain;
032:
033: /**
034: * Unit tests for {@link AbstractContainer}.
035: *
036: * @version $Id: TestAbstractContainer.java 239003 2004-05-31 20:05:27Z vmassol $
037: */
038: public class TestAbstractContainer extends TestCase {
039: /**
040: * The instance to test
041: */
042: private AbstractContainer container;
043:
044: /**
045: * @see TestCase#setUp()
046: */
047: protected void setUp() {
048: this .container = new AbstractContainer() {
049: public String getName() {
050: return "test container";
051: }
052:
053: public int getPort() {
054: return 8080;
055: }
056:
057: public void startUp() {
058: }
059:
060: public void shutDown() {
061: }
062: };
063: }
064:
065: /**
066: * Verify that the Ant filter chain is correctly configured to
067: * replace the "cactus.port" and "cactus.context" tokens.
068: *
069: * @throws Exception if an error happens during the test
070: */
071: public void testCreateFilterChainOk() throws Exception {
072: String testInputDirProperty = System
073: .getProperty("testinput.dir");
074: assertTrue("The system property 'testinput.dir' must be set",
075: testInputDirProperty != null);
076: File testInputDir = new File(testInputDirProperty);
077: assertTrue(
078: "The system property 'testinput.dir' must point to an "
079: + "existing directory", testInputDir
080: .isDirectory());
081: String fileName = "org/apache/cactus/integration/ant/cactified.ear";
082: File earFile = new File(testInputDir, fileName);
083: assertTrue("The test input " + fileName + " does not exist",
084: earFile.exists());
085:
086: this .container.setDeployableFile(EarParser.parse(earFile));
087:
088: // Note that we needed to add a last character to the string
089: // after the @cactus.context@ token as otherwise the Ant code
090: // fails! It looks like an Ant bug to me...
091: String buffer = "@cactus.port@:@cactus.context@:";
092:
093: FilterChain chain = this .container.createFilterChain();
094:
095: ChainReaderHelper helper = new ChainReaderHelper();
096: Vector chains = new Vector();
097: chains.addElement(chain);
098: helper.setFilterChains(chains);
099: helper.setPrimaryReader(new StringReader(buffer));
100: Reader reader = helper.getAssembledReader();
101: assertEquals("8080:empty:", helper.readFully(reader));
102: }
103: }
|