1 package org.apache.maven.wagon.providers.ssh;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.wagon.StreamingWagonTestCase;
23 import org.apache.maven.wagon.authentication.AuthenticationInfo;
24 import org.apache.maven.wagon.repository.Repository;
25 import org.apache.maven.wagon.resource.Resource;
26
27 import java.io.File;
28 import java.util.Arrays;
29
30
31
32
33
34 public abstract class AbstractEmbeddedScpWagonTest
35 extends StreamingWagonTestCase
36 {
37
38 SshServerEmbedded sshServer;
39
40 @Override
41 protected void setUp()
42 throws Exception
43 {
44 super.setUp();
45
46 String sshKeyResource = "ssh-keys/id_rsa";
47
48 sshServer = new SshServerEmbedded( getProtocol(), Arrays.asList( sshKeyResource ), false );
49
50 sshServer.start();
51 System.out.println( "sshd on port " + sshServer.getPort() );
52 }
53
54 @Override
55 @SuppressWarnings( "checkstyle:linelength" )
56 protected void tearDownWagonTestingFixtures()
57 throws Exception
58 {
59
60 for ( TestPasswordAuthenticator.PasswordAuthenticatorRequest request : sshServer.passwordAuthenticator.requests )
61 {
62 assertEquals( TestData.getUserName(), request.getUsername() );
63 assertEquals( TestData.getUserPassword(), request.getPassword() );
64 }
65 sshServer.stop();
66 }
67
68 protected abstract String getProtocol();
69
70 protected int getTestRepositoryPort()
71 {
72 return sshServer.getPort();
73 }
74
75 public String getTestRepositoryUrl()
76 {
77 return TestData.getTestRepositoryUrl( sshServer.getPort() );
78 }
79
80 protected AuthenticationInfo getAuthInfo()
81 {
82 AuthenticationInfo authInfo = super.getAuthInfo();
83
84 authInfo.setUserName( TestData.getUserName() );
85 authInfo.setPassword( TestData.getUserPassword() );
86
87 return authInfo;
88 }
89
90 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
91 {
92 return new File( repository.getBasedir(), resource.getName() ).lastModified();
93 }
94
95
96 @Override
97 protected abstract boolean supportsGetIfNewer();
98
99 }