KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > container > TestAbstractContainer


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.container;
21
22 import java.io.File JavaDoc;
23 import java.io.Reader JavaDoc;
24 import java.io.StringReader JavaDoc;
25 import java.util.Vector JavaDoc;
26
27 import junit.framework.TestCase;
28
29 import org.apache.cactus.integration.ant.deployment.EarParser;
30 import org.apache.tools.ant.filters.util.ChainReaderHelper;
31 import org.apache.tools.ant.types.FilterChain;
32
33 /**
34  * Unit tests for {@link AbstractContainer}.
35  *
36  * @version $Id: TestAbstractContainer.java,v 1.10 2004/05/31 20:05:23 vmassol Exp $
37  */

38 public class TestAbstractContainer extends TestCase
39 {
40     /**
41      * The instance to test
42      */

43     private AbstractContainer container;
44
45     /**
46      * @see TestCase#setUp()
47      */

48     protected void setUp()
49     {
50         this.container = new AbstractContainer()
51         {
52             public String JavaDoc getName()
53             {
54                 return "test container";
55             }
56
57             public int getPort()
58             {
59                 return 8080;
60             }
61
62             public void startUp()
63             {
64             }
65             
66             public void shutDown()
67             {
68             }
69         };
70     }
71
72     /**
73      * Verify that the Ant filter chain is correctly configured to
74      * replace the "cactus.port" and "cactus.context" tokens.
75      *
76      * @throws Exception if an error happens during the test
77      */

78     public void testCreateFilterChainOk() throws Exception JavaDoc
79     {
80         String JavaDoc testInputDirProperty = System.getProperty("testinput.dir");
81         assertTrue("The system property 'testinput.dir' must be set",
82             testInputDirProperty != null);
83         File JavaDoc testInputDir = new File JavaDoc(testInputDirProperty);
84         assertTrue("The system property 'testinput.dir' must point to an "
85             + "existing directory", testInputDir.isDirectory());
86         String JavaDoc fileName =
87             "org/apache/cactus/integration/ant/cactified.ear";
88         File JavaDoc earFile = new File JavaDoc(testInputDir, fileName);
89         assertTrue("The test input " + fileName + " does not exist",
90             earFile.exists());
91
92         this.container.setDeployableFile(EarParser.parse(earFile));
93
94         // Note that we needed to add a last character to the string
95
// after the @cactus.context@ token as otherwise the Ant code
96
// fails! It looks like an Ant bug to me...
97
String JavaDoc buffer = "@cactus.port@:@cactus.context@:";
98                         
99         FilterChain chain = this.container.createFilterChain();
100
101         ChainReaderHelper helper = new ChainReaderHelper();
102         Vector JavaDoc chains = new Vector JavaDoc();
103         chains.addElement(chain);
104         helper.setFilterChains(chains);
105         helper.setPrimaryReader(new StringReader JavaDoc(buffer));
106         Reader JavaDoc reader = helper.getAssembledReader();
107         assertEquals("8080:empty:", helper.readFully(reader));
108     }
109 }
110
Popular Tags