001package org.apache.maven.scm.provider.local.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.provider.ScmProviderRepository;
024import org.apache.maven.scm.repository.ScmRepository;
025import org.apache.maven.scm.repository.ScmRepositoryException;
026import org.codehaus.plexus.util.FileUtils;
027
028/**
029 * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
030 *
031 */
032public class LocalRepositoryTest
033    extends ScmTestCase
034{
035    public void setUp()
036        throws Exception
037    {
038        super.setUp();
039
040        FileUtils.mkdir( getWorkingDirectory().getAbsolutePath() );
041    }
042
043    public void testExistingRepository()
044        throws Exception
045    {
046        ScmRepository repository = getScmManager().makeScmRepository( "scm:local:src/test/repository:test-repo" );
047
048        assertNotNull( repository );
049
050        assertEquals( "local", repository.getProvider() );
051
052//        assertEquals( "src/test/repositories:test-repo", repository.getScmSpecificUrl() );
053
054        ScmProviderRepository providerRepository = repository.getProviderRepository();
055
056        assertNotNull( providerRepository );
057
058        assertTrue( providerRepository instanceof LocalScmProviderRepository );
059
060        LocalScmProviderRepository local = (LocalScmProviderRepository) providerRepository;
061
062        assertEquals( getTestFile( "src/test/repository" ).getAbsolutePath(), local.getRoot() );
063
064        assertEquals( "test-repo", local.getModule() );
065    }
066
067    public void testMissingRepositoryRoot()
068        throws Exception
069    {
070        try
071        {
072            getScmManager().makeScmRepository( "scm:local:" );
073
074            fail( "Expected ScmRepositoryException." );
075        }
076        catch ( ScmRepositoryException ex )
077        {
078            // expected
079        }
080    }
081
082    public void testNonExistingMissingRepositoryRoot()
083        throws Exception
084    {
085        try
086        {
087            getScmManager().makeScmRepository( "scm:local:non-existing-directory:module" );
088
089            fail( "Expected ScmRepositoryException." );
090        }
091        catch ( ScmRepositoryException ex )
092        {
093            // expected
094        }
095    }
096
097    public void testMissingModule()
098        throws Exception
099    {
100        try
101        {
102            getScmManager().makeScmRepository( "scm:local:src/test/repository" );
103
104            fail( "Expected ScmRepositoryException." );
105        }
106        catch ( ScmRepositoryException ex )
107        {
108            // expected
109        }
110
111        try
112        {
113            getScmManager().makeScmRepository( "scm:local:src/test/repository:" );
114
115            fail( "Expected ScmRepositoryException." );
116        }
117        catch ( ScmRepositoryException ex )
118        {
119            // expected
120        }
121    }
122
123
124    public void testNonExistingModule()
125        throws Exception
126    {
127        try
128        {
129            getScmManager().makeScmRepository( "scm:local:src/test/repository:non-existing-module" );
130
131            fail( "Expected ScmRepositoryException." );
132        }
133        catch ( ScmRepositoryException ex )
134        {
135            // expected
136        }
137    }
138
139    protected String getScmUrl()
140    {
141        return "scm:local|" + getRepository() + "|" + getModule();
142    }
143}