001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.scm.provider;
020
021import org.junit.Test;
022
023import static org.junit.Assert.assertEquals;
024import static org.junit.Assert.assertFalse;
025import static org.junit.Assert.assertTrue;
026
027/**
028 * @author <a href="mailto:dennisl@apache.org">Dennis Lundberg</a>
029 *
030 */
031public class ScmUrlUtilsTest {
032    private static final String SCM_URL_INVALID_1 = null;
033
034    private static final String SCM_URL_INVALID_2 = "scm";
035
036    private static final String SCM_URL_INVALID_3 = "scm:a";
037
038    private static final String SCM_URL_INVALID_4 = "scm:a-";
039
040    private static final String SCM_URL_VALID_1 = "scm:a:";
041
042    private static final String SCM_URL_VALID_2 = "scm:a|";
043
044    private static final String SCM_URL_VALID_3 = "scm:a:provider-specific-part";
045
046    private static final String SCM_URL_VALID_4 = "scm:a|provider-specific-part";
047
048    @Test
049    public void testGetProvider() throws Exception {
050        assertEquals("a", ScmUrlUtils.getProvider(SCM_URL_VALID_1));
051        assertEquals("a", ScmUrlUtils.getProvider(SCM_URL_VALID_2));
052        assertEquals("a", ScmUrlUtils.getProvider(SCM_URL_VALID_3));
053        assertEquals("a", ScmUrlUtils.getProvider(SCM_URL_VALID_4));
054    }
055
056    @Test
057    public void testGetProviderSpecificPart() throws Exception {
058        assertEquals("", ScmUrlUtils.getProviderSpecificPart(SCM_URL_VALID_1));
059        assertEquals("", ScmUrlUtils.getProviderSpecificPart(SCM_URL_VALID_2));
060        assertEquals("provider-specific-part", ScmUrlUtils.getProviderSpecificPart(SCM_URL_VALID_3));
061        assertEquals("provider-specific-part", ScmUrlUtils.getProviderSpecificPart(SCM_URL_VALID_4));
062    }
063
064    @Test
065    public void testIsValid() throws Exception {
066        assertTrue(ScmUrlUtils.isValid(SCM_URL_VALID_1));
067        assertTrue(ScmUrlUtils.isValid(SCM_URL_VALID_2));
068        assertTrue(ScmUrlUtils.isValid(SCM_URL_VALID_3));
069        assertFalse(ScmUrlUtils.isValid(SCM_URL_INVALID_1));
070        assertFalse(ScmUrlUtils.isValid(SCM_URL_INVALID_2));
071        assertFalse(ScmUrlUtils.isValid(SCM_URL_INVALID_3));
072        assertFalse(ScmUrlUtils.isValid(SCM_URL_INVALID_4));
073    }
074}