View Javadoc
1   package org.codehaus.plexus;
2   
3   /*
4    * Copyright 2001-2006 Codehaus 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  import java.io.File;
20  
21  import junit.framework.TestCase;
22  import org.codehaus.plexus.component.discovery.DiscoveredComponent;
23  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
24  import org.codehaus.plexus.test.DefaultLoadOnStartService;
25  
26  /**
27   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
28   */
29  public class PlexusTestCaseTest extends TestCase {
30      private String basedir;
31  
32      public void setUp() {
33          basedir = System.getProperty("basedir");
34  
35          if (basedir == null) {
36              basedir = new File(".").getAbsolutePath();
37          }
38      }
39  
40      public void testPlexusTestCase() throws Exception {
41          PlexusTestCase tc = new PlexusTestCase() {};
42  
43          tc.setUp();
44  
45          try {
46              tc.lookup(DiscoveredComponent.class, "unknown");
47  
48              fail("Expected ComponentLookupException.");
49          } catch (ComponentLookupException ex) {
50              assertTrue(true);
51          }
52  
53          // This component is discovered from src/test/META-INF/plexus/components.xml
54          DiscoveredComponent component = tc.lookup(DiscoveredComponent.class);
55  
56          assertNotNull(component);
57  
58          assertNotNull(tc.getClassLoader());
59  
60          tc.tearDown();
61      }
62  
63      public void testLoadOnStartComponents() throws Exception {
64          PlexusTestCase tc = new PlexusTestCase() {
65              protected String getCustomConfigurationName() {
66                  return PlexusTestCase.getTestConfiguration(getClass());
67              }
68          };
69  
70          tc.setupContainer();
71  
72          // Assert that the load on start component has started.
73  
74          assertTrue("The load on start components haven't been started.", DefaultLoadOnStartService.isStarted);
75  
76          tc.tearDown();
77      }
78  
79      public void testGetFile() {
80          File file = PlexusTestCase.getTestFile("pom.xml");
81  
82          assertTrue(file.exists());
83  
84          file = PlexusTestCase.getTestFile(basedir, "pom.xml");
85  
86          assertTrue(file.exists());
87      }
88  
89      public void testGetPath() {
90          File file = new File(PlexusTestCase.getTestPath("pom.xml"));
91  
92          assertTrue(file.exists());
93  
94          file = new File(PlexusTestCase.getTestPath(basedir, "pom.xml"));
95  
96          assertTrue(file.exists());
97      }
98  }