001package org.apache.maven.wagon.providers.file; 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.wagon.ConnectionException; 023import org.apache.maven.wagon.FileTestUtils; 024import org.apache.maven.wagon.StreamingWagonTestCase; 025import org.apache.maven.wagon.Wagon; 026import org.apache.maven.wagon.authentication.AuthenticationException; 027import org.apache.maven.wagon.repository.Repository; 028import org.apache.maven.wagon.resource.Resource; 029 030import java.io.File; 031import java.io.IOException; 032 033/** 034 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 035 * 036 */ 037public class FileWagonTest 038 extends StreamingWagonTestCase 039{ 040 protected String getProtocol() 041 { 042 return "file"; 043 } 044 045 protected String getTestRepositoryUrl() 046 throws IOException 047 { 048 File file = FileTestUtils.createUniqueDir( getName() + ".file-repository." ); 049 050 return "file://" + file.getPath(); 051 } 052 053 @Override 054 protected int getTestRepositoryPort() { 055 // file transfer dont needs a port 056 return 0; 057 } 058 059 /** 060 * This test is introduced to allow for null file wagons. 061 * Which is used heavily in the maven component ITs. 062 * 063 * @throws ConnectionException 064 * @throws AuthenticationException 065 */ 066 public void testNullFileWagon() throws ConnectionException, AuthenticationException 067 { 068 Wagon wagon = new FileWagon(); 069 Resource resource = new Resource(); 070 resource.setContentLength( 100000 ); 071 Repository repository = new Repository(); 072 wagon.connect( repository ); 073 } 074 075 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource ) 076 { 077 return new File( repository.getBasedir(), resource.getName() ).lastModified(); 078 } 079 080 public void testResourceExists() 081 throws Exception 082 { 083 String url = "file://" + getBasedir(); 084 085 Wagon wagon = new FileWagon(); 086 Repository repository = new Repository( "someID", url ); 087 wagon.connect( repository ); 088 089 assertTrue( wagon.resourceExists( "target" ) ); 090 assertTrue( wagon.resourceExists( "target/" ) ); 091 assertTrue( wagon.resourceExists( "pom.xml" ) ); 092 093 assertFalse( wagon.resourceExists( "pom.xml/" ) ); 094 095 wagon.disconnect(); 096 } 097}