View Javadoc

1   package org.apache.maven.wagon.providers.file;
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.wagon.ConnectionException;
23  import org.apache.maven.wagon.FileTestUtils;
24  import org.apache.maven.wagon.StreamingWagonTestCase;
25  import org.apache.maven.wagon.Wagon;
26  import org.apache.maven.wagon.authentication.AuthenticationException;
27  import org.apache.maven.wagon.repository.Repository;
28  import org.apache.maven.wagon.resource.Resource;
29  
30  import java.io.File;
31  import java.io.IOException;
32  
33  /**
34   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
35   *
36   */
37  public class FileWagonTest
38      extends StreamingWagonTestCase
39  {
40      protected String getProtocol()
41      {
42          return "file";
43      }
44  
45      protected String getTestRepositoryUrl()
46          throws IOException
47      {
48          File file = FileTestUtils.createUniqueDir( getName() + ".file-repository." );
49  
50          return "file://" + file.getPath();
51      }
52  
53      @Override
54      protected int getTestRepositoryPort() {
55          // file transfer dont needs a port
56          return 0;
57      }
58  
59      /**
60       * This test is introduced to allow for null file wagons.
61       * Which is used heavily in the maven component ITs.
62       * 
63       * @throws ConnectionException
64       * @throws AuthenticationException
65       */
66      public void testNullFileWagon() throws ConnectionException, AuthenticationException
67      {
68          Wagon wagon = new FileWagon();
69          Resource resource = new Resource();
70          resource.setContentLength( 100000 );
71          Repository repository = new Repository();
72          wagon.connect( repository );
73      }
74  
75      protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
76      {
77          return new File( repository.getBasedir(), resource.getName() ).lastModified();
78      }
79      
80      public void testResourceExists()
81          throws Exception
82      {
83          String url = "file://" + getBasedir();
84          
85          Wagon wagon = new FileWagon();
86          Repository repository = new Repository( "someID", url );
87          wagon.connect( repository );
88          
89          assertTrue( wagon.resourceExists( "target" ) );
90          assertTrue( wagon.resourceExists( "target/" ) );
91          assertTrue( wagon.resourceExists( "pom.xml" ) );
92          
93          assertFalse( wagon.resourceExists( "pom.xml/" ) );
94          
95          wagon.disconnect();
96      }
97  }