001package org.apache.maven.wagon.providers.ssh; 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.StreamingWagonTestCase; 023import org.apache.maven.wagon.authentication.AuthenticationInfo; 024import org.apache.maven.wagon.repository.Repository; 025import org.apache.maven.wagon.resource.Resource; 026 027import java.io.File; 028import java.util.Arrays; 029 030/** 031 * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a> 032 * 033 */ 034public abstract class AbstractEmbeddedScpWagonTest 035 extends StreamingWagonTestCase 036{ 037 038 SshServerEmbedded sshServer; 039 040 @Override 041 protected void setUp() 042 throws Exception 043 { 044 super.setUp(); 045 046 String sshKeyResource = "ssh-keys/id_rsa"; 047 048 sshServer = new SshServerEmbedded( getProtocol(), Arrays.asList( sshKeyResource ), false ); 049 050 sshServer.start(); 051 System.out.println( "sshd on port " + sshServer.getPort() ); 052 } 053 054 @Override 055 @SuppressWarnings( "checkstyle:linelength" ) 056 protected void tearDownWagonTestingFixtures() 057 throws Exception 058 { 059 060 for ( TestPasswordAuthenticator.PasswordAuthenticatorRequest request : sshServer.passwordAuthenticator.requests ) 061 { 062 assertEquals( TestData.getUserName(), request.getUsername() ); 063 assertEquals( TestData.getUserPassword(), request.getPassword() ); 064 } 065 sshServer.stop(); 066 } 067 068 protected abstract String getProtocol(); 069 070 protected int getTestRepositoryPort() 071 { 072 return sshServer.getPort(); 073 } 074 075 public String getTestRepositoryUrl() 076 { 077 return TestData.getTestRepositoryUrl( sshServer.getPort() ); 078 } 079 080 protected AuthenticationInfo getAuthInfo() 081 { 082 AuthenticationInfo authInfo = super.getAuthInfo(); 083 084 authInfo.setUserName( TestData.getUserName() ); 085 authInfo.setPassword( TestData.getUserPassword() ); 086 087 return authInfo; 088 } 089 090 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource ) 091 { 092 return new File( repository.getBasedir(), resource.getName() ).lastModified(); 093 } 094 095 096 @Override 097 protected abstract boolean supportsGetIfNewer(); 098 099}