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.TransferFailedException;
23  
24  import java.util.List;
25  
26  import junit.framework.TestCase;
27  
28  public class LSParserTest
29      extends TestCase
30  {
31      public void testParseLinux()
32          throws TransferFailedException
33      {
34          String rawLS = "total 32\n" + "drwxr-xr-x  5 joakim joakim 4096 2006-12-11 10:30 .\n"
35              + "drwxr-xr-x 14 joakim joakim 4096 2006-12-11 10:30 ..\n"
36              + "-rw-r--r--  1 joakim joakim  320 2006-12-09 18:46 .classpath\n"
37              + "-rw-r--r--  1 joakim joakim 1194 2006-12-11 09:25 pom.xml\n"
38              + "-rw-r--r--  1 joakim joakim  662 2006-12-09 18:46 .project\n"
39              + "drwxr-xr-x  4 joakim joakim 4096 2006-11-21 12:26 src\n"
40              + "drwxr-xr-x  4 joakim joakim 4096 2006-11-21 12:26 spaced out\n"
41              + "drwxr-xr-x  7 joakim joakim 4096 2006-12-11 10:31 .svn\n"
42              + "drwxr-xr-x  3 joakim joakim 4096 2006-12-11 08:39 target\n";
43  
44          LSParser parser = new LSParser();
45          List<String> files = parser.parseFiles( rawLS );
46          assertNotNull( files );
47          assertEquals( 9, files.size() );
48          assertTrue( files.contains( "pom.xml" ) );
49          assertTrue( files.contains( "spaced out" ) );
50      }
51  
52      public void testParseOSX() throws TransferFailedException
53      {
54          String rawLS = "total 32\n" + "drwxr-xr-x   5  joakim  joakim   238 Dec 11 10:30 .\n"
55              + "drwxr-xr-x  14  joakim  joakim   518 Dec 11 10:30 ..\n"
56              + "-rw-r--r--   1  joakim  joakim   320 May  9  2006 .classpath\n"
57              + "-rw-r--r--   1  joakim  joakim  1194 Dec 11 09:25 pom.xml\n"
58              + "-rw-r--r--   1  joakim  joakim   662 May  9  2006 .project\n"
59              + "drwxr-xr-x   4  joakim  joakim   204 Dec 11 12:26 src\n"
60              + "drwxr-xr-x   4  joakim  joakim   204 Dec 11 12:26 spaced out\n"
61              + "drwxr-xr-x   7  joakim  joakim   476 Dec 11 10:31 .svn\n"
62              + "drwxr-xr-x   3  joakim  joakim   238 Dec 11 08:39 target\n";
63  
64          LSParser parser = new LSParser();
65          List<String> files = parser.parseFiles( rawLS );
66          assertNotNull( files );
67          assertEquals( 9, files.size() );
68          assertTrue( files.contains( "pom.xml" ) );
69          assertTrue( files.contains( "spaced out" ) );
70      }
71  
72      public void testParseOSXFrLocale() throws TransferFailedException
73      {
74          String rawLS = "total 40\n" + "-rw-r--r--  1 olamy  staff  11 21 sep 00:34 .index.txt\n"
75                  + "-rw-r--r--  1 olamy  staff  19 21 sep 00:34 more-resources.dat\n"
76                  + "-rw-r--r--  1 olamy  staff  20 21 sep 00:34 test-resource b.txt\n"
77                  +"-rw-r--r--  1 olamy  staff  18 21 sep 00:34 test-resource.pom\n"
78                  + "-rw-r--r--  1 olamy  staff  18 21 sep 00:34 test-resource.txt\n";
79  
80          LSParser parser = new LSParser();
81          List<String> files = parser.parseFiles( rawLS );
82          assertNotNull( files );
83          assertEquals( 5, files.size() );
84          assertTrue( files.contains( "more-resources.dat" ) );
85          assertTrue( files.contains( ".index.txt" ) );
86      }
87  
88  
89  
90      public void testParseCygwin() throws TransferFailedException
91      {
92          String rawLS = "total 32\n" + "drwxr-xr-x+  5 joakim None    0 Dec 11 10:30 .\n"
93              + "drwxr-xr-x+ 14 joakim None    0 Dec 11 10:30 ..\n"
94              + "-rw-r--r--+  1 joakim None  320 May  9  2006 .classpath\n"
95              + "-rw-r--r--+  1 joakim None 1194 Dec 11 09:25 pom.xml\n"
96              + "-rw-r--r--+  1 joakim None  662 May  9  2006 .project\n"
97              + "drwxr-xr-x+  4 joakim None    0 Dec 11 12:26 src\n"
98              + "drwxr-xr-x+  4 joakim None    0 Dec 11 12:26 spaced out\n"
99              + "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 }