1   package org.apache.fulcrum.testcontainer;
2   /*
3    * Copyright 2004 The Apache Software Foundation.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License")
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  import java.io.File;
18  
19  import org.apache.avalon.framework.component.ComponentException;
20  /**
21   * Basic testing of the Container
22   * 
23   * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
24   * @version $Id: EcmContainerTest.java 223137 2004-10-30 13:18:00Z epugh $
25   */
26  public class EcmContainerTest extends BaseUnitTest
27  {
28      /**
29  	 * Constructor for test.
30  	 * 
31  	 * @param testName name of the test being executed
32  	 */
33      public EcmContainerTest(String testName)
34      {
35          super(testName);
36      }
37      
38      public void setUp() throws Exception{
39          containerType=CONTAINER_ECM;
40          super.setUp();
41      }
42  
43      public void testInitialization()
44      {
45          assertTrue(true);
46      }
47      public void testComponentUsage()
48      {
49          SimpleComponent sc = null;
50          try
51          {
52              sc = (SimpleComponent) this.lookup(SimpleComponent.ROLE);
53          }
54          catch (ComponentException e)
55          {
56              e.printStackTrace();
57              fail(e.getMessage());
58          }
59          assertNotNull(sc);
60          sc.test();
61          assertEquals(sc.getAppRoot(),sc.getAppRoot2());
62          this.release(sc);
63      }
64      public void testAlternativeRoles()
65      {
66          SimpleComponent sc = null;
67          File f = new File("src/test/TestAlternativeRoleConfig.xml");
68          assertTrue(f.exists());
69          this.setRoleFileName("src/test/TestAlternativeRoleConfig.xml");
70          try
71          {
72              sc = (SimpleComponent) this.lookup(SimpleComponent.ROLE);
73          }
74          catch (ComponentException e)
75          {
76              e.printStackTrace();
77              fail(e.getMessage());
78          }
79          assertTrue(sc instanceof AlternativeComponentImpl);
80          assertNotNull(sc);
81          sc.test();
82          this.release(sc);
83      }
84  
85      public void testLoadingContainerWithNoRolesfile()
86      {
87          SimpleComponent sc = null;
88  
89          this.setRoleFileName(null);
90          this.setConfigurationFileName(
91              "src/test/TestComponentConfigIntegratedRoles.xml");
92          try
93          {
94              sc = (SimpleComponent) this.lookup(SimpleComponent.ROLE);
95          }
96          catch (ComponentException e)
97          {
98              e.printStackTrace();
99              fail(e.getMessage());
100         }
101         assertTrue(sc instanceof AlternativeComponentImpl);
102         assertNotNull(sc);
103         sc.test();
104         this.release(sc);
105     }
106 
107     public void testLoadingNonExistentFile()
108     {
109         SimpleComponent sc = null;
110 
111         this.setRoleFileName(null);
112         this.setConfigurationFileName("BogusFile.xml");
113         try
114         {
115             sc = (SimpleComponent) this.lookup(SimpleComponent.ROLE);
116         }
117         catch(RuntimeException re){
118             //good
119         }
120         catch (ComponentException e)
121         {
122             
123             fail(e.getMessage());
124         }
125     }
126 }