Source Code Cross Referenced for ConcatTest.java in  » Build » ANT » org » apache » tools » ant » taskdefs » 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 » Build » ANT » org.apache.tools.ant.taskdefs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.taskdefs;
020:
021:        import org.apache.tools.ant.BuildFileTest;
022:        import org.apache.tools.ant.util.FileUtils;
023:
024:        import java.io.File;
025:        import java.io.FileReader;
026:        import java.io.IOException;
027:        import java.io.Reader;
028:
029:        /**
030:         * A test class for the 'concat' task, used to concatenate a series of
031:         * files into a single stream.
032:         *
033:         */
034:        public class ConcatTest extends BuildFileTest {
035:
036:            /**
037:             * The name of the temporary file.
038:             */
039:            private static final String tempFile = "concat.tmp";
040:
041:            /**
042:             * The name of the temporary file.
043:             */
044:            private static final String tempFile2 = "concat.tmp.2";
045:
046:            /** Utilities used for file operations */
047:            private static final FileUtils FILE_UTILS = FileUtils
048:                    .getFileUtils();
049:
050:            /**
051:             * Required constructor.
052:             */
053:            public ConcatTest(String name) {
054:                super (name);
055:            }
056:
057:            /**
058:             * Test set up, called by the unit test framework prior to each
059:             * test.
060:             */
061:            public void setUp() {
062:                configureProject("src/etc/testcases/taskdefs/concat.xml");
063:            }
064:
065:            /**
066:             * Test tear down, called by the unit test framework prior to each
067:             * test.
068:             */
069:            public void tearDown() {
070:                executeTarget("cleanup");
071:            }
072:
073:            /**
074:             * Expect an exception when insufficient information is provided.
075:             */
076:            public void test1() {
077:                expectBuildException("test1", "Insufficient information.");
078:            }
079:
080:            /**
081:             * Expect an exception when the destination file is invalid.
082:             */
083:            public void test2() {
084:                expectBuildException("test2", "Invalid destination file.");
085:            }
086:
087:            /**
088:             * Cats the string 'Hello, World!' to a temporary file.
089:             */
090:            public void test3() {
091:
092:                File file = new File(getProjectDir(), tempFile);
093:                if (file.exists()) {
094:                    file.delete();
095:                }
096:
097:                executeTarget("test3");
098:
099:                assertTrue(file.exists());
100:            }
101:
102:            /**
103:             * Cats the file created in test3 three times.
104:             */
105:            public void test4() {
106:                test3();
107:
108:                File file = new File(getProjectDir(), tempFile);
109:                final long origSize = file.length();
110:
111:                executeTarget("test4");
112:
113:                File file2 = new File(getProjectDir(), tempFile2);
114:                final long newSize = file2.length();
115:
116:                assertEquals(origSize * 3, newSize);
117:            }
118:
119:            /**
120:             * Cats the string 'Hello, World!' to the console.
121:             */
122:            public void test5() {
123:                expectLog("test5", "Hello, World!");
124:            }
125:
126:            public void test6() {
127:                String filename = "src/etc/testcases/taskdefs/thisfiledoesnotexist"
128:                        .replace('/', File.separatorChar);
129:                expectLogContaining("test6", filename + " does not exist.");
130:            }
131:
132:            public void testConcatNoNewline() {
133:                expectLog("testConcatNoNewline", "ab");
134:            }
135:
136:            public void testConcatNoNewlineEncoding() {
137:                expectLog("testConcatNoNewlineEncoding", "ab");
138:            }
139:
140:            public void testPath() {
141:                test3();
142:
143:                File file = new File(getProjectDir(), tempFile);
144:                final long origSize = file.length();
145:
146:                executeTarget("testPath");
147:
148:                File file2 = new File(getProjectDir(), tempFile2);
149:                final long newSize = file2.length();
150:
151:                assertEquals(origSize, newSize);
152:
153:            }
154:
155:            public void testAppend() {
156:                test3();
157:
158:                File file = new File(getProjectDir(), tempFile);
159:                final long origSize = file.length();
160:
161:                executeTarget("testAppend");
162:
163:                File file2 = new File(getProjectDir(), tempFile2);
164:                final long newSize = file2.length();
165:
166:                assertEquals(origSize * 2, newSize);
167:
168:            }
169:
170:            public void testFilter() {
171:                executeTarget("testfilter");
172:                assertTrue(getLog().indexOf("REPLACED") > -1);
173:            }
174:
175:            public void testNoOverwrite() {
176:                executeTarget("testnooverwrite");
177:                File file2 = new File(getProjectDir(), tempFile2);
178:                long size = file2.length();
179:                assertEquals(size, 0);
180:            }
181:
182:            public void testheaderfooter() {
183:                test3();
184:                expectLog("testheaderfooter", "headerHello, World!footer");
185:            }
186:
187:            public void testfileheader() {
188:                test3();
189:                expectLog("testfileheader", "Hello, World!Hello, World!");
190:            }
191:
192:            /**
193:             * Expect an exception when attempting to cat an file to itself
194:             */
195:            public void testsame() {
196:                expectBuildException("samefile", "output file same as input");
197:            }
198:
199:            /**
200:             * Check if filter inline works
201:             */
202:            public void testfilterinline() {
203:                executeTarget("testfilterinline");
204:                assertTrue(getLog().indexOf("REPLACED") > -1);
205:            }
206:
207:            /**
208:             * Check if multireader works
209:             */
210:            public void testmultireader() {
211:                executeTarget("testmultireader");
212:                assertTrue(getLog().indexOf("Bye") > -1);
213:                assertTrue(getLog().indexOf("Hello") == -1);
214:            }
215:
216:            /**
217:             * Check if fixlastline works
218:             */
219:            public void testfixlastline() throws IOException {
220:                expectFileContains("testfixlastline", "concat.line4",
221:                        "end of line" + System.getProperty("line.separator")
222:                                + "This has");
223:            }
224:
225:            /**
226:             * Check if fixlastline works with eol
227:             */
228:            public void testfixlastlineeol() throws IOException {
229:                expectFileContains("testfixlastlineeol", "concat.linecr",
230:                        "end of line\rThis has");
231:            }
232:
233:            // ------------------------------------------------------
234:            //   Helper methods - should be in BuildFileTest
235:            // -----------------------------------------------------
236:
237:            private String getFileString(String filename) throws IOException {
238:                Reader r = null;
239:                try {
240:                    r = new FileReader(getProject().resolveFile(filename));
241:                    return FileUtils.readFully(r);
242:                } finally {
243:                    FileUtils.close(r);
244:                }
245:
246:            }
247:
248:            private String getFileString(String target, String filename)
249:                    throws IOException {
250:                executeTarget(target);
251:                return getFileString(filename);
252:            }
253:
254:            private void expectFileContains(String target, String filename,
255:                    String contains) throws IOException {
256:                String content = getFileString(target, filename);
257:                assertTrue("expecting file " + filename + " to contain "
258:                        + contains + " but got " + content, content
259:                        .indexOf(contains) > -1);
260:            }
261:
262:            public void testTranscoding() throws IOException {
263:                executeTarget("testTranscoding");
264:                File f1 = getProject().resolveFile("copy/expected/utf-8");
265:                File f2 = getProject().resolveFile("concat.utf8");
266:                assertTrue(FILE_UTILS.contentEquals(f1, f2));
267:            }
268:
269:            public void testResources() {
270:                executeTarget("testResources");
271:            }
272:
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.