View Javadoc

1   package org.apache.continuum.scm.manager;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  import org.apache.maven.scm.manager.NoSuchScmProviderException;
24  import org.apache.maven.scm.provider.ScmProvider;
25  import org.apache.maven.scm.provider.cvslib.cvsexe.CvsExeScmProvider;
26  import org.apache.maven.scm.provider.cvslib.cvsjava.CvsJavaScmProvider;
27  import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  import org.springframework.context.ApplicationContext;
31  
32  import java.util.Properties;
33  
34  /**
35   * @version $Id: ScmManagerTest.java 1372260 2012-08-13 04:29:09Z brett $
36   * @todo replace with a spring integration test
37   */
38  public class ScmManagerTest
39      extends TestCase
40  {
41      private static final Logger log = LoggerFactory.getLogger( ScmManagerTest.class );
42  
43      private ScmManager manager;
44  
45      public void setUp()
46      {
47          ApplicationContext context = new PlexusClassPathXmlApplicationContext(
48              new String[]{"classpath*:META-INF/spring-context.xml", "classpath*:META-INF/plexus/components.xml",
49                  "classpath*:" + getClass().getName().replace( '.', '/' ) + ".xml"} );
50          manager = (ScmManager) context.getBean( "scmManager" );
51      }
52  
53      public void testScmProviders()
54          throws NoSuchScmProviderException
55      {
56          Properties backupSysProps = System.getProperties();
57  
58          try
59          {
60              manager.getScmLogger().info( "Hello, World" );
61              assertNotNull( manager.getProviderByType( "svn" ) );
62  
63              ScmProvider cvsProvider = manager.getProviderByType( "cvs" );
64              assertNotNull( cvsProvider );
65  
66              log.info( "cvs provider class " + cvsProvider.getClass().getName() );
67  
68              assertEquals( CvsJavaScmProvider.class, cvsProvider.getClass() );
69  
70              System.setProperty( "maven.scm.provider.cvs.implementation", "cvs_native" );
71  
72              cvsProvider = manager.getProviderByType( "cvs" );
73              assertNotNull( cvsProvider );
74  
75              log.info( "cvs provider class " + cvsProvider.getClass().getName() );
76              assertEquals( CvsExeScmProvider.class, cvsProvider.getClass() );
77              System.setProperty( "maven.scm.provider.cvs.implementation", "cvs" );
78  
79              cvsProvider = manager.getProviderByType( "cvs" );
80              assertNotNull( cvsProvider );
81  
82              log.info( "cvs provider class " + cvsProvider.getClass().getName() );
83  
84              assertEquals( CvsJavaScmProvider.class, cvsProvider.getClass() );
85          }
86          finally
87          {
88              System.setProperties( backupSysProps );
89              System.setProperty( "maven.scm.provider.cvs.implementation", "cvs" );
90          }
91  
92      }
93  }