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: YaafiContainerTest.java 223282 2005-03-01 12:17:31Z sgoeschl $
25   */
26  public class YaafiContainerTest extends BaseUnitTest
27  {
28      /**
29       * Constructor for test.
30       *
31       * @param testName name of the test being executed
32       */
33      public YaafiContainerTest(String testName)
34      {
35          super(testName);
36      }
37  
38      public void testInitialization()
39      {
40          assertTrue(true);
41      }
42      public void testComponentUsage()
43      {
44          SimpleComponent sc = null;
45          try
46          {
47              sc = (SimpleComponent) this.lookup(SimpleComponent.class.getName());
48              //sc = (SimpleComponent) this.lookup("SimpleComponent");
49          }
50          catch (ComponentException e)
51          {
52              e.printStackTrace();
53              fail(e.getMessage());
54          }
55          assertNotNull(sc);
56          sc.test();
57          assertEquals(sc.getAppRoot(),sc.getAppRoot2());
58          this.release(sc);
59      }
60      public void testAlternativeRoles()
61      {
62          SimpleComponent sc = null;
63          File f = new File("src/test/TestAlternativeRoleConfig.xml");
64          assertTrue(f.exists());
65          this.setRoleFileName("src/test/TestAlternativeRoleConfig.xml");
66          try
67          {
68              sc = (SimpleComponent) this.lookup(SimpleComponent.ROLE);
69          }
70          catch (ComponentException e)
71          {
72              e.printStackTrace();
73              fail(e.getMessage());
74          }
75          assertTrue(sc instanceof AlternativeComponentImpl);
76          assertNotNull(sc);
77          sc.test();
78          this.release(sc);
79      }
80  
81      public void testLoadingContainerWithNoRolesfileFails()
82      {
83          SimpleComponent sc = null;
84  
85          this.setRoleFileName(null);
86          this.setConfigurationFileName(
87              "src/test/TestComponentConfigIntegratedRoles.xml");
88          try
89          {
90              sc = (SimpleComponent) this.lookup(SimpleComponent.ROLE);
91              fail("We should fail");
92          }
93          catch (Exception e)
94          {
95              //good  We expect to fail
96          }
97  
98      }
99  
100 }