View Javadoc
1   package org.apache.maven.scm.provider;
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  
24  /**
25   * @author <a href="mailto:dennisl@apache.org">Dennis Lundberg</a>
26   *
27   */
28  public class ScmUrlUtilsTest
29      extends TestCase
30  {
31      private static final String SCM_URL_CVS_COLON = "scm:cvs:local:repository:module";
32  
33      private static final String SCM_URL_CVS_PIPE = "scm:cvs|local|repository|module";
34  
35      private static final String SCM_URL_CVS_INVALID = "scm|cvs|local|repository|module";
36  
37      private static final String SCM_URL_INVALID_1 = null;
38  
39      private static final String SCM_URL_INVALID_2 = "scm";
40  
41      private static final String SCM_URL_INVALID_3 = "scm:a";
42  
43      private static final String SCM_URL_INVALID_4 = "scm:a-";
44  
45      private static final String SCM_URL_VALID_1 = "scm:a:";
46  
47      private static final String SCM_URL_VALID_2 = "scm:a|";
48  
49      private static final String SCM_URL_VALID_3 = "scm:a:provider-specific-part";
50  
51      private static final String SCM_URL_VALID_4 = "scm:a|provider-specific-part";
52  
53      public void testGetDelimiter()
54          throws Exception
55      {
56          assertEquals( ":", ScmUrlUtils.getDelimiter( SCM_URL_CVS_COLON ) );
57          assertEquals( "|", ScmUrlUtils.getDelimiter( SCM_URL_CVS_PIPE ) );
58          assertEquals( "|", ScmUrlUtils.getDelimiter( SCM_URL_CVS_INVALID ) );
59      }
60  
61      public void testGetProvider()
62          throws Exception
63      {
64          assertEquals( "cvs", ScmUrlUtils.getProvider( SCM_URL_CVS_COLON ) );
65          assertEquals( "cvs", ScmUrlUtils.getProvider( SCM_URL_CVS_PIPE ) );
66          assertEquals( "cvs", ScmUrlUtils.getProvider( SCM_URL_CVS_INVALID ) );
67  
68          assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_1 ) );
69          assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_2 ) );
70          assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_3 ) );
71          assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_4 ) );
72      }
73  
74      public void testGetProviderSpecificPart()
75          throws Exception
76      {
77          assertEquals( "local:repository:module", ScmUrlUtils.getProviderSpecificPart( SCM_URL_CVS_COLON ) );
78          assertEquals( "local|repository|module", ScmUrlUtils.getProviderSpecificPart( SCM_URL_CVS_PIPE ) );
79          assertEquals( "local|repository|module", ScmUrlUtils.getProviderSpecificPart( SCM_URL_CVS_INVALID ) );
80  
81          assertEquals( "", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_1 ) );
82          assertEquals( "", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_2 ) );
83          assertEquals( "provider-specific-part", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_3 ) );
84          assertEquals( "provider-specific-part", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_4 ) );
85      }
86  
87      public void testIsValid()
88          throws Exception
89      {
90          assertTrue( ScmUrlUtils.isValid( SCM_URL_CVS_COLON ) );
91          assertTrue( ScmUrlUtils.isValid( SCM_URL_CVS_PIPE ) );
92          assertFalse( ScmUrlUtils.isValid( SCM_URL_CVS_INVALID ) );
93  
94          assertTrue( ScmUrlUtils.isValid( SCM_URL_VALID_1 ) );
95          assertTrue( ScmUrlUtils.isValid( SCM_URL_VALID_2 ) );
96          assertTrue( ScmUrlUtils.isValid( SCM_URL_VALID_3 ) );
97          assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_1 ) );
98          assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_2 ) );
99          assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_3 ) );
100         assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_4 ) );
101     }
102 }