1832 |
03 Jul 07 |
gregory |
1 |
/* |
1832 |
03 Jul 07 |
gregory |
$Id: code_templates.xml 1319 2007-03-01 10:22:22Z gregory $ |
1832 |
03 Jul 07 |
gregory |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
1832 |
03 Jul 07 |
gregory |
5 |
|
1832 |
03 Jul 07 |
gregory |
Files are copyright by their respective authors. The contributions to |
1832 |
03 Jul 07 |
gregory |
files where copyright is not explicitly stated can be traced with the |
1832 |
03 Jul 07 |
gregory |
source code revision system. |
1832 |
03 Jul 07 |
gregory |
9 |
|
1832 |
03 Jul 07 |
gregory |
This file is part of Proteios. |
1832 |
03 Jul 07 |
gregory |
Available at http://www.proteios.org/ |
1832 |
03 Jul 07 |
gregory |
12 |
|
1832 |
03 Jul 07 |
gregory |
Proteios is free software; you can redistribute it and/or |
1832 |
03 Jul 07 |
gregory |
modify it under the terms of the GNU General Public License |
1832 |
03 Jul 07 |
gregory |
as published by the Free Software Foundation; either version 2 |
1832 |
03 Jul 07 |
gregory |
of the License, or (at your option) any later version. |
1832 |
03 Jul 07 |
gregory |
17 |
|
1832 |
03 Jul 07 |
gregory |
Proteios is distributed in the hope that it will be useful, |
1832 |
03 Jul 07 |
gregory |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1832 |
03 Jul 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1832 |
03 Jul 07 |
gregory |
GNU General Public License for more details. |
1832 |
03 Jul 07 |
gregory |
22 |
|
1832 |
03 Jul 07 |
gregory |
You should have received a copy of the GNU General Public License |
1832 |
03 Jul 07 |
gregory |
along with this program; if not, write to the Free Software |
1832 |
03 Jul 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, |
1832 |
03 Jul 07 |
gregory |
Boston, MA 02111-1307, USA. |
1832 |
03 Jul 07 |
gregory |
27 |
*/ |
1832 |
03 Jul 07 |
gregory |
28 |
package org.proteios; |
1832 |
03 Jul 07 |
gregory |
29 |
|
1842 |
04 Jul 07 |
gregory |
30 |
import static org.junit.Assert.assertEquals; |
1842 |
04 Jul 07 |
gregory |
31 |
import static org.junit.Assert.assertNotNull; |
1842 |
04 Jul 07 |
gregory |
32 |
import org.junit.Before; |
1832 |
03 Jul 07 |
gregory |
33 |
import org.junit.Test; |
1832 |
03 Jul 07 |
gregory |
34 |
import java.io.File; |
1832 |
03 Jul 07 |
gregory |
35 |
import java.net.MalformedURLException; |
1832 |
03 Jul 07 |
gregory |
36 |
import java.net.URI; |
1832 |
03 Jul 07 |
gregory |
37 |
import java.net.URISyntaxException; |
1832 |
03 Jul 07 |
gregory |
38 |
import java.net.URL; |
1832 |
03 Jul 07 |
gregory |
39 |
import java.util.List; |
1842 |
04 Jul 07 |
gregory |
40 |
import java.util.jar.JarEntry; |
1832 |
03 Jul 07 |
gregory |
41 |
import java.util.regex.Pattern; |
1832 |
03 Jul 07 |
gregory |
42 |
|
1832 |
03 Jul 07 |
gregory |
43 |
/** |
1832 |
03 Jul 07 |
gregory |
* @author gregory |
1832 |
03 Jul 07 |
gregory |
45 |
*/ |
1832 |
03 Jul 07 |
gregory |
46 |
public class FileLocatorTest |
1832 |
03 Jul 07 |
gregory |
47 |
{ |
1832 |
03 Jul 07 |
gregory |
48 |
/** |
1832 |
03 Jul 07 |
gregory |
* The test properties |
1832 |
03 Jul 07 |
gregory |
50 |
*/ |
1832 |
03 Jul 07 |
gregory |
51 |
private PropertiesFile2 conf = null; |
1842 |
04 Jul 07 |
gregory |
52 |
private File dir = null; |
1832 |
03 Jul 07 |
gregory |
53 |
|
1832 |
03 Jul 07 |
gregory |
54 |
|
1832 |
03 Jul 07 |
gregory |
55 |
/** |
1842 |
04 Jul 07 |
gregory |
* Loads the properties file |
1842 |
04 Jul 07 |
gregory |
57 |
*/ |
1842 |
04 Jul 07 |
gregory |
58 |
@Before |
1842 |
04 Jul 07 |
gregory |
59 |
public void setUp() |
1842 |
04 Jul 07 |
gregory |
60 |
throws MalformedURLException, URISyntaxException |
1842 |
04 Jul 07 |
gregory |
61 |
{ |
1842 |
04 Jul 07 |
gregory |
62 |
conf = new PropertiesFile2(); |
1842 |
04 Jul 07 |
gregory |
63 |
String testDataDir = conf.getProperty(PropertiesFile2.TEST_DATA); |
1842 |
04 Jul 07 |
gregory |
64 |
URL extensionsDir; |
1842 |
04 Jul 07 |
gregory |
65 |
extensionsDir = new URL(testDataDir); |
1842 |
04 Jul 07 |
gregory |
66 |
URI uri = extensionsDir.toURI(); |
1842 |
04 Jul 07 |
gregory |
67 |
dir = new File(uri); |
1842 |
04 Jul 07 |
gregory |
68 |
} |
1842 |
04 Jul 07 |
gregory |
69 |
|
1842 |
04 Jul 07 |
gregory |
70 |
|
1842 |
04 Jul 07 |
gregory |
71 |
/** |
1832 |
03 Jul 07 |
gregory |
* Test method for |
1832 |
03 Jul 07 |
gregory |
* {@link org.proteios.FileLocator#find(java.io.File, boolean, java.util.regex.Pattern)}. |
1832 |
03 Jul 07 |
gregory |
74 |
*/ |
1832 |
03 Jul 07 |
gregory |
75 |
@Test |
1832 |
03 Jul 07 |
gregory |
76 |
public void testFind() |
1832 |
03 Jul 07 |
gregory |
77 |
{ |
1832 |
03 Jul 07 |
gregory |
78 |
FileLocator local = new FileLocator(); |
3687 |
26 Apr 10 |
gregory |
79 |
List<File> files = local.find(dir, true, Pattern.compile("corrupt_mzdata.xml")); |
1832 |
03 Jul 07 |
gregory |
80 |
assertNotNull(files); |
3687 |
26 Apr 10 |
gregory |
81 |
assertEquals(1, files.size()); |
1832 |
03 Jul 07 |
gregory |
82 |
// |
3687 |
26 Apr 10 |
gregory |
83 |
files = local.find(dir, false, Pattern.compile("no_such_file")); |
1832 |
03 Jul 07 |
gregory |
84 |
assertNotNull(files); |
1832 |
03 Jul 07 |
gregory |
85 |
assertEquals(0, files.size()); |
1832 |
03 Jul 07 |
gregory |
86 |
} |
1842 |
04 Jul 07 |
gregory |
87 |
|
1842 |
04 Jul 07 |
gregory |
88 |
|
1842 |
04 Jul 07 |
gregory |
89 |
@Test |
1842 |
04 Jul 07 |
gregory |
90 |
public void testAsClassName() |
1842 |
04 Jul 07 |
gregory |
91 |
{ |
1842 |
04 Jul 07 |
gregory |
92 |
FileLocator local = new FileLocator(); |
1842 |
04 Jul 07 |
gregory |
93 |
String in, out; |
1842 |
04 Jul 07 |
gregory |
94 |
in = "path/to/File.class"; |
1842 |
04 Jul 07 |
gregory |
95 |
out = local.asClassName(in); |
1842 |
04 Jul 07 |
gregory |
96 |
assertEquals("path.to.File", out); |
1842 |
04 Jul 07 |
gregory |
97 |
// |
1842 |
04 Jul 07 |
gregory |
98 |
in = "path/to/File.xml"; |
1842 |
04 Jul 07 |
gregory |
99 |
out = local.asClassName(in); |
1842 |
04 Jul 07 |
gregory |
100 |
assertEquals(null, out); |
1842 |
04 Jul 07 |
gregory |
101 |
} |
1842 |
04 Jul 07 |
gregory |
102 |
|
1842 |
04 Jul 07 |
gregory |
103 |
|
1842 |
04 Jul 07 |
gregory |
104 |
/** |
1842 |
04 Jul 07 |
gregory |
105 |
|
1842 |
04 Jul 07 |
gregory |
106 |
*/ |
1842 |
04 Jul 07 |
gregory |
107 |
@Test |
1842 |
04 Jul 07 |
gregory |
108 |
public void testFindInJar() |
1842 |
04 Jul 07 |
gregory |
109 |
{ |
1842 |
04 Jul 07 |
gregory |
110 |
FileLocator local = new FileLocator(); |
1842 |
04 Jul 07 |
gregory |
111 |
List<File> files = local.find(dir, true, Pattern |
3687 |
26 Apr 10 |
gregory |
112 |
.compile("myExtension.*\\.ext\\.jar")); |
1842 |
04 Jul 07 |
gregory |
113 |
assertEquals(1, files.size()); |
1842 |
04 Jul 07 |
gregory |
114 |
List<JarEntry> result = local.find(files.get(0), Pattern |
1842 |
04 Jul 07 |
gregory |
115 |
.compile(".*\\.class")); |
1842 |
04 Jul 07 |
gregory |
116 |
assertNotNull(result); |
3687 |
26 Apr 10 |
gregory |
117 |
assertEquals(3, result.size()); |
1842 |
04 Jul 07 |
gregory |
118 |
} |
1832 |
03 Jul 07 |
gregory |
119 |
} |