View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.scm.provider.local.repository;
20  
21  import org.apache.maven.scm.ScmTestCase;
22  import org.apache.maven.scm.provider.ScmProviderRepository;
23  import org.apache.maven.scm.repository.ScmRepository;
24  import org.apache.maven.scm.repository.ScmRepositoryException;
25  import org.codehaus.plexus.util.FileUtils;
26  import org.junit.Before;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertNotNull;
31  import static org.junit.Assert.assertTrue;
32  import static org.junit.Assert.fail;
33  
34  /**
35   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
36   *
37   */
38  public class LocalRepositoryTest extends ScmTestCase {
39      @Before
40      @Override
41      public void setUp() throws Exception {
42          super.setUp();
43  
44          FileUtils.mkdir(getWorkingDirectory().getAbsolutePath());
45      }
46  
47      @Test
48      public void testExistingRepository() throws Exception {
49          ScmRepository repository = getScmManager().makeScmRepository("scm:local:src/test/repository:test-repo");
50  
51          assertNotNull(repository);
52  
53          assertEquals("local", repository.getProvider());
54  
55          ScmProviderRepository providerRepository = repository.getProviderRepository();
56  
57          assertNotNull(providerRepository);
58  
59          assertTrue(providerRepository instanceof LocalScmProviderRepository);
60  
61          LocalScmProviderRepository local = (LocalScmProviderRepository) providerRepository;
62  
63          assertEquals(getTestFile("src/test/repository").getAbsolutePath(), local.getRoot());
64  
65          assertEquals("test-repo", local.getModule());
66      }
67  
68      @Test
69      public void testMissingRepositoryRoot() throws Exception {
70          try {
71              getScmManager().makeScmRepository("scm:local:");
72  
73              fail("Expected ScmRepositoryException.");
74          } catch (ScmRepositoryException ex) {
75              // expected
76          }
77      }
78  
79      @Test
80      public void testNonExistingMissingRepositoryRoot() throws Exception {
81          try {
82              getScmManager().makeScmRepository("scm:local:non-existing-directory:module");
83  
84              fail("Expected ScmRepositoryException.");
85          } catch (ScmRepositoryException ex) {
86              // expected
87          }
88      }
89  
90      @Test
91      public void testMissingModule() throws Exception {
92          try {
93              getScmManager().makeScmRepository("scm:local:src/test/repository");
94  
95              fail("Expected ScmRepositoryException.");
96          } catch (ScmRepositoryException ex) {
97              // expected
98          }
99  
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 }