Coverage Report - org.apache.maven.wagon.providers.ssh.AbstractEmbeddedScpWagonWithKeyTest
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractEmbeddedScpWagonWithKeyTest
0 %
0/58
0 %
0/6
1,3
 
 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.Wagon;
 24  
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
 25  
 import org.apache.maven.wagon.repository.Repository;
 26  
 import org.apache.maven.wagon.resource.Resource;
 27  
 import org.codehaus.plexus.util.FileUtils;
 28  
 
 29  
 import java.io.File;
 30  
 import java.util.Arrays;
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
 35  
  * @version $Id$
 36  
  */
 37  0
 public abstract class AbstractEmbeddedScpWagonWithKeyTest
 38  
     extends StreamingWagonTestCase
 39  
 {
 40  
 
 41  
     SshServerEmbedded sshServerEmbedded;
 42  
 
 43  
 
 44  
     @Override
 45  
     protected void setUp()
 46  
         throws Exception
 47  
     {
 48  0
         super.setUp();
 49  
 
 50  0
         String sshKeyResource = "ssh-keys/id_rsa.pub";
 51  
 
 52  0
         sshServerEmbedded = new SshServerEmbedded( getProtocol(), Arrays.asList( sshKeyResource ), true );
 53  
 
 54  0
         sshServerEmbedded.start();
 55  0
         System.out.println( "sshd on port " + sshServerEmbedded.getPort() );
 56  0
     }
 57  
 
 58  
     @Override
 59  
     protected void tearDownWagonTestingFixtures()
 60  
         throws Exception
 61  
     {
 62  
 
 63  0
         sshServerEmbedded.stop();
 64  0
     }
 65  
 
 66  
     protected abstract String getProtocol();
 67  
 
 68  
     @Override
 69  
     protected int getTestRepositoryPort()
 70  
     {
 71  0
         return sshServerEmbedded.getPort();
 72  
     }
 73  
 
 74  
 
 75  
     public String getTestRepositoryUrl()
 76  
     {
 77  0
         return TestData.getTestRepositoryUrl( sshServerEmbedded.getPort() );
 78  
     }
 79  
 
 80  
     protected AuthenticationInfo getAuthInfo()
 81  
     {
 82  0
         AuthenticationInfo authInfo = super.getAuthInfo();
 83  
         // user : guest/guest123 -  passphrase : toto01
 84  0
         authInfo.setUserName( "guest" );
 85  
         //authInfo.setPassword( TestData.getUserPassword() );
 86  0
         authInfo.setPrivateKey( new File( "src/test/ssh-keys/id_rsa" ).getPath() );
 87  
 
 88  0
         return authInfo;
 89  
     }
 90  
 
 91  
     protected long getExpectedLastModifiedOnGet( Repository repository, Resource resource )
 92  
     {
 93  0
         return new File( repository.getBasedir(), resource.getName() ).lastModified();
 94  
     }
 95  
 
 96  
     public void testConnect()
 97  
         throws Exception
 98  
     {
 99  0
         getWagon().connect( new Repository( "foo", getTestRepositoryUrl() ), getAuthInfo() );
 100  0
         assertTrue( true );
 101  0
     }
 102  
 
 103  
 
 104  
     @Override
 105  
     protected boolean supportsGetIfNewer()
 106  
     {
 107  0
         return false;
 108  
     }
 109  
 
 110  
     public void testWithSpaces()
 111  
         throws Exception
 112  
     {
 113  0
         String dir = "foo   test";
 114  0
         File spaceDirectory = new File( TestData.getRepoPath(), dir );
 115  0
         if ( spaceDirectory.exists() )
 116  
         {
 117  0
             FileUtils.deleteDirectory( spaceDirectory );
 118  
         }
 119  0
         spaceDirectory.mkdirs();
 120  
 
 121  0
         String subDir = "foo bar";
 122  0
         File sub = new File( spaceDirectory, subDir );
 123  0
         if ( sub.exists() )
 124  
         {
 125  0
             FileUtils.deleteDirectory( sub );
 126  
         }
 127  0
         sub.mkdirs();
 128  
 
 129  0
         File dummy = new File( "src/test/resources/dummy.txt" );
 130  0
         FileUtils.copyFileToDirectory( dummy, sub );
 131  
 
 132  0
         String url = getTestRepositoryUrl() + "/" + dir;
 133  0
         Repository repo = new Repository( "foo", url );
 134  0
         Wagon wagon = getWagon();
 135  0
         wagon.connect( repo, getAuthInfo() );
 136  0
         List<String> files = wagon.getFileList( subDir );
 137  0
         assertNotNull( files );
 138  0
         assertEquals( 1, files.size() );
 139  0
         assertTrue( files.contains( "dummy.txt" ) );
 140  
 
 141  0
         wagon.put( new File( "src/test/resources/dummy.txt" ), subDir + "/newdummy.txt" );
 142  
 
 143  0
         files = wagon.getFileList( subDir );
 144  0
         assertNotNull( files );
 145  0
         assertEquals( 2, files.size() );
 146  0
         assertTrue( files.contains( "dummy.txt" ) );
 147  0
         assertTrue( files.contains( "newdummy.txt" ) );
 148  
 
 149  0
         File sourceWithSpace = new File( "target/directory with spaces" );
 150  0
         if ( sourceWithSpace.exists() )
 151  
         {
 152  0
             FileUtils.deleteDirectory( sourceWithSpace );
 153  
         }
 154  0
         File resources = new File( "src/test/resources" );
 155  
 
 156  0
         FileUtils.copyDirectory( resources, sourceWithSpace );
 157  
 
 158  0
         wagon.putDirectory( sourceWithSpace, "target with spaces" );
 159  
 
 160  0
         files = wagon.getFileList( "target with spaces" );
 161  
 
 162  0
         assertNotNull( files );
 163  0
         assertTrue( files.contains( "dummy.txt" ) );
 164  0
         assertFalse( files.contains( "newdummy.txt" ) );
 165  0
         assertTrue( files.contains( "log4j.xml" ) );
 166  0
     }
 167  
 
 168  
 }