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