001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.util.test;
023:
024: import java.net.URL;
025: import java.util.Collection;
026: import java.util.Iterator;
027:
028: import org.jboss.net.protocol.file.FileURLLister;
029: import org.jboss.test.JBossTestCase;
030:
031: /**
032: * FileURLLister tests
033: *
034: * @author <a href="dimitris@jboss.org">Dimitris Andreadis</a>
035: * @version $Revision: 57211 $
036: **/
037: public class FileURLListerUnitTestCase extends JBossTestCase {
038: public FileURLListerUnitTestCase(String name) {
039: super (name);
040: }
041:
042: public void testListDeployLikeDirStructureDontRecurse()
043: throws Exception {
044: getLog().debug("+++ testListDeployLikeDirStructureDontRecurse");
045:
046: String baseUrlString = super
047: .getResourceURL("util/fileurllister/deploy/");
048: URL baseUrl = new URL(baseUrlString);
049:
050: FileURLLister lister = new FileURLLister();
051: Collection files = lister.listMembers(baseUrl, "*", false);
052:
053: logResult(files);
054:
055: String[] expected = new String[] { "dotted.sub.dir/",
056: "nondottedsubdir/", "one.xml", "two.xml" };
057:
058: checkResult(files, baseUrlString, expected);
059: }
060:
061: public void testListDeployLikeDirStructureRecurse()
062: throws Exception {
063: getLog().debug("+++ testListDeployLikeDirStructureRecurse");
064:
065: String baseUrlString = super
066: .getResourceURL("util/fileurllister/deploy/");
067: URL baseUrl = new URL(baseUrlString);
068:
069: FileURLLister lister = new FileURLLister();
070: Collection files = lister.listMembers(baseUrl, "*", true);
071:
072: logResult(files);
073:
074: String[] expected = new String[] { "dotted.sub.dir/",
075: "nondottedsubdir/three.xml", "one.xml", "two.xml", };
076:
077: checkResult(files, baseUrlString, expected);
078: }
079:
080: public void testListDeployLikeDirStructureDontRecurseWithFilter()
081: throws Exception {
082: getLog()
083: .debug(
084: "+++ testListDeployLikeDirStructureDontRecurseWithFilter");
085:
086: String baseUrlString = super
087: .getResourceURL("util/fileurllister/deploy/");
088: URL baseUrl = new URL(baseUrlString);
089:
090: FileURLLister lister = new FileURLLister();
091: Collection files = lister.listMembers(baseUrl,
092: "one.xml,nondottedsubdir,three.xml", false);
093:
094: logResult(files);
095:
096: String[] expected = new String[] { "nondottedsubdir/",
097: "one.xml" };
098:
099: checkResult(files, baseUrlString, expected);
100: }
101:
102: public void testListDeployLikeDirStructureRecurseWithFilter()
103: throws Exception {
104: getLog().debug(
105: "+++ testListDeployLikeDirStructureRecurseWithFilter");
106:
107: String baseUrlString = super
108: .getResourceURL("util/fileurllister/deploy/");
109: URL baseUrl = new URL(baseUrlString);
110:
111: FileURLLister lister = new FileURLLister();
112: Collection files = lister.listMembers(baseUrl,
113: "one.xml,nondottedsubdir,three.xml", true);
114:
115: logResult(files);
116:
117: String[] expected = new String[] { "nondottedsubdir/three.xml",
118: "one.xml" };
119:
120: checkResult(files, baseUrlString, expected);
121: }
122:
123: private void logResult(Collection result) {
124: for (Iterator i = result.iterator(); i.hasNext();) {
125: URL url = (URL) i.next();
126: getLog().debug(url.toString());
127: }
128: }
129:
130: private void checkResult(Collection result, String baseUrlString,
131: String[] expected) throws Exception {
132: assertTrue("result.size(" + result.size()
133: + ") != expected.length(" + expected.length + ")",
134: result.size() == expected.length);
135:
136: for (int i = 0; i < expected.length; i++) {
137: URL excepted = new URL(baseUrlString + expected[i]);
138: assertTrue("Expected URL: " + excepted, result
139: .contains(excepted));
140: }
141: }
142: }
|