001    package org.apache.maven.scm.provider;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     * http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import junit.framework.TestCase;
023    
024    /**
025     * @author <a href="mailto:dennisl@apache.org">Dennis Lundberg</a>
026     * @version $Id: ScmUrlUtilsTest.java 483105 2006-12-06 15:07:54Z evenisse $
027     */
028    public class ScmUrlUtilsTest
029        extends TestCase
030    {
031        private static final String SCM_URL_CVS_COLON = "scm:cvs:local:repository:module";
032    
033        private static final String SCM_URL_CVS_PIPE = "scm:cvs|local|repository|module";
034    
035        private static final String SCM_URL_CVS_INVALID = "scm|cvs|local|repository|module";
036    
037        private static final String SCM_URL_INVALID_1 = null;
038    
039        private static final String SCM_URL_INVALID_2 = "scm";
040    
041        private static final String SCM_URL_INVALID_3 = "scm:a";
042    
043        private static final String SCM_URL_INVALID_4 = "scm:a-";
044    
045        private static final String SCM_URL_VALID_1 = "scm:a:";
046    
047        private static final String SCM_URL_VALID_2 = "scm:a|";
048    
049        private static final String SCM_URL_VALID_3 = "scm:a:provider-specific-part";
050    
051        private static final String SCM_URL_VALID_4 = "scm:a|provider-specific-part";
052    
053        public void testGetDelimiter()
054            throws Exception
055        {
056            assertEquals( ":", ScmUrlUtils.getDelimiter( SCM_URL_CVS_COLON ) );
057            assertEquals( "|", ScmUrlUtils.getDelimiter( SCM_URL_CVS_PIPE ) );
058            assertEquals( "|", ScmUrlUtils.getDelimiter( SCM_URL_CVS_INVALID ) );
059        }
060    
061        public void testGetProvider()
062            throws Exception
063        {
064            assertEquals( "cvs", ScmUrlUtils.getProvider( SCM_URL_CVS_COLON ) );
065            assertEquals( "cvs", ScmUrlUtils.getProvider( SCM_URL_CVS_PIPE ) );
066            assertEquals( "cvs", ScmUrlUtils.getProvider( SCM_URL_CVS_INVALID ) );
067    
068            assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_1 ) );
069            assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_2 ) );
070            assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_3 ) );
071            assertEquals( "a", ScmUrlUtils.getProvider( SCM_URL_VALID_4 ) );
072        }
073    
074        public void testGetProviderSpecificPart()
075            throws Exception
076        {
077            assertEquals( "local:repository:module", ScmUrlUtils.getProviderSpecificPart( SCM_URL_CVS_COLON ) );
078            assertEquals( "local|repository|module", ScmUrlUtils.getProviderSpecificPart( SCM_URL_CVS_PIPE ) );
079            assertEquals( "local|repository|module", ScmUrlUtils.getProviderSpecificPart( SCM_URL_CVS_INVALID ) );
080    
081            assertEquals( "", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_1 ) );
082            assertEquals( "", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_2 ) );
083            assertEquals( "provider-specific-part", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_3 ) );
084            assertEquals( "provider-specific-part", ScmUrlUtils.getProviderSpecificPart( SCM_URL_VALID_4 ) );
085        }
086    
087        public void testIsValid()
088            throws Exception
089        {
090            assertTrue( ScmUrlUtils.isValid( SCM_URL_CVS_COLON ) );
091            assertTrue( ScmUrlUtils.isValid( SCM_URL_CVS_PIPE ) );
092            assertFalse( ScmUrlUtils.isValid( SCM_URL_CVS_INVALID ) );
093    
094            assertTrue( ScmUrlUtils.isValid( SCM_URL_VALID_1 ) );
095            assertTrue( ScmUrlUtils.isValid( SCM_URL_VALID_2 ) );
096            assertTrue( ScmUrlUtils.isValid( SCM_URL_VALID_3 ) );
097            assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_1 ) );
098            assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_2 ) );
099            assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_3 ) );
100            assertFalse( ScmUrlUtils.isValid( SCM_URL_INVALID_4 ) );
101        }
102    }