Source Code Cross Referenced for IvyResolveTest.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.File;
021:
022:        import junit.framework.TestCase;
023:
024:        import org.apache.ivy.Ivy;
025:        import org.apache.ivy.TestHelper;
026:        import org.apache.ivy.core.module.id.ModuleRevisionId;
027:        import org.apache.tools.ant.BuildException;
028:        import org.apache.tools.ant.Project;
029:        import org.apache.tools.ant.taskdefs.Delete;
030:
031:        public class IvyResolveTest extends TestCase {
032:            private File cache;
033:
034:            private IvyResolve resolve;
035:
036:            protected void setUp() throws Exception {
037:                createCache();
038:                Project project = new Project();
039:                project.setProperty("ivy.settings.file",
040:                        "test/repositories/ivysettings.xml");
041:                project.setProperty("ivy.cache.dir", cache.getAbsolutePath());
042:
043:                resolve = new IvyResolve();
044:                resolve.setProject(project);
045:            }
046:
047:            private void createCache() {
048:                cache = new File("build/cache");
049:                cache.mkdirs();
050:            }
051:
052:            protected void tearDown() throws Exception {
053:                cleanCache();
054:            }
055:
056:            private void cleanCache() {
057:                Delete del = new Delete();
058:                del.setProject(new Project());
059:                del.setDir(cache);
060:                del.execute();
061:            }
062:
063:            public void testSimple() throws Exception {
064:                // depends on org="org1" name="mod1.2" rev="2.0"
065:                resolve.setFile(new File(
066:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
067:                resolve.execute();
068:
069:                assertTrue(getResolvedIvyFileInCache(
070:                        ModuleRevisionId.newInstance("apache",
071:                                "resolve-simple", "1.0")).exists());
072:
073:                // dependencies
074:                assertTrue(getIvyFileInCache(
075:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
076:                        .exists());
077:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
078:                        "mod1.2", "jar", "jar").exists());
079:            }
080:
081:            public void testResolveWithoutIvyFile() throws Exception {
082:                // IVY-630
083:                resolve.getProject().setProperty("ivy.settings.file",
084:                        "test/repositories/IVY-630/ivysettings.xml");
085:
086:                resolve.setFile(new File(
087:                        "test/java/org/apache/ivy/ant/ivy-630.xml"));
088:                resolve.setConf("default");
089:                resolve.setHaltonfailure(false);
090:                resolve.execute();
091:
092:                assertTrue(getIvyFileInCache(
093:                        ModuleRevisionId.newInstance("junit", "junit", "4.1"))
094:                        .exists());
095:                assertTrue(getArchiveFileInCache("junit", "junit", "4.1",
096:                        "junit", "jar", "jar").exists());
097:            }
098:
099:            private File getArchiveFileInCache(String organisation,
100:                    String module, String revision, String artifact,
101:                    String type, String ext) {
102:                return TestHelper.getArchiveFileInCache(getIvy(), organisation,
103:                        module, revision, artifact, type, ext);
104:            }
105:
106:            private File getIvyFileInCache(ModuleRevisionId id) {
107:                return TestHelper.getRepositoryCacheManager(getIvy(), id)
108:                        .getIvyFileInCache(id);
109:            }
110:
111:            private File getResolvedIvyFileInCache(ModuleRevisionId id) {
112:                return getIvy().getResolutionCacheManager()
113:                        .getResolvedIvyFileInCache(id);
114:            }
115:
116:            public void testInline() throws Exception {
117:                // same as before, but expressing dependency directly without ivy file
118:                resolve.setOrganisation("org1");
119:                resolve.setModule("mod1.2");
120:                resolve.setRevision("2.0");
121:                resolve.setInline(true);
122:                resolve.execute();
123:
124:                // dependencies
125:                assertTrue(getIvyFileInCache(
126:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
127:                        .exists());
128:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
129:                        "mod1.2", "jar", "jar").exists());
130:            }
131:
132:            public void testInlineForNonExistingModule() throws Exception {
133:                resolve.setOrganisation("org1XX");
134:                resolve.setModule("mod1.2");
135:                resolve.setRevision("2.0");
136:                resolve.setInline(true);
137:                resolve.setHaltonfailure(false);
138:                resolve.setFailureProperty("failure.property");
139:                resolve.execute();
140:
141:                // the resolve must have failed -> the failure property must be set
142:                String failure = resolve.getProject().getProperty(
143:                        "failure.property");
144:                assertTrue("Failure property must have been specified!",
145:                        Boolean.valueOf(failure).booleanValue());
146:            }
147:
148:            public void testWithSlashes() throws Exception {
149:                resolve.setFile(new File(
150:                        "test/java/org/apache/ivy/core/resolve/ivy-198.xml"));
151:                resolve.execute();
152:
153:                File resolvedIvyFileInCache = getResolvedIvyFileInCache(ModuleRevisionId
154:                        .newInstance("myorg/mydep", "system/module", "1.0"));
155:                assertTrue(resolvedIvyFileInCache.exists());
156:
157:                // dependencies
158:                assertTrue(getIvyFileInCache(
159:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
160:                        .exists());
161:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
162:                        "mod1.2", "jar", "jar").exists());
163:
164:                assertTrue(getIvyFileInCache(
165:                        ModuleRevisionId.newInstance("yourorg/yourdep",
166:                                "yoursys/yourmod", "1.0")).exists());
167:                assertTrue(getArchiveFileInCache("yourorg/yourdep",
168:                        "yoursys/yourmod", "1.0", "yourmod", "jar", "jar")
169:                        .exists());
170:            }
171:
172:            public void testDepsChanged() throws Exception {
173:                resolve.setFile(new File(
174:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
175:                resolve.execute();
176:
177:                assertEquals("true", getIvy().getVariable("ivy.deps.changed"));
178:
179:                resolve.execute();
180:
181:                assertEquals("false", getIvy().getVariable("ivy.deps.changed"));
182:            }
183:
184:            public void testConflictingDepsChanged() throws Exception {
185:                resolve.setFile(new File(
186:                        "test/repositories/2/mod4.1/ivy-4.1.xml"));
187:                resolve.execute();
188:
189:                assertEquals("true", getIvy().getVariable("ivy.deps.changed"));
190:
191:                resolve.execute();
192:
193:                assertEquals("false", getIvy().getVariable("ivy.deps.changed"));
194:            }
195:
196:            public void testDouble() throws Exception {
197:                resolve.setFile(new File(
198:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
199:                resolve.execute();
200:
201:                assertEquals("resolve-simple", getIvy().getVariable(
202:                        "ivy.module"));
203:                assertEquals("1.0", getIvy().getVariable("ivy.revision"));
204:
205:                resolve.setFile(new File(
206:                        "test/java/org/apache/ivy/ant/ivy-double.xml"));
207:                resolve.execute();
208:
209:                assertEquals("resolve-double", getIvy().getVariable(
210:                        "ivy.module"));
211:                assertEquals("1.1", getIvy().getVariable("ivy.revision"));
212:            }
213:
214:            public void testFailure() throws Exception {
215:                try {
216:                    resolve.setFile(new File(
217:                            "test/java/org/apache/ivy/ant/ivy-failure.xml"));
218:                    resolve.execute();
219:                    fail("failure didn't raised an exception with default haltonfailure setting");
220:                } catch (BuildException ex) {
221:                    // ok => should raise an exception
222:                }
223:            }
224:
225:            public void testFailureWithMissingConfigurations() throws Exception {
226:                try {
227:                    resolve.setFile(new File(
228:                            "test/java/org/apache/ivy/ant/ivy-simple.xml"));
229:                    resolve.setConf("default,unknown");
230:                    resolve.execute();
231:                    fail("missing configurations didn't raised an exception");
232:                } catch (BuildException ex) {
233:                    assertTrue(ex.getMessage().indexOf("unknown") != -1);
234:                }
235:            }
236:
237:            public void testFailureOnBadDependencyIvyFile() throws Exception {
238:                try {
239:                    resolve.setFile(new File(
240:                            "test/java/org/apache/ivy/ant/ivy-failure2.xml"));
241:                    resolve.execute();
242:                    fail("failure didn't raised an exception with default haltonfailure setting");
243:                } catch (BuildException ex) {
244:                    // ok => should raise an exception
245:                }
246:            }
247:
248:            public void testFailureOnBadStatusInDependencyIvyFile()
249:                    throws Exception {
250:                try {
251:                    resolve.setFile(new File(
252:                            "test/java/org/apache/ivy/ant/ivy-failure3.xml"));
253:                    resolve.execute();
254:                    fail("failure didn't raised an exception with default haltonfailure setting");
255:                } catch (BuildException ex) {
256:                    // ok => should raise an exception
257:                }
258:            }
259:
260:            public void testHaltOnFailure() throws Exception {
261:                try {
262:                    resolve.setFile(new File(
263:                            "test/java/org/apache/ivy/ant/ivy-failure.xml"));
264:                    resolve.setHaltonfailure(false);
265:                    resolve.execute();
266:                } catch (BuildException ex) {
267:                    ex.printStackTrace();
268:                    fail("failure raised an exception with haltonfailure set to false");
269:                }
270:            }
271:
272:            public void testWithResolveId() throws Exception {
273:                resolve.setFile(new File(
274:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
275:                resolve.setResolveId("testWithResolveId");
276:                resolve.execute();
277:
278:                assertTrue(getResolvedIvyFileInCache(
279:                        ModuleRevisionId.newInstance("apache",
280:                                "resolve-simple", "1.0")).exists());
281:                assertTrue(getIvy().getResolutionCacheManager()
282:                        .getConfigurationResolveReportInCache(
283:                                "testWithResolveId", "default").exists());
284:
285:                // dependencies
286:                assertTrue(getIvyFileInCache(
287:                        ModuleRevisionId.newInstance("org1", "mod1.2", "2.0"))
288:                        .exists());
289:                assertTrue(getArchiveFileInCache("org1", "mod1.2", "2.0",
290:                        "mod1.2", "jar", "jar").exists());
291:
292:                // test the properties
293:                Project project = resolve.getProject();
294:                assertEquals("apache", project.getProperty("ivy.organisation"));
295:                assertEquals("apache", project
296:                        .getProperty("ivy.organisation.testWithResolveId"));
297:                assertEquals("resolve-simple", project
298:                        .getProperty("ivy.module"));
299:                assertEquals("resolve-simple", project
300:                        .getProperty("ivy.module.testWithResolveId"));
301:                assertEquals("1.0", project.getProperty("ivy.revision"));
302:                assertEquals("1.0", project
303:                        .getProperty("ivy.revision.testWithResolveId"));
304:                assertEquals("true", project.getProperty("ivy.deps.changed"));
305:                assertEquals("true", project
306:                        .getProperty("ivy.deps.changed.testWithResolveId"));
307:                assertEquals("default", project
308:                        .getProperty("ivy.resolved.configurations"));
309:                assertEquals(
310:                        "default",
311:                        project
312:                                .getProperty("ivy.resolved.configurations.testWithResolveId"));
313:
314:                // test the references
315:                assertNotNull(project.getReference("ivy.resolved.report"));
316:                assertNotNull(project
317:                        .getReference("ivy.resolved.report.testWithResolveId"));
318:                assertNotNull(project.getReference("ivy.resolved.descriptor"));
319:                assertNotNull(project
320:                        .getReference("ivy.resolved.descriptor.testWithResolveId"));
321:                assertNotNull(project
322:                        .getReference("ivy.resolved.configurations.ref"));
323:                assertNotNull(project
324:                        .getReference("ivy.resolved.configurations.ref.testWithResolveId"));
325:            }
326:
327:            public void testDoubleResolveWithResolveId() throws Exception {
328:                resolve.setFile(new File(
329:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
330:                resolve.setResolveId("testWithResolveId");
331:                resolve.execute();
332:
333:                IvyResolve newResolve = new IvyResolve();
334:                newResolve.setProject(resolve.getProject());
335:                newResolve.setFile(new File(
336:                        "test/java/org/apache/ivy/ant/ivy-simple2.xml"));
337:                newResolve.execute();
338:
339:                // test the properties
340:                Project project = resolve.getProject();
341:                assertEquals("apache2", project.getProperty("ivy.organisation"));
342:                assertEquals("apache", project
343:                        .getProperty("ivy.organisation.testWithResolveId"));
344:                assertEquals("resolve-simple2", project
345:                        .getProperty("ivy.module"));
346:                assertEquals("resolve-simple", project
347:                        .getProperty("ivy.module.testWithResolveId"));
348:                assertEquals("1.1", project.getProperty("ivy.revision"));
349:                assertEquals("1.0", project
350:                        .getProperty("ivy.revision.testWithResolveId"));
351:                assertEquals("true", project.getProperty("ivy.deps.changed"));
352:                assertEquals("true", project
353:                        .getProperty("ivy.deps.changed.testWithResolveId"));
354:                assertEquals("default", project
355:                        .getProperty("ivy.resolved.configurations"));
356:                assertEquals(
357:                        "default",
358:                        project
359:                                .getProperty("ivy.resolved.configurations.testWithResolveId"));
360:
361:                // test the references
362:                assertNotNull(project.getReference("ivy.resolved.report"));
363:                assertNotNull(project
364:                        .getReference("ivy.resolved.report.testWithResolveId"));
365:                assertNotNull(project.getReference("ivy.resolved.descriptor"));
366:                assertNotNull(project
367:                        .getReference("ivy.resolved.descriptor.testWithResolveId"));
368:                assertNotNull(project
369:                        .getReference("ivy.resolved.configurations.ref"));
370:                assertNotNull(project
371:                        .getReference("ivy.resolved.configurations.ref.testWithResolveId"));
372:            }
373:
374:            public void testDifferentResolveWithSameResolveId()
375:                    throws Exception {
376:                resolve.setFile(new File(
377:                        "test/java/org/apache/ivy/ant/ivy-simple.xml"));
378:                resolve.setResolveId("testWithResolveId");
379:                resolve.execute();
380:
381:                IvyResolve newResolve = new IvyResolve();
382:                newResolve.setProject(resolve.getProject());
383:                newResolve.setFile(new File(
384:                        "test/java/org/apache/ivy/ant/ivy-simple2.xml"));
385:                newResolve.setResolveId("testWithResolveId");
386:                newResolve.execute();
387:
388:                // test the properties
389:                Project project = resolve.getProject();
390:                assertEquals("apache2", project.getProperty("ivy.organisation"));
391:                assertEquals("apache2", project
392:                        .getProperty("ivy.organisation.testWithResolveId"));
393:                assertEquals("resolve-simple2", project
394:                        .getProperty("ivy.module"));
395:                assertEquals("resolve-simple2", project
396:                        .getProperty("ivy.module.testWithResolveId"));
397:                assertEquals("1.1", project.getProperty("ivy.revision"));
398:                assertEquals("1.1", project
399:                        .getProperty("ivy.revision.testWithResolveId"));
400:                assertEquals("true", project.getProperty("ivy.deps.changed"));
401:                assertEquals("true", project
402:                        .getProperty("ivy.deps.changed.testWithResolveId"));
403:                assertEquals("default", project
404:                        .getProperty("ivy.resolved.configurations"));
405:                assertEquals(
406:                        "default",
407:                        project
408:                                .getProperty("ivy.resolved.configurations.testWithResolveId"));
409:
410:                // test the references
411:                assertNotNull(project.getReference("ivy.resolved.report"));
412:                assertNotNull(project
413:                        .getReference("ivy.resolved.report.testWithResolveId"));
414:                assertNotNull(project.getReference("ivy.resolved.descriptor"));
415:                assertNotNull(project
416:                        .getReference("ivy.resolved.descriptor.testWithResolveId"));
417:                assertNotNull(project
418:                        .getReference("ivy.resolved.configurations.ref"));
419:                assertNotNull(project
420:                        .getReference("ivy.resolved.configurations.ref.testWithResolveId"));
421:            }
422:
423:            public void testResolveWithAbsoluteFile() {
424:                // IVY-396
425:                File ivyFile = new File(
426:                        "test/java/org/apache/ivy/ant/ivy-simple.xml");
427:                resolve.getProject().setProperty("ivy.dep.file",
428:                        ivyFile.getAbsolutePath());
429:                resolve.execute();
430:
431:                assertTrue(getResolvedIvyFileInCache(
432:                        ModuleRevisionId.newInstance("apache",
433:                                "resolve-simple", "1.0")).exists());
434:            }
435:
436:            public void testResolveWithRelativeFile() {
437:                // IVY-396
438:                resolve.getProject().setProperty("ivy.dep.file",
439:                        "test/java/org/apache/ivy/ant/ivy-simple.xml");
440:                resolve.execute();
441:
442:                assertTrue(getResolvedIvyFileInCache(
443:                        ModuleRevisionId.newInstance("apache",
444:                                "resolve-simple", "1.0")).exists());
445:            }
446:
447:            private Ivy getIvy() {
448:                return resolve.getIvyInstance();
449:            }
450:
451:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.