001package org.apache.maven.scm.provider.starteam.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.repository.ScmRepository;
024import org.apache.maven.scm.repository.ScmRepositoryException;
025
026/**
027 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
028 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
029 *
030 */
031public class StarteamScmProviderRepositoryTest
032    extends ScmTestCase
033{
034    public void testParseConnection()
035        throws Exception
036    {
037        testUrl( "scm:starteam:myhost:1234/projecturl", null, null, "myhost", 1234, "/projecturl" );
038    }
039
040    public void testParseConnectionWithUsername()
041        throws Exception
042    {
043        testUrl( "scm:starteam:myusername@myhost:1234/projecturl", "myusername", null, "myhost", 1234, "/projecturl" );
044    }
045
046    public void testParseConnectionWithUsernameAndPassword()
047        throws Exception
048    {
049        testUrl( "scm:starteam:myusername:mypassword@myhost:1234/projecturl", "myusername", "mypassword", "myhost",
050                 1234, "/projecturl" );
051    }
052
053    public void testParseConnection2()
054        throws Exception
055    {
056        testUrl( "scm:starteam:myhost:1234:/projecturl", null, null, "myhost", 1234, "/projecturl" );
057    }
058
059    public void testParseConnectionWithUsername2()
060        throws Exception
061    {
062        testUrl( "scm:starteam:myusername@myhost:1234:/projecturl", "myusername", null, "myhost", 1234, "/projecturl" );
063    }
064
065    public void testParseConnectionWithUsernameAndPassword2()
066        throws Exception
067    {
068        testUrl( "scm:starteam:myusername:mypassword@myhost:1234:/projecturl", "myusername", "mypassword", "myhost",
069                 1234, "/projecturl" );
070    }
071
072    public void testInvalidConnection()
073        throws Exception
074    {
075        testIllegalUrl( "scm:starteam:invalidConnectionString" );
076    }
077
078    // ----------------------------------------------------------------------
079    //
080    // ----------------------------------------------------------------------
081
082    private void testUrl( String url, String expectedUser, String expectedPassword, String expectedHost,
083                          int expectedPort, String expectedPath )
084        throws Exception
085    {
086        ScmRepository repository = getScmManager().makeScmRepository( url );
087
088        assertNotNull( "ScmManager.makeScmRepository() returned null", repository );
089
090        assertNotNull( "The provider repository was null.", repository.getProviderRepository() );
091
092        assertTrue( "The SCM Repository isn't a " + StarteamScmProviderRepository.class.getName() + ".", repository
093            .getProviderRepository() instanceof StarteamScmProviderRepository );
094
095        StarteamScmProviderRepository repo = (StarteamScmProviderRepository) repository.getProviderRepository();
096
097        assertEquals( expectedUser, repo.getUser() );
098
099        assertEquals( expectedPassword, repo.getPassword() );
100
101        assertEquals( expectedHost, repo.getHost() );
102
103        assertEquals( expectedPort, repo.getPort() );
104
105        assertEquals( expectedPath, repo.getPath() );
106    }
107
108    private void testIllegalUrl( String url )
109        throws Exception
110    {
111        try
112        {
113            getScmManager().makeScmRepository( url );
114
115            fail( "Expected a ScmRepositoryException while testing the url '" + url + "'." );
116        }
117        catch ( ScmRepositoryException e )
118        {
119            // expected
120        }
121    }
122}