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