001package org.apache.maven.scm.provider.integrity.repository;
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
022import org.apache.maven.scm.ScmTestCase;
023import org.apache.maven.scm.manager.ScmManager;
024import org.apache.maven.scm.repository.ScmRepository;
025
026/**
027 * IntegrityScmProviderRepositoryTest
028 *
029 * @author <a href="mailto:cletus@mks.com">Cletus D'Souza</a>
030 */
031public class IntegrityScmProviderRepositoryTest
032    extends ScmTestCase
033{
034    private ScmManager scmManager;
035
036    /**
037     * Initialize our ScmManager object
038     */
039    public void setUp()
040        throws Exception
041    {
042        super.setUp();
043        scmManager = getScmManager();
044    }
045
046    /**
047     * Executes a test with the bare minimum required for the Integrity Scm URL String
048     *
049     * @throws Exception
050     */
051    public void testMinimumUrlString()
052        throws Exception
053    {
054        // Minimum url string
055        testValidUrl( "scm:integrity|#/repo/project", "#/repo/project", "", 0, "", "" );
056    }
057
058    /**
059     * Executes a test with only the hostname specified
060     *
061     * @throws Exception
062     */
063    public void testWithHostname()
064        throws Exception
065    {
066        // Test with host
067        testValidUrl( "scm:integrity|@localhost|#/repo/project", "#/repo/project", "localhost", 0, "", "" );
068    }
069
070    /**
071     * Executes a test with only the hostname and port specified
072     *
073     * @throws Exception
074     */
075    public void testWithHostAndPort()
076        throws Exception
077    {
078        // Test host and port
079        testValidUrl( "scm:integrity|@localhost:7001|#/repo/project", "#/repo/project", "localhost", 7001, "", "" );
080    }
081
082    /**
083     * Executes a test with only the username specified
084     *
085     * @throws Exception
086     */
087    public void testWithUser()
088        throws Exception
089    {
090        // Test with user
091        testValidUrl( "scm:integrity|dsouza@|#/repo/project", "#/repo/project", "", 0, "dsouza", "" );
092    }
093
094    /**
095     * Executes a test with the username and password specified
096     *
097     * @throws Exception
098     */
099    public void testWithUserAndPassword()
100        throws Exception
101    {
102        // Test with user and password
103        testValidUrl( "scm:integrity|dsouza/password@|#/repo/project", "#/repo/project", "", 0, "dsouza", "password" );
104    }
105
106    /**
107     * Executes a test with the username and hostname specified
108     *
109     * @throws Exception
110     */
111    public void testWithUserAndHost()
112        throws Exception
113    {
114        // Test with user and host
115        testValidUrl( "scm:integrity|dsouza@localhost|#/repo/project", "#/repo/project", "localhost", 0, "dsouza", "" );
116    }
117
118    /**
119     * Executes a test with the username and hostname plus port specified
120     *
121     * @throws Exception
122     */
123    public void testWithUserAndHostPort()
124        throws Exception
125    {
126        // Test with user and host:port
127        testValidUrl( "scm:integrity|dsouza@localhost:7001|#/repo/project", "#/repo/project", "localhost", 7001,
128                      "dsouza", "" );
129    }
130
131    /**
132     * Executes a test with the username and password plus hostname specified
133     *
134     * @throws Exception
135     */
136    public void testWithUserPasswordAndHost()
137        throws Exception
138    {
139        // Test with user/password and host
140        testValidUrl( "scm:integrity|dsouza/password@localhost|#/repo/project", "#/repo/project", "localhost", 0,
141                      "dsouza", "password" );
142    }
143
144    /**
145     * Executes a test with all the components of the SCM URL string specified
146     *
147     * @throws Exception
148     */
149    public void testWithWholeURL()
150        throws Exception
151    {
152        // Test with the complete url
153        testValidUrl( "scm:integrity|dsouza/password@localhost:7001|#/repo/project", "#/repo/project", "localhost",
154                      7001, "dsouza", "password" );
155    }
156
157    /**
158     * Tests the various components of the Integrity SCM URL
159     *
160     * @param scmUrl             Integrity SCM URL
161     * @param expectedConfigPath Expected Configuration Path
162     * @param expectedHost       Expected Hostname
163     * @param expectedPort       Expected Port
164     * @param expectedUser       Expected Username
165     * @param expectedPassword   Expected Password
166     * @throws Exception
167     */
168    private void testValidUrl( String scmUrl, String expectedConfigPath, String expectedHost, int expectedPort,
169                               String expectedUser, String expectedPassword )
170        throws Exception
171    {
172        ScmRepository repo = scmManager.makeScmRepository( scmUrl );
173        assertNotNull( "ScmManager.makeScmRepository() returned null", repo );
174        assertNotNull( "The provider repository was null.", repo.getProviderRepository() );
175        assertTrue( "The SCM Repository isn't a " + IntegrityScmProviderRepository.class.getName() + ".",
176                    repo.getProviderRepository() instanceof IntegrityScmProviderRepository );
177        IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repo.getProviderRepository();
178        assertEquals( "Configration Path is incorrect", expectedConfigPath, iRepo.getConfigruationPath() );
179        assertEquals( "Hostname is incorrect", expectedHost, iRepo.getHost() );
180        assertEquals( "Port is incorrect", expectedPort, iRepo.getPort() );
181        assertEquals( "Username is incorrect", expectedUser, iRepo.getUser() );
182        assertEquals( "Password is incorrect", expectedPassword, iRepo.getPassword() );
183    }
184}