1 package org.apache.maven.wagon.providers.ftp;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.ftpserver.interfaces.FtpServerInterface;
25 import org.apache.maven.wagon.FileTestUtils;
26 import org.apache.maven.wagon.StreamingWagonTestCase;
27 import org.apache.maven.wagon.Wagon;
28 import org.apache.maven.wagon.authentication.AuthenticationException;
29 import org.apache.maven.wagon.authentication.AuthenticationInfo;
30 import org.apache.maven.wagon.repository.Repository;
31 import org.apache.maven.wagon.resource.Resource;
32 import org.codehaus.plexus.util.FileUtils;
33
34
35
36
37
38 public class FtpWagonTest
39 extends StreamingWagonTestCase
40 {
41 private FtpServerInterface server;
42
43 protected String getProtocol()
44 {
45 return "ftp";
46 }
47
48 protected void setupWagonTestingFixtures()
49 throws Exception
50 {
51 server = (FtpServerInterface) lookup( FtpServerInterface.ROLE );
52 }
53
54 protected void createDirectory( Wagon wagon, String resourceToCreate, String dirName )
55 throws Exception
56 {
57 super.createDirectory( wagon, resourceToCreate, dirName );
58
59 getRepositoryDirectory().mkdirs();
60 }
61
62 protected void tearDownWagonTestingFixtures()
63 throws Exception
64 {
65 release( server );
66 }
67
68 protected String getTestRepositoryUrl()
69 {
70 return "ftp://localhost:10023";
71 }
72
73 public AuthenticationInfo getAuthInfo()
74 {
75 AuthenticationInfo authInfo = new AuthenticationInfo();
76
77 authInfo.setUserName( "admin" );
78
79 authInfo.setPassword( "admin" );
80
81 return authInfo;
82 }
83
84 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
85 {
86 File file = new File( getRepositoryDirectory(), resource.getName() );
87
88
89 return ( file.lastModified() / 60000 ) * 60000;
90 }
91
92 private File getRepositoryDirectory()
93 {
94 return getTestFile( "target/test-output/local-repository" );
95 }
96
97 public void testNoPassword()
98 throws Exception
99 {
100 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
101 authenticationInfo.setUserName( "me" );
102 try
103 {
104 getWagon().connect( new Repository( "id", getTestRepositoryUrl() ), authenticationInfo );
105 fail();
106 }
107 catch ( AuthenticationException e )
108 {
109 assertTrue( true );
110 }
111 }
112
113 public void testDefaultUserName()
114 throws Exception
115 {
116 AuthenticationInfo authenticationInfo = new AuthenticationInfo();
117 authenticationInfo.setPassword( "secret" );
118 try
119 {
120 getWagon().connect( new Repository( "id", getTestRepositoryUrl() ), authenticationInfo );
121 fail();
122 }
123 catch ( AuthenticationException e )
124 {
125 assertEquals( System.getProperty( "user.name" ), authenticationInfo.getUserName() );
126 }
127 }
128 }