KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > url > ApacheURLListerTest


1 /*
2  * This file is subject to the license found in LICENCE.TXT in the root directory of the project.
3  *
4  * #SNAPSHOT#
5  */

6 package fr.jayasoft.ivy.url;
7
8 import junit.framework.TestCase;
9
10 import java.net.URL JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13
14
15 /**
16  * Tests {@link ApacheURLLister}.
17  *
18  * @author Xavier Hanin
19  * @author <a HREF="johnmshields@yahoo.com">John M. Shields</a>
20  */

21 public class ApacheURLListerTest extends TestCase {
22
23     /**
24      * Tests {@link ApacheURLLister#retrieveListing(URL, boolean, boolean)}.
25      *
26      * @throws Exception
27      */

28     public void testRetrieveListing() throws Exception JavaDoc {
29         ApacheURLLister lister = new ApacheURLLister();
30
31         List JavaDoc files = lister.retrieveListing(ApacheURLListerTest.class.getResource("apache-file-listing.html"), true, false);
32         assertNotNull(files);
33         assertTrue(files.size() > 0);
34         for (Iterator JavaDoc iter = files.iterator(); iter.hasNext();) {
35             URL JavaDoc file = (URL JavaDoc) iter.next();
36             assertTrue("found a non matching file: "+file, file.getPath().matches(".*/[^/]+\\.(jar|md5|sha1)"));
37         }
38
39
40         // try a directory listing
41
List JavaDoc dirs = lister.retrieveListing(ApacheURLListerTest.class.getResource("apache-dir-listing.html"), false, true);
42         assertNotNull(dirs);
43         assertEquals(4, dirs.size());
44
45
46         List JavaDoc empty = lister.retrieveListing(ApacheURLListerTest.class.getResource("apache-dir-listing.html"), true, false);
47         assertTrue(empty.isEmpty());
48     }
49     
50     /**
51      * Tests {@link ApacheURLLister#retrieveListing(URL, boolean, boolean)}.
52      *
53      * @throws Exception
54      */

55     public void testRetrieveListingWithSpaces() throws Exception JavaDoc {
56         ApacheURLLister lister = new ApacheURLLister();
57
58         List JavaDoc files = lister.retrieveListing(ApacheURLListerTest.class.getResource("listing-with-spaces.html"), true, false);
59         assertNotNull(files);
60         assertTrue(files.size() > 0);
61     }
62 }
63
Popular Tags