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 sshServerEmbedded; 039 040 @Override 041 protected void setUp() 042 throws Exception 043 { 044 super.setUp(); 045 046 String sshKeyResource = "ssh-keys/id_rsa"; 047 048 sshServerEmbedded = new SshServerEmbedded( getProtocol(), Arrays.asList( sshKeyResource ), false ); 049 050 sshServerEmbedded.start(); 051 System.out.println( "sshd on port " + sshServerEmbedded.getPort() ); 052 } 053 054 @Override 055 protected void tearDownWagonTestingFixtures() 056 throws Exception 057 { 058 059 for ( TestPasswordAuthenticator.PasswordAuthenticatorRequest passwordAuthenticatorRequest : sshServerEmbedded.passwordAuthenticator.passwordAuthenticatorRequests ) 060 { 061 assertEquals( TestData.getUserName(), passwordAuthenticatorRequest.username ); 062 assertEquals( TestData.getUserPassword(), passwordAuthenticatorRequest.password ); 063 } 064 sshServerEmbedded.stop(); 065 } 066 067 protected abstract String getProtocol(); 068 069 @Override 070 protected int getTestRepositoryPort() 071 { 072 return sshServerEmbedded.getPort(); 073 } 074 075 076 public String getTestRepositoryUrl() 077 { 078 return TestData.getTestRepositoryUrl( sshServerEmbedded.getPort() ); 079 } 080 081 protected AuthenticationInfo getAuthInfo() 082 { 083 AuthenticationInfo authInfo = super.getAuthInfo(); 084 085 authInfo.setUserName( TestData.getUserName() ); 086 authInfo.setPassword( TestData.getUserPassword() ); 087 088 return authInfo; 089 } 090 091 protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource ) 092 { 093 return new File( repository.getBasedir(), resource.getName() ).lastModified(); 094 } 095 096 097 @Override 098 protected abstract boolean supportsGetIfNewer(); 099 100}