Source Code Cross Referenced for EchoPropertiesTest.java in  » Build » ANT » org » apache » tools » ant » taskdefs » optional » 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.optional 
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.optional;
020:
021:        import org.apache.tools.ant.BuildFileTest;
022:
023:        import java.io.IOException;
024:        import java.io.File;
025:        import java.io.InputStream;
026:        import java.io.BufferedInputStream;
027:        import java.io.FileInputStream;
028:        import java.io.FileReader;
029:        import java.io.BufferedReader;
030:        import java.util.Properties;
031:
032:        /**
033:         * Tests the EchoProperties task.
034:         *
035:         * @created   17-Jan-2002
036:         * @since     Ant 1.5
037:         */
038:        public class EchoPropertiesTest extends BuildFileTest {
039:
040:            private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
041:            private static final String GOOD_OUTFILE = "test.properties";
042:            private static final String GOOD_OUTFILE_XML = "test.xml";
043:            private static final String PREFIX_OUTFILE = "test-prefix.properties";
044:            private static final String TEST_VALUE = "isSet";
045:            private static final String BAD_OUTFILE = ".";
046:
047:            public EchoPropertiesTest(String name) {
048:                super (name);
049:            }
050:
051:            public void setUp() {
052:                configureProject(TASKDEFS_DIR + "echoproperties.xml");
053:                project.setProperty("test.property", TEST_VALUE);
054:            }
055:
056:            public void tearDown() {
057:                executeTarget("cleanup");
058:            }
059:
060:            public void testEchoToLog() {
061:                expectLogContaining("testEchoToLog", "test.property="
062:                        + TEST_VALUE);
063:            }
064:
065:            public void testEchoWithEmptyPrefixToLog() {
066:                expectLogContaining("testEchoWithEmptyPrefixToLog",
067:                        "test.property=" + TEST_VALUE);
068:            }
069:
070:            public void testReadBadFile() {
071:                expectBuildExceptionContaining("testReadBadFile",
072:                        "srcfile is a directory", "srcfile is a directory!");
073:            }
074:
075:            public void testReadBadFileFail() {
076:                expectBuildExceptionContaining("testReadBadFile",
077:                        "srcfile is a directory", "srcfile is a directory!");
078:            }
079:
080:            public void testReadBadFileNoFail() {
081:                expectLog("testReadBadFileNoFail", "srcfile is a directory!");
082:            }
083:
084:            public void testEchoToBadFile() {
085:                expectBuildExceptionContaining("testEchoToBadFile",
086:                        "destfile is a directory", "destfile is a directory!");
087:            }
088:
089:            public void testEchoToBadFileFail() {
090:                expectBuildExceptionContaining("testEchoToBadFileFail",
091:                        "destfile is a directory", "destfile is a directory!");
092:            }
093:
094:            public void testEchoToBadFileNoFail() {
095:                expectLog("testEchoToBadFileNoFail", "destfile is a directory!");
096:            }
097:
098:            public void testEchoToGoodFile() throws Exception {
099:                executeTarget("testEchoToGoodFile");
100:                assertGoodFile();
101:            }
102:
103:            public void testEchoToGoodFileXml() throws Exception {
104:                executeTarget("testEchoToGoodFileXml");
105:
106:                // read in the file
107:                File f = createRelativeFile(GOOD_OUTFILE_XML);
108:                FileReader fr = new FileReader(f);
109:                try {
110:                    BufferedReader br = new BufferedReader(fr);
111:                    String read = null;
112:                    while ((read = br.readLine()) != null) {
113:                        if (read
114:                                .indexOf("<property name=\"test.property\" value=\""
115:                                        + TEST_VALUE + "\" />") >= 0) {
116:                            // found the property we set - it's good.
117:                            return;
118:                        }
119:                    }
120:                    fail("did not encounter set property in generated file.");
121:                } finally {
122:                    try {
123:                        fr.close();
124:                    } catch (IOException e) {
125:                    }
126:                }
127:            }
128:
129:            public void testEchoToGoodFileFail() throws Exception {
130:                executeTarget("testEchoToGoodFileFail");
131:                assertGoodFile();
132:            }
133:
134:            public void testEchoToGoodFileNoFail() throws Exception {
135:                executeTarget("testEchoToGoodFileNoFail");
136:                assertGoodFile();
137:            }
138:
139:            public void testEchoPrefix() throws Exception {
140:                testEchoPrefixVarious("testEchoPrefix");
141:            }
142:
143:            public void testEchoPrefixAsPropertyset() throws Exception {
144:                testEchoPrefixVarious("testEchoPrefixAsPropertyset");
145:            }
146:
147:            public void testEchoPrefixAsNegatedPropertyset() throws Exception {
148:                testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset");
149:            }
150:
151:            public void testEchoPrefixAsDoublyNegatedPropertyset()
152:                    throws Exception {
153:                testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset");
154:            }
155:
156:            public void testWithPrefixAndRegex() throws Exception {
157:                expectSpecificBuildException(
158:                        "testWithPrefixAndRegex",
159:                        "The target must fail with prefix and regex attributes set",
160:                        "Please specify either prefix or regex, but not both");
161:            }
162:
163:            public void testWithEmptyPrefixAndRegex() throws Exception {
164:                expectLogContaining("testEchoWithEmptyPrefixToLog",
165:                        "test.property=" + TEST_VALUE);
166:            }
167:
168:            public void testWithRegex() throws Exception {
169:                executeTarget("testWithRegex");
170:                assertDebuglogContaining("ant.home=");
171:            }
172:
173:            private void testEchoPrefixVarious(String target) throws Exception {
174:                executeTarget(target);
175:                Properties props = loadPropFile(PREFIX_OUTFILE);
176:                assertEquals("prefix didn't include 'a.set' property", "true",
177:                        props.getProperty("a.set"));
178:                assertNull("prefix failed to filter out property 'b.set'",
179:                        props.getProperty("b.set"));
180:            }
181:
182:            protected Properties loadPropFile(String relativeFilename)
183:                    throws IOException {
184:                File f = createRelativeFile(relativeFilename);
185:                Properties props = new Properties();
186:                InputStream in = null;
187:                try {
188:                    in = new BufferedInputStream(new FileInputStream(f));
189:                    props.load(in);
190:                } finally {
191:                    if (in != null) {
192:                        try {
193:                            in.close();
194:                        } catch (IOException e) {
195:                        }
196:                    }
197:                }
198:                return props;
199:            }
200:
201:            protected void assertGoodFile() throws Exception {
202:                File f = createRelativeFile(GOOD_OUTFILE);
203:                assertTrue("Did not create " + f.getAbsolutePath(), f.exists());
204:                Properties props = loadPropFile(GOOD_OUTFILE);
205:                props.list(System.out);
206:                assertEquals("test property not found ", TEST_VALUE, props
207:                        .getProperty("test.property"));
208:                /*
209:                 // read in the file
210:                 FileReader fr = new FileReader( f );
211:                 try {
212:                 BufferedReader br = new BufferedReader( fr );
213:                 String read = null;
214:                 while ( (read = br.readLine()) != null)
215:                 {
216:                 if (read.indexOf("test.property" + TEST_VALUE) >= 0)
217:                 {
218:                 // found the property we set - it's good.
219:                 return;
220:                 }
221:                 }
222:                 fail( "did not encounter set property in generated file." );
223:                 } finally {
224:                 try { fr.close(); } catch(IOException e) {}
225:                 }
226:                 */
227:            }
228:
229:            protected String toAbsolute(String filename) {
230:                return createRelativeFile(filename).getAbsolutePath();
231:            }
232:
233:            protected File createRelativeFile(String filename) {
234:                if (filename.equals(".")) {
235:                    return getProjectDir();
236:                }
237:                // else
238:                return new File(getProjectDir(), filename);
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.