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.TransferFailedException; 023 024import java.util.List; 025 026import junit.framework.TestCase; 027 028public class LSParserTest 029 extends TestCase 030{ 031 public void testParseLinux() 032 throws TransferFailedException 033 { 034 String rawLS = "total 32\n" + "drwxr-xr-x 5 joakim joakim 4096 2006-12-11 10:30 .\n" 035 + "drwxr-xr-x 14 joakim joakim 4096 2006-12-11 10:30 ..\n" 036 + "-rw-r--r-- 1 joakim joakim 320 2006-12-09 18:46 .classpath\n" 037 + "-rw-r--r-- 1 joakim joakim 1194 2006-12-11 09:25 pom.xml\n" 038 + "-rw-r--r-- 1 joakim joakim 662 2006-12-09 18:46 .project\n" 039 + "drwxr-xr-x 4 joakim joakim 4096 2006-11-21 12:26 src\n" 040 + "drwxr-xr-x 4 joakim joakim 4096 2006-11-21 12:26 spaced out\n" 041 + "drwxr-xr-x 7 joakim joakim 4096 2006-12-11 10:31 .svn\n" 042 + "drwxr-xr-x 3 joakim joakim 4096 2006-12-11 08:39 target\n"; 043 044 LSParser parser = new LSParser(); 045 List<String> files = parser.parseFiles( rawLS ); 046 assertNotNull( files ); 047 assertEquals( 9, files.size() ); 048 assertTrue( files.contains( "pom.xml" ) ); 049 assertTrue( files.contains( "spaced out" ) ); 050 } 051 052 public void testParseOSX() throws TransferFailedException 053 { 054 String rawLS = "total 32\n" + "drwxr-xr-x 5 joakim joakim 238 Dec 11 10:30 .\n" 055 + "drwxr-xr-x 14 joakim joakim 518 Dec 11 10:30 ..\n" 056 + "-rw-r--r-- 1 joakim joakim 320 May 9 2006 .classpath\n" 057 + "-rw-r--r-- 1 joakim joakim 1194 Dec 11 09:25 pom.xml\n" 058 + "-rw-r--r-- 1 joakim joakim 662 May 9 2006 .project\n" 059 + "drwxr-xr-x 4 joakim joakim 204 Dec 11 12:26 src\n" 060 + "drwxr-xr-x 4 joakim joakim 204 Dec 11 12:26 spaced out\n" 061 + "drwxr-xr-x 7 joakim joakim 476 Dec 11 10:31 .svn\n" 062 + "drwxr-xr-x 3 joakim joakim 238 Dec 11 08:39 target\n"; 063 064 LSParser parser = new LSParser(); 065 List<String> files = parser.parseFiles( rawLS ); 066 assertNotNull( files ); 067 assertEquals( 9, files.size() ); 068 assertTrue( files.contains( "pom.xml" ) ); 069 assertTrue( files.contains( "spaced out" ) ); 070 } 071 072 public void testParseOSXFrLocale() throws TransferFailedException 073 { 074 String rawLS = "total 40\n" + "-rw-r--r-- 1 olamy staff 11 21 sep 00:34 .index.txt\n" 075 + "-rw-r--r-- 1 olamy staff 19 21 sep 00:34 more-resources.dat\n" 076 + "-rw-r--r-- 1 olamy staff 20 21 sep 00:34 test-resource b.txt\n" 077 +"-rw-r--r-- 1 olamy staff 18 21 sep 00:34 test-resource.pom\n" 078 + "-rw-r--r-- 1 olamy staff 18 21 sep 00:34 test-resource.txt\n"; 079 080 LSParser parser = new LSParser(); 081 List<String> files = parser.parseFiles( rawLS ); 082 assertNotNull( files ); 083 assertEquals( 5, files.size() ); 084 assertTrue( files.contains( "more-resources.dat" ) ); 085 assertTrue( files.contains( ".index.txt" ) ); 086 } 087 088 089 090 public void testParseCygwin() throws TransferFailedException 091 { 092 String rawLS = "total 32\n" + "drwxr-xr-x+ 5 joakim None 0 Dec 11 10:30 .\n" 093 + "drwxr-xr-x+ 14 joakim None 0 Dec 11 10:30 ..\n" 094 + "-rw-r--r--+ 1 joakim None 320 May 9 2006 .classpath\n" 095 + "-rw-r--r--+ 1 joakim None 1194 Dec 11 09:25 pom.xml\n" 096 + "-rw-r--r--+ 1 joakim None 662 May 9 2006 .project\n" 097 + "drwxr-xr-x+ 4 joakim None 0 Dec 11 12:26 src\n" 098 + "drwxr-xr-x+ 4 joakim None 0 Dec 11 12:26 spaced out\n" 099 + "drwxr-xr-x+ 7 joakim None 0 Dec 11 10:31 .svn\n" 100 + "drwxr-xr-x+ 3 joakim None 0 Dec 11 08:39 target\n"; 101 102 LSParser parser = new LSParser(); 103 List<String> files = parser.parseFiles( rawLS ); 104 assertNotNull( files ); 105 assertEquals( 9, files.size() ); 106 assertTrue( files.contains( "pom.xml" ) ); 107 assertTrue( files.contains( "spaced out" ) ); 108 } 109 110 /** 111 * Snicoll, Jvanzyl, and Tom reported problems with wagon-ssh.getFileList(). 112 * Just adding a real-world example of the ls to see if it is a problem. 113 * - Joakime 114 */ 115 public void testParsePeopleApacheStaging() throws TransferFailedException 116 { 117 String rawLS = "total 6\n" 118 + "drwxr-xr-x 3 snicoll snicoll 512 Feb 7 11:04 .\n" 119 + "drwxr-xr-x 3 snicoll snicoll 512 Feb 7 11:04 ..\n" 120 + "drwxr-xr-x 3 snicoll snicoll 512 Feb 7 11:04 org\n" 121 + "drwxr-xr-x 3 snicoll snicoll 512 Feb 7 11:04 spaced out\n"; 122 123 LSParser parser = new LSParser(); 124 List<String> files = parser.parseFiles( rawLS ); 125 assertNotNull( files ); 126 assertEquals( 4, files.size() ); 127 assertTrue( files.contains( "org" ) ); 128 assertTrue( files.contains( "spaced out" ) ); 129 } 130}