Source Code Cross Referenced for TestJarFactory.java in  » Code-Analyzer » JBlanket » csdl » jblanket » util » 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 » JBlanket » csdl.jblanket.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package csdl.jblanket.util;
002:
003:        import java.io.File;
004:        import java.util.Enumeration;
005:        import java.util.jar.JarEntry;
006:        import java.util.jar.JarFile;
007:
008:        import junit.framework.TestCase;
009:        import junit.framework.TestSuite;
010:        import junit.textui.TestRunner;
011:
012:        import org.apache.tools.ant.DirectoryScanner;
013:
014:        /**
015:         * Tests operations in the JarFactory class.
016:         * <p>
017:         * If using Ant to execute this test class a 'jblanket.testdir' system property needs to be set in
018:         * the build.xml file.  If running test class from command line, must provide '-Djblanket.testdir'
019:         * to set the system property.  This value is used by both the testJar and testUnjar methods.
020:         *
021:         * @author Joy M. Agustin
022:         * @version $Id: TestJarFactory.java,v 1.1 2004/11/07 00:32:26 timshadel Exp $
023:         */
024:        public class TestJarFactory extends TestCase {
025:
026:            /** Subdirectory holding JAR file for testing */
027:            private String jarTestdataDir;
028:            /** Subdirectory holding extracted JAR files for testing */
029:            private String unjarTestdataDir;
030:
031:            /** Directory holding files created by testing */
032:            private String testDir;
033:
034:            /** Name of directory holding data for testing */
035:            private final String testdataDirName = "testdata";
036:            /** Name of directory holding JAR file for testing */
037:            private final String jarTestdataDirName = "jar";
038:            /** Name of directory holding extracted JAR files for testing */
039:            private final String unjarTestdataDirName = "unjar";
040:            /** Name of JAR file to use for testing extraction */
041:            private final String jarFileName = "stack.jar";
042:
043:            /** Directory seperator */
044:            private final String SLASH = File.separator;
045:
046:            /** Grammar for CVS directories */
047:            private final String cvsGrammar = "**" + SLASH + "CVS" + SLASH
048:                    + "**";
049:            /** Include condition 1 */
050:            private final String include1 = "edu" + SLASH + "**";
051:            /** Include condition 2 */
052:            private final String include2 = "META-INF";
053:
054:            /**
055:             * Required for JUnit.
056:             *
057:             * @param name Test case name.
058:             */
059:            public TestJarFactory(String name) {
060:                super (name);
061:            }
062:
063:            /**
064:             * Sets up variables for testing.
065:             */
066:            public void setUp() {
067:
068:                this .testDir = System.getProperty("jblanket.testdir") + SLASH
069:                        + "testjar";
070:                assertNotNull("Checking for presence of methodset_testdir.",
071:                        this .testDir);
072:
073:                // initialize testdata sub/directory variables
074:                String testdataDir = System.getProperty("jblanket.data.dir");
075:                this .jarTestdataDir = testdataDir + SLASH
076:                        + this .jarTestdataDirName;
077:                this .unjarTestdataDir = testdataDir + SLASH
078:                        + this .unjarTestdataDirName;
079:            }
080:
081:            /**
082:             * Tests both the <code>jar</code> and <code>unjar</code> methods in the JarFactory class.
083:             *
084:             * @throws Exception If problems occur.
085:             */
086:            public void testJarFactory() throws Exception {
087:
088:                // tests extraction of a JAR file by checking the content that is output.
089:                JarFactory factory = new JarFactory(this .testDir);
090:                factory.unJar(new File(this .jarTestdataDir, this .jarFileName));
091:
092:                // get known unpacked contents
093:                DirectoryScanner knownScanner = new DirectoryScanner();
094:                knownScanner.setIncludes(new String[] { include1, include2 });
095:                knownScanner.setExcludes(new String[] { cvsGrammar });
096:                knownScanner.setBasedir(new File(this .unjarTestdataDir));
097:                knownScanner.scan();
098:                String[] knownDirectories = knownScanner
099:                        .getIncludedDirectories();
100:                String[] knownFiles = knownScanner.getIncludedFiles();
101:
102:                // get contents unpacked by factory
103:                DirectoryScanner factoryScanner = new DirectoryScanner();
104:                factoryScanner.setIncludes(new String[] { include1, include2 });
105:                factoryScanner.setBasedir(new File(this .testDir));
106:                factoryScanner.scan();
107:                String[] factoryDirectories = factoryScanner
108:                        .getIncludedDirectories();
109:                String[] factoryFiles = factoryScanner.getIncludedFiles();
110:
111:                // check known contents to factory contents
112:                assertEquals("checking number of directories",
113:                        knownDirectories.length, factoryDirectories.length);
114:                assertEquals("checking number of files", knownFiles.length,
115:                        factoryFiles.length);
116:
117:                assertTrue("Checking at least one file is not empty",
118:                        factoryFiles[0].length() > 0);
119:
120:                // test creation of a JAR file by checking the content that is output.
121:                factory = new JarFactory(this .testDir);
122:                // if file exists, delete and create new one
123:                File jarFile = new File(this .testDir, this .jarFileName);
124:                if (jarFile.exists()) {
125:                    jarFile.delete();
126:                }
127:                factory.jar(jarFile);
128:
129:                // get known jar file entries
130:                JarFile knownFile = new JarFile(new File(this .jarTestdataDir,
131:                        this .jarFileName));
132:                Enumeration knownEnum = knownFile.entries();
133:
134:                // get entries created by factory
135:                JarFile factoryFile = new JarFile(new File(this .testDir,
136:                        this .jarFileName));
137:                Enumeration factoryEnum = factoryFile.entries();
138:
139:                // check known entries to factory entries
140:                while (knownEnum.hasMoreElements()
141:                        && factoryEnum.hasMoreElements()) {
142:                    assertEquals("checking JAR entries", ((JarEntry) knownEnum
143:                            .nextElement()).getName(), ((JarEntry) factoryEnum
144:                            .nextElement()).getName());
145:                }
146:                assertTrue("checking if all entries were included", !knownEnum
147:                        .hasMoreElements());
148:                assertTrue("checking if extra entries were included",
149:                        !factoryEnum.hasMoreElements());
150:
151:                knownFile.close();
152:                factoryFile.close();
153:            }
154:
155:            /**
156:             * Provide stand-alone execution of this test case during initial development.
157:             *
158:             * @param args The command line arguments
159:             */
160:            public static void main(String[] args) {
161:
162:                System.out.println("JUnit testing JarFactory.");
163:                //Runs all no-arg methods starting with "test".
164:                TestRunner.run(new TestSuite(TestJarFactory.class));
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.