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 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  }