001package org.apache.maven.scm.provider.accurev;
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 static org.apache.maven.scm.provider.accurev.AccuRevScmProviderRepositoryMatcher.isRepo;
023import static org.hamcrest.Matchers.is;
024import static org.junit.Assert.assertThat;
025
026import org.apache.maven.scm.repository.ScmRepositoryException;
027import org.junit.Test;
028
029public class AccurevScmProviderTest
030{
031
032    @Test
033    public void testMakeProviderScmRepository()
034        throws Exception
035    {
036
037        // [:stream][:/project/dir]
038        assertAccurevRepo( "", null, null );
039        assertAccurevRepo( "aStream:/project/dir", "aStream", "project/dir" );
040        assertAccurevRepo( "/project/dir", null, "project/dir" );
041        assertAccurevRepo( "my_QA_Stream", "my_QA_Stream", null );
042
043    }
044
045    private static void assertAccurevRepo( String url, String expStream, String expPath )
046        throws ScmRepositoryException
047    {
048        AccuRevScmProvider provider = new AccuRevScmProvider();
049
050        AccuRevScmProviderRepository repository =
051            (AccuRevScmProviderRepository) provider.makeProviderScmRepository( url, ':' );
052
053        assertThat( repository, isRepo( null, null, null, AccuRev.DEFAULT_PORT, expStream, expPath ) );
054
055    }
056
057    @Test
058    public void testMakeProviderWithBothKindsOfDirectorySeparators()
059        throws ScmRepositoryException
060    {
061        assertThat( getRepo( "aStream:\\project\\dir" ), isRepo( null, null, null, 5050, "aStream", "project\\dir" ) );
062    }
063
064    @Test
065    public void testProviderWithHostPort()
066        throws Exception
067    {
068
069        assertThat( getRepo( "@myHost:aStream:/project/dir" ), isRepo( null, null, "myHost", AccuRev.DEFAULT_PORT,
070                                                                       "aStream", "project/dir" ) );
071        assertThat( getRepo( "@myHost:5051:/project/dir" ), isRepo( null, null, "myHost", 5051, null, "project/dir" ) );
072    }
073
074    @Test
075    public void testBlankAsUsedInTckTests()
076        throws ScmRepositoryException
077    {
078        assertThat( getRepo( ":aDepotStream" ), isRepo( null, null, null, 5050, "aDepotStream", null ) );
079    }
080
081    @Test
082    public void testProviderWithUserPass()
083        throws Exception
084    {
085        assertThat( getRepo( "aUser/theirPassword:/project/dir" ), isRepo( "aUser", "theirPassword", null,
086                                                                           AccuRev.DEFAULT_PORT, null, "project/dir" ) );
087
088        assertThat( getRepo( "aUser/theirPassword@theHost:5051:aStream:/project/dir" ), isRepo( "aUser",
089                                                                                                "theirPassword",
090                                                                                                "theHost", 5051,
091                                                                                                "aStream",
092                                                                                                "project/dir" ) );
093
094        assertThat( getRepo( "aUser@theHost:5050:aStream" ), isRepo( "aUser", null, "theHost", 5050, "aStream", null ) );
095
096        assertThat( getRepo( "aUser/" ), isRepo( "aUser", null, null, 5050, null, null ) );
097    }
098
099    @Test
100    public void testProviderWithProperties()
101        throws Exception
102    {
103        AccuRevScmProviderRepository repo =
104            getRepo( "aUser/theirPassword@theHost:5051:aStream:?tagFormat='depot_%s'&accurevExe=/opt/accurev/bin/accurev:/project/dir" );
105
106        assertThat( repo, isRepo( "aUser", "theirPassword", "theHost", 5051, "aStream", "project/dir" ) );
107        assertThat( repo.getAccuRev().getExecutable(), is( "/opt/accurev/bin/accurev" ) );
108        assertThat( repo.getTagFormat(), is( "depot_%s" ) );
109    }
110
111    @Test
112    public void testProviderWithSystemProperties()
113        throws Exception
114    {
115        String tagFormatProperty = AccuRevScmProvider.SYSTEM_PROPERTY_PREFIX + AccuRevScmProvider.TAG_FORMAT_PROPERTY;
116        System.setProperty( tagFormatProperty, "depot_%s" );
117        String exeProperty = AccuRevScmProvider.SYSTEM_PROPERTY_PREFIX + AccuRevScmProvider.ACCUREV_EXECUTABLE_PROPERTY;
118        System.setProperty( exeProperty, "/expect/overide" );
119
120        AccuRevScmProviderRepository repo =
121            getRepo( "aUser/theirPassword@theHost:5051:aStream:?accurevExe=/opt/accurev/bin/accurev:/project/dir" );
122
123        assertThat( repo, isRepo( "aUser", "theirPassword", "theHost", 5051, "aStream", "project/dir" ) );
124        assertThat( repo.getAccuRev().getExecutable(), is( "/opt/accurev/bin/accurev" ) );
125        assertThat( repo.getTagFormat(), is( "depot_%s" ) );
126
127        System.clearProperty( tagFormatProperty );
128        System.clearProperty( exeProperty );
129    }
130
131    private static AccuRevScmProviderRepository getRepo( String url )
132        throws ScmRepositoryException
133    {
134        AccuRevScmProviderRepository repo =
135            (AccuRevScmProviderRepository) new AccuRevScmProvider().makeProviderScmRepository( url, ':' );
136        return repo;
137    }
138
139    @Test
140    public void testGetSCMType()
141    {
142
143        assertThat( ( new AccuRevScmProvider() ).getScmType(), is( "accurev" ) );
144    }
145}