Source Code Cross Referenced for GenJarTest.java in  » Code-Analyzer » GenJar » org » apache » tools » ant » taskdefs » optional » genjar » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » GenJar » org.apache.tools.ant.taskdefs.optional.genjar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         * Copyright (c) 2002,2003 Jesse Stockall.  All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution, if
019:         *    any, must include the following acknowlegement:
020:         *       "This product includes software developed by the
021:         *        Apache Software Foundation (http://www.apache.org/)."
022:         *    Alternately, this acknowlegement may appear in the software itself,
023:         *    if and wherever such third-party acknowlegements normally appear.
024:         *
025:         * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
026:         *    Foundation" must not be used to endorse or promote products derived
027:         *    from this software without prior written permission. For written
028:         *    permission, please contact apache@apache.org.
029:         *
030:         * 5. Products derived from this software may not be called "Apache"
031:         *    nor may "Apache" appear in their names without prior written
032:         *    permission of the Apache Group.
033:         *
034:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
038:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045:         * SUCH DAMAGE.
046:         * ====================================================================
047:         *
048:         */
049:        package org.apache.tools.ant.taskdefs.optional.genjar;
050:
051:        import java.io.BufferedReader;
052:        import java.io.File;
053:        import java.io.FileInputStream;
054:        import java.io.IOException;
055:        import java.io.InputStreamReader;
056:        import java.util.ArrayList;
057:
058:        import java.util.Iterator;
059:
060:        import org.apache.tools.ant.BuildFileTest;
061:        import org.apache.tools.ant.Project;
062:
063:        /**
064:         * Description of the Class
065:         *
066:         * @author   <a href="mailto:jesse_dev@yahoo.com">Jesse</a>
067:         */
068:        public class GenJarTest extends BuildFileTest {
069:
070:            private Project project;
071:
072:            /**
073:             * Constructor for the SOSTest object
074:             *
075:             * @param s  Test name
076:             */
077:            public GenJarTest(String s) {
078:                super (s);
079:            }
080:
081:            /**
082:             * The JUnit setup method
083:             *
084:             * @throws Exception
085:             */
086:            protected void setUp() throws Exception {
087:                project = new Project();
088:                project.setBasedir(".");
089:                configureProject("test/build.xml");
090:            }
091:
092:            /**
093:             * The teardown method for JUnit
094:             *
095:             * @throws Exception
096:             */
097:            protected void tearDown() throws Exception {
098:                executeTarget("clean");
099:            }
100:
101:            /** Tests */
102:            public void testBuildExceptions() {
103:                expectSpecificBuildException("test.ex.1", "some cause",
104:                        "GenJar: Either a jarfile or destdir attribute is required");
105:                expectSpecificBuildException("test.ex.2", "some cause",
106:                        "can't add 'file' - fileset already used");
107:                expectBuildException("test.ex.3",
108:                        "can't add 'file' - fileset already used");
109:                expectSpecificBuildException("test.ex.4", "some cause",
110:                        "GenJar: Can't specify both file and dir in a <library> element");
111:            }
112:
113:            /** Tests */
114:            public void testResources1() {
115:                executeTarget("test.resource.1");
116:                File dir = new File("test/build/R1");
117:                ArrayList genList = getFileList(dir);
118:                ArrayList staticList = readStaticTestFile(new File(
119:                        "test/etc/R1.filelist"));
120:
121:                assertEquals("Different number of files", staticList.size(),
122:                        genList.size());
123:
124:                assertTrue("Incorrect file in jar", genList
125:                        .containsAll(staticList));
126:            }
127:
128:            /** Tests */
129:            public void testResources2() {
130:                executeTarget("test.resource.2");
131:                File dir = new File("test/build/R2");
132:                ArrayList genList = getFileList(dir);
133:                ArrayList staticList = readStaticTestFile(new File(
134:                        "test/etc/R2.filelist"));
135:
136:                assertEquals("Different number of files", staticList.size(),
137:                        genList.size());
138:
139:                assertTrue("Incorrect file in jar", genList
140:                        .containsAll(staticList));
141:            }
142:
143:            /** Tests */
144:            public void testClass1() {
145:                executeTarget("test.class.1");
146:                File dir = new File("test/build/CL1");
147:                ArrayList genList = getFileList(dir);
148:
149:                ArrayList staticList = readStaticTestFile(new File(
150:                        "test/etc/CL1.filelist"));
151:
152:                assertEquals("Different number of files", staticList.size(),
153:                        genList.size());
154:
155:                assertTrue("Incorrect file in jar", genList
156:                        .containsAll(staticList));
157:            }
158:
159:            //    public void testClass2() {
160:            //        executeTarget("test.class.2");
161:            //        File dir = new File("test/build/CL2");
162:            //        ArrayList genList = getFileList(dir);
163:            //        ArrayList staticList = readStaticTestFile(new File("test/etc/CL2.filelist"));
164:            //
165:            //        for (Iterator it = genList.iterator(); it.hasNext();) {
166:            //            System.out.println(it.next());
167:            //        }
168:            //
169:            //        assertEquals("Different number of files", staticList.size(), genList.size());
170:            //
171:            //        assertTrue("Incorrect file in jar", genList.containsAll(staticList));
172:            //    }
173:
174:            /** Tests */
175:            public void testClass3() {
176:                executeTarget("test.class.3");
177:                File dir = new File("test/build/CL3");
178:                ArrayList genList = getFileList(dir);
179:                ArrayList staticList = readStaticTestFile(new File(
180:                        "test/etc/CL3.filelist"));
181:
182:                assertEquals("Different number of files", staticList.size(),
183:                        genList.size());
184:
185:                assertTrue("Incorrect file in jar", genList
186:                        .containsAll(staticList));
187:            }
188:
189:            /** Tests */
190:            public void testClassFilter1() {
191:                executeTarget("test.classfilter.1");
192:                File dir = new File("test/build/CF1");
193:                ArrayList genList = getFileList(dir);
194:                ArrayList staticList = readStaticTestFile(new File(
195:                        "test/etc/CF1.filelist"));
196:
197:                assertEquals("Different number of files", staticList.size(),
198:                        genList.size());
199:
200:                assertTrue("Incorrect file in jar", genList
201:                        .containsAll(staticList));
202:            }
203:
204:            /** Tests */
205:            public void testClassFilter2() {
206:                executeTarget("test.classfilter.2");
207:                File dir = new File("test/build/CF2");
208:                ArrayList genList = getFileList(dir);
209:                ArrayList staticList = readStaticTestFile(new File(
210:                        "test/etc/CF2.filelist"));
211:
212:                assertEquals("Different number of files", staticList.size(),
213:                        genList.size());
214:
215:                assertTrue("Incorrect file in jar", genList
216:                        .containsAll(staticList));
217:            }
218:
219:            /** Tests */
220:            public void testLibrary1() {
221:                executeTarget("test.library.1");
222:                File dir = new File("test/build/L1");
223:                ArrayList genList = getFileList(dir);
224:                ArrayList staticList = readStaticTestFile(new File(
225:                        "test/etc/L1.filelist"));
226:
227:                assertEquals("Different number of files", staticList.size(),
228:                        genList.size());
229:
230:                assertTrue("Incorrect file in jar", genList
231:                        .containsAll(staticList));
232:            }
233:
234:            /** Tests */
235:            public void testLibrary2() {
236:                executeTarget("test.library.2");
237:                File dir = new File("test/build/L2");
238:                ArrayList genList = getFileList(dir);
239:                ArrayList staticList = readStaticTestFile(new File(
240:                        "test/etc/L2.filelist"));
241:
242:                assertEquals("Different number of files", staticList.size(),
243:                        genList.size());
244:
245:                assertTrue("Incorrect file in jar", genList
246:                        .containsAll(staticList));
247:            }
248:
249:            /** Tests */
250:            public void testLibrary3() {
251:                executeTarget("test.library.3");
252:                File dir = new File("test/build/L3");
253:                ArrayList genList = getFileList(dir);
254:                ArrayList staticList = readStaticTestFile(new File(
255:                        "test/etc/L3.filelist"));
256:
257:                //        for (Iterator it = genList.iterator(); it.hasNext();) {
258:                //            System.out.println("genList " + it.next());
259:                //        }
260:                //
261:                //        for (Iterator it = staticList.iterator(); it.hasNext();) {
262:                //            System.out.println("staticList " + it.next());
263:                //        }
264:
265:                assertEquals("Different number of files", staticList.size(),
266:                        genList.size());
267:
268:                assertTrue("Incorrect file in jar", genList
269:                        .containsAll(staticList));
270:            }
271:
272:            /** Tests */
273:            public void testSignJar() {
274:                expectLogContaining("test.sign.jar", "jar verified.");
275:            }
276:
277:            /** Tests */
278:            public void testUpperCaseClasspathEntry() {
279:                executeTarget("test.classpath.1");
280:                File dir = new File("test/build/CP1");
281:                ArrayList genList = getFileList(dir);
282:                ArrayList staticList = readStaticTestFile(new File(
283:                        "test/etc/CP1.filelist"));
284:
285:                assertEquals("Different number of files", staticList.size(),
286:                        genList.size());
287:
288:                assertTrue("Incorrect file in jar", genList
289:                        .containsAll(staticList));
290:            }
291:
292:            /** Tests */
293:            public void testFileLocking1() {
294:                executeTarget("test.locking.1");
295:            }
296:
297:            /** Tests text in exceptions */
298:            public void testExceptionMsg1() {
299:                expectBuildExceptionContaining("test.exception.msg.1", "",
300:                        "Unable to resolve: bbb/Class6.class");
301:            }
302:
303:            /** Tests text in exceptions */
304:            public void testExceptionMsg2() throws Exception {
305:                String dir = System.getProperty("user.dir", "")
306:                        + File.separator + "test";
307:                File file = new File(dir + File.separator, "file.exists");
308:                file.createNewFile();
309:                file.deleteOnExit();
310:                expectBuildExceptionContaining("test.exception.msg.2", "",
311:                        "Destination directory: \'" + dir + File.separator
312:                                + "file.exists\' is not a valid directory");
313:            }
314:
315:            /** Tests text in exceptions */
316:            public void testExceptionMsg3() throws Exception {
317:                String dir = System.getProperty("user.dir", "")
318:                        + File.separator + "test" + File.separator + "nodir";
319:                expectBuildExceptionContaining("test.exception.msg.3", "",
320:                        "Destination directory: \'" + dir + "\' does not exist");
321:            }
322:
323:            public void testExceptionMsg4() {
324:                expectBuildExceptionContaining("test.exception.msg.4", "",
325:                        "GenJar: Either a jarfile or destdir attribute is required");
326:            }
327:
328:            // Utility methods
329:
330:            private ArrayList readStaticTestFile(File file) {
331:                ArrayList al = new ArrayList();
332:                if (!file.exists()) {
333:                    fail(file.getPath() + "does not exist");
334:                }
335:                if (!file.isFile()) {
336:                    fail(file.getPath() + "is not a file");
337:                }
338:                try {
339:                    FileInputStream fin = new FileInputStream(file);
340:
341:                    BufferedReader myInput = new BufferedReader(
342:                            new InputStreamReader(fin));
343:                    String line;
344:                    while ((line = myInput.readLine()) != null) {
345:                        // Convert to the path seperators, so the tests will run n Windows as well
346:                        al.add(line.replace('/', File.separatorChar));
347:                    }
348:                } catch (IOException ioe) {
349:                    fail("Error reading file list" + file.getPath());
350:                }
351:                return al;
352:            }
353:
354:            private ArrayList getFileList(File dir) {
355:                ArrayList al = new ArrayList();
356:                if (!dir.exists()) {
357:                    fail(dir.getPath() + "does not exist");
358:                }
359:                if (!dir.isDirectory()) {
360:                    fail(dir.getPath() + "is not a directory");
361:                }
362:
363:                File[] files = dir.listFiles();
364:                for (int i = 0, length = files.length; i < length; i++) {
365:                    if (files[i].isFile()) {
366:                        al.add(files[i].getPath());
367:                        continue;
368:                    }
369:                    if (files[i].isDirectory()) {
370:                        al.addAll(getFileList(files[i]));
371:                    }
372:                }
373:                return al;
374:            }
375:        }
w_ww__.j___a___va__2_s__.__c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.