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