Source Code Cross Referenced for IvyDeliverTest.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » ant » 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 » apache ivy » org.apache.ivy.ant 
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:        package org.apache.ivy.ant;
019:
020:        import java.io.BufferedReader;
021:        import java.io.File;
022:        import java.io.FileReader;
023:        import java.util.HashMap;
024:        import java.util.Map;
025:
026:        import junit.framework.TestCase;
027:
028:        import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
029:        import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
030:        import org.apache.ivy.core.module.id.ModuleRevisionId;
031:        import org.apache.ivy.core.settings.IvySettings;
032:        import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
033:        import org.apache.ivy.util.FileUtil;
034:        import org.apache.tools.ant.Project;
035:        import org.apache.tools.ant.taskdefs.Delete;
036:
037:        public class IvyDeliverTest extends TestCase {
038:            private File cache;
039:
040:            private IvyDeliver deliver;
041:
042:            private Project project;
043:
044:            protected void setUp() throws Exception {
045:                cleanTestDir();
046:                cleanRep();
047:                createCache();
048:                project = new Project();
049:                project.init();
050:                project.setProperty("ivy.settings.file",
051:                        "test/repositories/ivysettings.xml");
052:                project.setProperty("build", "build/test/deliver");
053:
054:                deliver = new IvyDeliver();
055:                deliver.setProject(project);
056:                System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
057:            }
058:
059:            private void createCache() {
060:                cache = new File("build/cache");
061:                cache.mkdirs();
062:            }
063:
064:            protected void tearDown() throws Exception {
065:                cleanCache();
066:                cleanTestDir();
067:                cleanRep();
068:            }
069:
070:            private void cleanCache() {
071:                Delete del = new Delete();
072:                del.setProject(new Project());
073:                del.setDir(cache);
074:                del.execute();
075:            }
076:
077:            private void cleanTestDir() {
078:                Delete del = new Delete();
079:                del.setProject(new Project());
080:                del.setDir(new File("build/test/deliver"));
081:                del.execute();
082:            }
083:
084:            private void cleanRep() {
085:                Delete del = new Delete();
086:                del.setProject(new Project());
087:                del.setDir(new File("test/repositories/1/apache"));
088:                del.execute();
089:            }
090:
091:            public void testSimple() throws Exception {
092:                project.setProperty("ivy.dep.file",
093:                        "test/java/org/apache/ivy/ant/ivy-latest.xml");
094:                IvyResolve res = new IvyResolve();
095:                res.setProject(project);
096:                res.execute();
097:
098:                deliver.setPubrevision("1.2");
099:                deliver
100:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
101:                deliver.execute();
102:
103:                // should have done the ivy delivering
104:                File deliveredIvyFile = new File(
105:                        "build/test/deliver/ivy-1.2.xml");
106:                assertTrue(deliveredIvyFile.exists());
107:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
108:                        .parseDescriptor(new IvySettings(),
109:                                deliveredIvyFile.toURL(), true);
110:                assertEquals(ModuleRevisionId.newInstance("apache",
111:                        "resolve-latest", "1.2"), md.getModuleRevisionId());
112:                DependencyDescriptor[] dds = md.getDependencies();
113:                assertEquals(1, dds.length);
114:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
115:                        "2.2"), dds[0].getDependencyRevisionId());
116:            }
117:
118:            public void testWithResolveId() throws Exception {
119:                IvyResolve resolve = new IvyResolve();
120:                resolve.setProject(project);
121:                resolve.setFile(new File(
122:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
123:                resolve.setResolveId("withResolveId");
124:                resolve.execute();
125:
126:                // resolve another ivy file
127:                resolve = new IvyResolve();
128:                resolve.setProject(project);
129:                resolve.setFile(new File(
130:                        "test/java/org/apache/ivy/ant/ivy-latest.xml"));
131:                resolve.execute();
132:
133:                deliver.setResolveId("withResolveId");
134:                deliver.setPubrevision("1.2");
135:                deliver
136:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
137:                deliver.execute();
138:
139:                // should have done the ivy delivering
140:                File deliveredIvyFile = new File(
141:                        "build/test/deliver/ivy-1.2.xml");
142:                assertTrue(deliveredIvyFile.exists());
143:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
144:                        .parseDescriptor(new IvySettings(),
145:                                deliveredIvyFile.toURL(), true);
146:                assertEquals(ModuleRevisionId.newInstance("apache",
147:                        "resolve-simple", "1.2"), md.getModuleRevisionId());
148:                DependencyDescriptor[] dds = md.getDependencies();
149:                assertEquals(1, dds.length);
150:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
151:                        "2.0"), dds[0].getDependencyRevisionId());
152:            }
153:
154:            public void testWithResolveIdInAnotherBuild() throws Exception {
155:                // create a new build
156:                Project other = new Project();
157:                other.setProperty("ivy.settings.file",
158:                        "test/repositories/ivysettings.xml");
159:                other.setProperty("build", "build/test/deliver");
160:
161:                // do a resolve in the new build
162:                IvyResolve resolve = new IvyResolve();
163:                resolve.setProject(other);
164:                resolve.setFile(new File(
165:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
166:                resolve.setResolveId("withResolveId");
167:                resolve.execute();
168:
169:                // resolve another ivy file
170:                resolve = new IvyResolve();
171:                resolve.setProject(project);
172:                resolve.setFile(new File(
173:                        "test/java/org/apache/ivy/ant/ivy-latest.xml"));
174:                resolve.execute();
175:
176:                deliver.setResolveId("withResolveId");
177:                deliver.setPubrevision("1.2");
178:                deliver
179:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
180:                deliver.execute();
181:
182:                // should have done the ivy delivering
183:                File deliveredIvyFile = new File(
184:                        "build/test/deliver/ivy-1.2.xml");
185:                assertTrue(deliveredIvyFile.exists());
186:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
187:                        .parseDescriptor(new IvySettings(),
188:                                deliveredIvyFile.toURL(), true);
189:                assertEquals(ModuleRevisionId.newInstance("apache",
190:                        "resolve-simple", "1.2"), md.getModuleRevisionId());
191:                DependencyDescriptor[] dds = md.getDependencies();
192:                assertEquals(1, dds.length);
193:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
194:                        "2.0"), dds[0].getDependencyRevisionId());
195:            }
196:
197:            public void testWithBranch() throws Exception {
198:                // test case for IVY-404
199:                project.setProperty("ivy.dep.file",
200:                        "test/java/org/apache/ivy/ant/ivy-latest-branch.xml");
201:                IvyResolve res = new IvyResolve();
202:                res.setProject(project);
203:                res.execute();
204:
205:                deliver.setPubrevision("1.2");
206:                deliver
207:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
208:                deliver.execute();
209:
210:                // should have done the ivy delivering
211:                File deliveredIvyFile = new File(
212:                        "build/test/deliver/ivy-1.2.xml");
213:                assertTrue(deliveredIvyFile.exists());
214:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
215:                        .parseDescriptor(new IvySettings(),
216:                                deliveredIvyFile.toURL(), true);
217:                assertEquals(ModuleRevisionId.newInstance("apache",
218:                        "resolve-latest", "1.2"), md.getModuleRevisionId());
219:                DependencyDescriptor[] dds = md.getDependencies();
220:                assertEquals(1, dds.length);
221:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
222:                        "TRUNK", "2.2"), dds[0].getDependencyRevisionId());
223:            }
224:
225:            public void testReplaceBranch() throws Exception {
226:                IvyAntSettings settings = new IvyAntSettings();
227:                settings.setProject(project);
228:                settings.execute();
229:                // change the default branch to use
230:                settings.getConfiguredIvyInstance().getSettings()
231:                        .setDefaultBranch("BRANCH1");
232:
233:                // resolve a module dependencies
234:                project.setProperty("ivy.dep.file",
235:                        "test/java/org/apache/ivy/ant/ivy-latest.xml");
236:                IvyResolve res = new IvyResolve();
237:                res.setProject(project);
238:                res.execute();
239:
240:                // deliver this module
241:                deliver.setPubrevision("1.2");
242:                deliver
243:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
244:                deliver.execute();
245:
246:                // should have done the ivy delivering, including setting the branch according to the 
247:                // configured default
248:                File deliveredIvyFile = new File(
249:                        "build/test/deliver/ivy-1.2.xml");
250:                assertTrue(deliveredIvyFile.exists());
251:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
252:                        .parseDescriptor(new IvySettings(),
253:                                deliveredIvyFile.toURL(), true);
254:                assertEquals(ModuleRevisionId.newInstance("apache",
255:                        "resolve-latest", "1.2"), md.getModuleRevisionId());
256:                DependencyDescriptor[] dds = md.getDependencies();
257:                assertEquals(1, dds.length);
258:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
259:                        "BRANCH1", "2.2"), dds[0].getDependencyRevisionId());
260:            }
261:
262:            public void testWithExtraAttributes() throws Exception {
263:                // test case for IVY-415
264:                project.setProperty("ivy.dep.file",
265:                        "test/java/org/apache/ivy/ant/ivy-latest-extra.xml");
266:                IvyResolve res = new IvyResolve();
267:                res.setValidate(false);
268:                res.setProject(project);
269:                res.execute();
270:
271:                deliver.setPubrevision("1.2");
272:                deliver
273:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
274:                deliver.setValidate(false);
275:                deliver.execute();
276:
277:                // should have done the ivy delivering
278:                File deliveredIvyFile = new File(
279:                        "build/test/deliver/ivy-1.2.xml");
280:                assertTrue(deliveredIvyFile.exists());
281:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
282:                        .parseDescriptor(new IvySettings(),
283:                                deliveredIvyFile.toURL(), false);
284:                assertEquals(ModuleRevisionId.newInstance("apache",
285:                        "resolve-latest", "1.2"), md.getModuleRevisionId());
286:                DependencyDescriptor[] dds = md.getDependencies();
287:                assertEquals(1, dds.length);
288:                Map extraAtt = new HashMap();
289:                extraAtt.put("myExtraAtt", "myValue");
290:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
291:                        "2.2", extraAtt), dds[0].getDependencyRevisionId());
292:            }
293:
294:            public void testWithDynEvicted() throws Exception {
295:                project.setProperty("ivy.dep.file",
296:                        "test/java/org/apache/ivy/ant/ivy-dyn-evicted.xml");
297:                IvyResolve res = new IvyResolve();
298:                res.setValidate(false);
299:                res.setProject(project);
300:                res.execute();
301:
302:                deliver.setPubrevision("1.2");
303:                deliver
304:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
305:                deliver.setValidate(false);
306:                deliver.execute();
307:
308:                // should have done the ivy delivering
309:                File deliveredIvyFile = new File(
310:                        "build/test/deliver/ivy-1.2.xml");
311:                assertTrue(deliveredIvyFile.exists());
312:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
313:                        .parseDescriptor(new IvySettings(),
314:                                deliveredIvyFile.toURL(), false);
315:                assertEquals(ModuleRevisionId.newInstance("apache",
316:                        "resolve-latest", "1.2"), md.getModuleRevisionId());
317:                DependencyDescriptor[] dds = md.getDependencies();
318:                assertEquals(2, dds.length);
319:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
320:                        "1.1"), dds[0].getDependencyRevisionId());
321:            }
322:
323:            public void testReplaceImportedConfigurations() throws Exception {
324:                project.setProperty("ivy.dep.file",
325:                        "test/java/org/apache/ivy/ant/ivy-import-confs.xml");
326:                IvyResolve res = new IvyResolve();
327:                res.setProject(project);
328:                res.execute();
329:
330:                deliver.setPubrevision("1.2");
331:                deliver
332:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
333:                deliver.execute();
334:
335:                // should have done the ivy delivering
336:                File deliveredIvyFile = new File(
337:                        "build/test/deliver/ivy-1.2.xml");
338:                assertTrue(deliveredIvyFile.exists());
339:                String deliveredFileContent = FileUtil
340:                        .readEntirely(new BufferedReader(new FileReader(
341:                                deliveredIvyFile)));
342:                assertTrue(
343:                        "import not replaced: import can still be found in file",
344:                        deliveredFileContent.indexOf("import") == -1);
345:                assertTrue(
346:                        "import not replaced: conf1 cannot be found in file",
347:                        deliveredFileContent.indexOf("conf1") != -1);
348:            }
349:
350:            public void testReplaceVariables() throws Exception {
351:                project.setProperty("ivy.dep.file",
352:                        "test/java/org/apache/ivy/ant/ivy-with-variables.xml");
353:                IvyResolve res = new IvyResolve();
354:                res.setProject(project);
355:                res.execute();
356:
357:                res.getIvyInstance().getSettings().setVariable("myvar",
358:                        "myvalue");
359:
360:                deliver.setPubrevision("1.2");
361:                deliver
362:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
363:                deliver.execute();
364:
365:                // should have done the ivy delivering
366:                File deliveredIvyFile = new File(
367:                        "build/test/deliver/ivy-1.2.xml");
368:                assertTrue(deliveredIvyFile.exists());
369:                String deliveredFileContent = FileUtil
370:                        .readEntirely(new BufferedReader(new FileReader(
371:                                deliveredIvyFile)));
372:                assertTrue(
373:                        "variable not replaced: myvar can still be found in file",
374:                        deliveredFileContent.indexOf("myvar") == -1);
375:                assertTrue(
376:                        "variable not replaced: myvalue cannot be found in file",
377:                        deliveredFileContent.indexOf("myvalue") != -1);
378:            }
379:
380:            public void testNoReplaceDynamicRev() throws Exception {
381:                project.setProperty("ivy.dep.file",
382:                        "test/java/org/apache/ivy/ant/ivy-latest.xml");
383:                IvyResolve res = new IvyResolve();
384:                res.setProject(project);
385:                res.execute();
386:
387:                deliver.setPubrevision("1.2");
388:                deliver
389:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
390:                deliver.setReplacedynamicrev(false);
391:                deliver.execute();
392:
393:                // should have done the ivy delivering
394:                File deliveredIvyFile = new File(
395:                        "build/test/deliver/ivy-1.2.xml");
396:                assertTrue(deliveredIvyFile.exists());
397:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
398:                        .parseDescriptor(new IvySettings(),
399:                                deliveredIvyFile.toURL(), true);
400:                assertEquals(ModuleRevisionId.newInstance("apache",
401:                        "resolve-latest", "1.2"), md.getModuleRevisionId());
402:                DependencyDescriptor[] dds = md.getDependencies();
403:                assertEquals(1, dds.length);
404:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
405:                        "latest.integration"), dds[0].getDependencyRevisionId());
406:            }
407:
408:            public void testDifferentRevisionsForSameModule() throws Exception {
409:                project
410:                        .setProperty("ivy.dep.file",
411:                                "test/java/org/apache/ivy/ant/ivy-different-revisions.xml");
412:                IvyResolve res = new IvyResolve();
413:                res.setProject(project);
414:                res.execute();
415:
416:                deliver.setPubrevision("1.2");
417:                deliver
418:                        .setDeliverpattern("build/test/deliver/ivy-[revision].xml");
419:                deliver.execute();
420:
421:                // should have done the ivy delivering
422:                File deliveredIvyFile = new File(
423:                        "build/test/deliver/ivy-1.2.xml");
424:                assertTrue(deliveredIvyFile.exists());
425:                ModuleDescriptor md = XmlModuleDescriptorParser.getInstance()
426:                        .parseDescriptor(new IvySettings(),
427:                                deliveredIvyFile.toURL(), true);
428:                assertEquals(ModuleRevisionId.newInstance("apache",
429:                        "different-revs", "1.2"), md.getModuleRevisionId());
430:                DependencyDescriptor[] dds = md.getDependencies();
431:                assertEquals(3, dds.length);
432:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
433:                        "2.0"), dds[0].getDependencyRevisionId());
434:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1",
435:                        "1.0"), dds[1].getDependencyRevisionId());
436:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.2",
437:                        "1.1"), dds[2].getDependencyRevisionId());
438:            }
439:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.