View Javadoc

1   package org.apache.maven.wagon.providers.ssh;
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.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   * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
32   *
33   */
34  public abstract class AbstractEmbeddedScpWagonTest
35      extends StreamingWagonTestCase
36  {
37  
38      SshServerEmbedded sshServerEmbedded;
39  
40      @Override
41      protected void setUp()
42          throws Exception
43      {
44          super.setUp();
45  
46          String sshKeyResource = "ssh-keys/id_rsa";
47  
48          sshServerEmbedded = new SshServerEmbedded( getProtocol(), Arrays.asList( sshKeyResource ), false );
49  
50          sshServerEmbedded.start();
51          System.out.println( "sshd on port " + sshServerEmbedded.getPort() );
52      }
53  
54      @Override
55      protected void tearDownWagonTestingFixtures()
56          throws Exception
57      {
58  
59          for ( TestPasswordAuthenticator.PasswordAuthenticatorRequest passwordAuthenticatorRequest : sshServerEmbedded.passwordAuthenticator.passwordAuthenticatorRequests )
60          {
61              assertEquals( TestData.getUserName(), passwordAuthenticatorRequest.username );
62              assertEquals( TestData.getUserPassword(), passwordAuthenticatorRequest.password );
63          }
64          sshServerEmbedded.stop();
65      }
66  
67      protected abstract String getProtocol();
68  
69      @Override
70      protected int getTestRepositoryPort()
71      {
72          return sshServerEmbedded.getPort();
73      }
74  
75  
76      public String getTestRepositoryUrl()
77      {
78          return TestData.getTestRepositoryUrl( sshServerEmbedded.getPort() );
79      }
80  
81      protected AuthenticationInfo getAuthInfo()
82      {
83          AuthenticationInfo authInfo = super.getAuthInfo();
84  
85          authInfo.setUserName( TestData.getUserName() );
86          authInfo.setPassword( TestData.getUserPassword() );
87  
88          return authInfo;
89      }
90  
91      protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
92      {
93          return new File( repository.getBasedir(), resource.getName() ).lastModified();
94      }
95  
96  
97      @Override
98      protected abstract boolean supportsGetIfNewer();
99  
100 }