Source Code Cross Referenced for PomModuleDescriptorParserTest.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » plugins » parser » m2 » 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.plugins.parser.m2 
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.plugins.parser.m2;
019:
020:        import java.io.File;
021:        import java.io.IOException;
022:        import java.text.ParseException;
023:        import java.util.Arrays;
024:        import java.util.Collections;
025:        import java.util.HashSet;
026:        import java.util.Map;
027:
028:        import org.apache.ivy.core.module.descriptor.Artifact;
029:        import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
030:        import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
031:        import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
032:        import org.apache.ivy.core.module.id.ModuleId;
033:        import org.apache.ivy.core.module.id.ModuleRevisionId;
034:        import org.apache.ivy.core.resolve.ResolveData;
035:        import org.apache.ivy.core.resolve.ResolvedModuleRevision;
036:        import org.apache.ivy.core.settings.IvySettings;
037:        import org.apache.ivy.plugins.parser.AbstractModuleDescriptorParserTester;
038:        import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
039:        import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest;
040:        import org.apache.ivy.plugins.repository.url.URLResource;
041:        import org.apache.ivy.plugins.resolver.MockResolver;
042:
043:        public class PomModuleDescriptorParserTest extends
044:                AbstractModuleDescriptorParserTester {
045:            // junit test -- DO NOT REMOVE used by ant to know it's a junit test
046:
047:            private IvySettings settings = new IvySettings();
048:
049:            private class MockedDependencyResolver extends MockResolver {
050:                public ResolvedModuleRevision getDependency(
051:                        DependencyDescriptor dd, ResolveData data)
052:                        throws ParseException {
053:                    //TODO make it a real mock and check that dd and data are the one that are expected
054:                    DefaultModuleDescriptor moduleDesc = DefaultModuleDescriptor
055:                            .newDefaultInstance(dd.getDependencyRevisionId());
056:                    ResolvedModuleRevision r = new ResolvedModuleRevision(this ,
057:                            this , moduleDesc, null);
058:                    return r;
059:                }
060:            }
061:
062:            private File dest = new File("build/test/test-write.xml");
063:            private MockResolver mockedResolver = new MockedDependencyResolver();
064:
065:            protected void setUp() throws Exception {
066:                settings.setDictatorResolver(mockedResolver);
067:                super .setUp();
068:                if (dest.exists()) {
069:                    dest.delete();
070:                }
071:                if (!dest.getParentFile().exists()) {
072:                    dest.getParentFile().mkdirs();
073:                }
074:            }
075:
076:            protected void tearDown() throws Exception {
077:                if (dest.exists()) {
078:                    dest.delete();
079:                }
080:            }
081:
082:            public void testAccept() throws Exception {
083:                assertTrue(PomModuleDescriptorParser.getInstance().accept(
084:                        new URLResource(getClass().getResource(
085:                                "test-simple.pom"))));
086:                assertFalse(PomModuleDescriptorParser.getInstance().accept(
087:                        new URLResource(XmlModuleDescriptorParserTest.class
088:                                .getResource("test.xml"))));
089:            }
090:
091:            public void testSimple() throws Exception {
092:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
093:                        .parseDescriptor(settings,
094:                                getClass().getResource("test-simple.pom"),
095:                                false);
096:                assertNotNull(md);
097:
098:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
099:                        "org.apache", "test", "1.0");
100:                assertEquals(mrid, md.getModuleRevisionId());
101:
102:                assertNotNull(md.getConfigurations());
103:                assertEquals(
104:                        Arrays
105:                                .asList(PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS),
106:                        Arrays.asList(md.getConfigurations()));
107:
108:                Artifact[] artifact = md.getArtifacts("master");
109:                assertEquals(1, artifact.length);
110:                assertEquals(mrid, artifact[0].getModuleRevisionId());
111:                assertEquals("test", artifact[0].getName());
112:                assertEquals("jar", artifact[0].getExt());
113:                assertEquals("jar", artifact[0].getType());
114:            }
115:
116:            public void testPackaging() throws Exception {
117:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
118:                        .parseDescriptor(settings,
119:                                getClass().getResource("test-packaging.pom"),
120:                                false);
121:                assertNotNull(md);
122:
123:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
124:                        "org.apache", "test", "1.0");
125:                assertEquals(mrid, md.getModuleRevisionId());
126:
127:                Artifact[] artifact = md.getArtifacts("master");
128:                assertEquals(1, artifact.length);
129:                assertEquals(mrid, artifact[0].getModuleRevisionId());
130:                assertEquals("test", artifact[0].getName());
131:                assertEquals("war", artifact[0].getExt());
132:                assertEquals("war", artifact[0].getType());
133:            }
134:
135:            public void testParent() throws Exception {
136:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
137:                        .parseDescriptor(settings,
138:                                getClass().getResource("test-parent.pom"),
139:                                false);
140:                assertNotNull(md);
141:
142:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
143:                        "org.apache", "test", "1.0");
144:                assertEquals(mrid, md.getModuleRevisionId());
145:
146:                Artifact[] artifact = md.getArtifacts("master");
147:                assertEquals(1, artifact.length);
148:                assertEquals(mrid, artifact[0].getModuleRevisionId());
149:                assertEquals("test", artifact[0].getName());
150:            }
151:
152:            public void testParent2() throws Exception {
153:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
154:                        .parseDescriptor(settings,
155:                                getClass().getResource("test-parent2.pom"),
156:                                false);
157:                assertNotNull(md);
158:
159:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
160:                        "org.apache", "test", "1.0");
161:                assertEquals(mrid, md.getModuleRevisionId());
162:
163:                Artifact[] artifact = md.getArtifacts("master");
164:                assertEquals(1, artifact.length);
165:                assertEquals(mrid, artifact[0].getModuleRevisionId());
166:                assertEquals("test", artifact[0].getName());
167:            }
168:
169:            public void testParentVersion() throws Exception {
170:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
171:                        .parseDescriptor(
172:                                settings,
173:                                getClass().getResource(
174:                                        "test-parent.version.pom"), false);
175:                assertNotNull(md);
176:
177:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
178:                        "org.apache", "test", "1.0");
179:                assertEquals(mrid, md.getModuleRevisionId());
180:
181:                Artifact[] artifact = md.getArtifacts("master");
182:                assertEquals(1, artifact.length);
183:                assertEquals(mrid, artifact[0].getModuleRevisionId());
184:                assertEquals("test", artifact[0].getName());
185:            }
186:
187:            public void testDependencies() throws Exception {
188:                ModuleDescriptor md = PomModuleDescriptorParser
189:                        .getInstance()
190:                        .parseDescriptor(
191:                                settings,
192:                                getClass().getResource("test-dependencies.pom"),
193:                                false);
194:                assertNotNull(md);
195:
196:                assertEquals(ModuleRevisionId.newInstance("org.apache", "test",
197:                        "1.0"), md.getModuleRevisionId());
198:
199:                DependencyDescriptor[] dds = md.getDependencies();
200:                assertNotNull(dds);
201:                assertEquals(1, dds.length);
202:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
203:                        "commons-logging", "1.0.4"), dds[0]
204:                        .getDependencyRevisionId());
205:                assertEquals(
206:                        "There is no special artifact when there is no classifier",
207:                        0, dds[0].getAllDependencyArtifacts().length);
208:            }
209:
210:            public void testDependenciesWithClassifier() throws Exception {
211:                ModuleDescriptor md = PomModuleDescriptorParser
212:                        .getInstance()
213:                        .parseDescriptor(
214:                                settings,
215:                                getClass()
216:                                        .getResource(
217:                                                "test-dependencies-with-classifier.pom"),
218:                                true);
219:                assertNotNull(md);
220:
221:                assertEquals(ModuleRevisionId.newInstance("org.apache", "test",
222:                        "1.0"), md.getModuleRevisionId());
223:
224:                DependencyDescriptor[] dds = md.getDependencies();
225:                assertNotNull(dds);
226:                assertEquals(1, dds.length);
227:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
228:                        "commons-logging", "1.0.4"), dds[0]
229:                        .getDependencyRevisionId());
230:                Map extraAtt = Collections.singletonMap("classifier", "asl");
231:                assertEquals(1, dds[0].getAllDependencyArtifacts().length);
232:                assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0]
233:                        .getExtraAttributes());
234:
235:                // now we verify the conversion to an Ivy file
236:                PomModuleDescriptorParser.getInstance().toIvyFile(
237:                        getClass().getResource(
238:                                "test-dependencies-with-classifier.pom")
239:                                .openStream(),
240:                        new URLResource(getClass().getResource(
241:                                "test-dependencies-with-classifier.pom")),
242:                        dest, md);
243:
244:                assertTrue(dest.exists());
245:
246:                // the converted Ivy file should be parsable with validate=true
247:                ModuleDescriptor md2 = XmlModuleDescriptorParser.getInstance()
248:                        .parseDescriptor(new IvySettings(), dest.toURL(), true);
249:
250:                // and the parsed module descriptor should be similar to the original
251:                assertNotNull(md2);
252:                assertEquals(md.getModuleRevisionId(), md2
253:                        .getModuleRevisionId());
254:                dds = md2.getDependencies();
255:                assertEquals(1, dds[0].getAllDependencyArtifacts().length);
256:                assertEquals(extraAtt, dds[0].getAllDependencyArtifacts()[0]
257:                        .getExtraAttributes());
258:            }
259:
260:            public void testWithVersionPropertyAndPropertiesTag()
261:                    throws Exception {
262:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
263:                        .parseDescriptor(settings,
264:                                getClass().getResource("test-version.pom"),
265:                                false);
266:                assertNotNull(md);
267:
268:                DependencyDescriptor[] dds = md.getDependencies();
269:                assertNotNull(dds);
270:                assertEquals(2, dds.length);
271:                assertEquals(ModuleRevisionId.newInstance("org.apache",
272:                        "test-other", "1.0"), dds[0].getDependencyRevisionId());
273:                assertEquals(ModuleRevisionId.newInstance("org.apache",
274:                        "test-yet-other", "5.76"), dds[1]
275:                        .getDependencyRevisionId());
276:            }
277:
278:            // IVY-392
279:            public void testDependenciesWithProfile() throws Exception {
280:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
281:                        .parseDescriptor(
282:                                settings,
283:                                getClass().getResource(
284:                                        "test-dependencies-with-profile.pom"),
285:                                false);
286:                assertNotNull(md);
287:
288:                assertEquals(ModuleRevisionId.newInstance("org.apache", "test",
289:                        "1.0"), md.getModuleRevisionId());
290:
291:                DependencyDescriptor[] dds = md.getDependencies();
292:                assertNotNull(dds);
293:                assertEquals(1, dds.length);
294:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
295:                        "commons-logging", "1.0.4"), dds[0]
296:                        .getDependencyRevisionId());
297:            }
298:
299:            public void testWithoutVersion() throws Exception {
300:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
301:                        .parseDescriptor(
302:                                settings,
303:                                getClass().getResource(
304:                                        "test-without-version.pom"), false);
305:                assertNotNull(md);
306:
307:                assertEquals(new ModuleId("org.apache", "test"), md
308:                        .getModuleRevisionId().getModuleId());
309:
310:                DependencyDescriptor[] dds = md.getDependencies();
311:                assertNotNull(dds);
312:                assertEquals(1, dds.length);
313:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
314:                        "commons-logging", "1.0.4"), dds[0]
315:                        .getDependencyRevisionId());
316:            }
317:
318:            public void testProperties() throws Exception {
319:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
320:                        .parseDescriptor(settings,
321:                                getClass().getResource("test-properties.pom"),
322:                                false);
323:                assertNotNull(md);
324:
325:                assertEquals(ModuleRevisionId.newInstance("drools",
326:                        "drools-smf", "2.0-beta-18"), md.getModuleRevisionId());
327:
328:                DependencyDescriptor[] dds = md.getDependencies();
329:                assertNotNull(dds);
330:                assertEquals(1, dds.length);
331:                assertEquals(ModuleRevisionId.newInstance("drools",
332:                        "drools-core", "2.0-beta-18"), dds[0]
333:                        .getDependencyRevisionId());
334:            }
335:
336:            public void testReal() throws Exception {
337:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
338:                        .parseDescriptor(settings,
339:                                getClass().getResource("commons-lang-1.0.pom"),
340:                                false);
341:                assertNotNull(md);
342:
343:                assertEquals(ModuleRevisionId.newInstance("commons-lang",
344:                        "commons-lang", "1.0"), md.getModuleRevisionId());
345:
346:                DependencyDescriptor[] dds = md.getDependencies();
347:                assertNotNull(dds);
348:                assertEquals(1, dds.length);
349:                assertEquals(ModuleRevisionId.newInstance("junit", "junit",
350:                        "3.7"), dds[0].getDependencyRevisionId());
351:            }
352:
353:            public void testReal2() throws Exception {
354:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
355:                        .parseDescriptor(
356:                                settings,
357:                                getClass().getResource(
358:                                        "wicket-1.3-incubating-SNAPSHOT.pom"),
359:                                false);
360:                assertNotNull(md);
361:
362:                assertEquals(ModuleRevisionId.newInstance("org.apache.wicket",
363:                        "wicket", "1.3-incubating-SNAPSHOT"), md
364:                        .getModuleRevisionId());
365:            }
366:
367:            public void testVariables() throws Exception {
368:                // test case for IVY-425
369:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
370:                        .parseDescriptor(
371:                                settings,
372:                                getClass().getResource(
373:                                        "spring-hibernate3-2.0.2.pom"), false);
374:                assertNotNull(md);
375:
376:                assertEquals(ModuleRevisionId.newInstance(
377:                        "org.springframework", "spring-hibernate3", "2.0.2"),
378:                        md.getModuleRevisionId());
379:
380:                DependencyDescriptor[] dds = md.getDependencies();
381:                assertNotNull(dds);
382:                assertEquals(11, dds.length);
383:                assertEquals(ModuleRevisionId.newInstance(
384:                        "org.springframework", "spring-web", "2.0.2"), dds[10]
385:                        .getDependencyRevisionId());
386:            }
387:
388:            public void testDependenciesInProfile() throws Exception {
389:                // test case for IVY-423
390:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
391:                        .parseDescriptor(
392:                                settings,
393:                                getClass().getResource(
394:                                        "mule-module-builders-1.3.3.pom"),
395:                                false);
396:                assertNotNull(md);
397:
398:                assertEquals(ModuleRevisionId.newInstance("org.mule.modules",
399:                        "mule-module-builders", "1.3.3"), md
400:                        .getModuleRevisionId());
401:            }
402:
403:            public void testIVY424() throws Exception {
404:                // test case for IVY-424
405:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
406:                        .parseDescriptor(
407:                                settings,
408:                                getClass().getResource(
409:                                        "shale-tiger-1.1.0-SNAPSHOT.pom"),
410:                                false);
411:                assertNotNull(md);
412:
413:                assertEquals(ModuleRevisionId.newInstance("org.apache.shale",
414:                        "shale-tiger", "1.1.0-SNAPSHOT"), md
415:                        .getModuleRevisionId());
416:            }
417:
418:            public void testOptional() throws Exception {
419:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
420:                        .parseDescriptor(settings,
421:                                getClass().getResource("test-optional.pom"),
422:                                false);
423:                assertNotNull(md);
424:
425:                assertEquals(ModuleRevisionId.newInstance("org.apache", "test",
426:                        "1.0"), md.getModuleRevisionId());
427:                assertTrue(Arrays.asList(md.getConfigurationsNames()).contains(
428:                        "optional"));
429:
430:                DependencyDescriptor[] dds = md.getDependencies();
431:                assertNotNull(dds);
432:                assertEquals(2, dds.length);
433:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
434:                        "commons-logging", "1.0.4"), dds[0]
435:                        .getDependencyRevisionId());
436:                assertEquals(new HashSet(Arrays
437:                        .asList(new String[] { "optional" })), new HashSet(
438:                        Arrays.asList(dds[0].getModuleConfigurations())));
439:                //I don't know what it should be.  Ivy has no notion of optional dependencies
440:                //assertEquals(new HashSet(Arrays.asList(new String[] {"compile(*)", "runtime(*)",
441:                //        "master(*)"})), new HashSet(Arrays.asList(dds[0]
442:                //        .getDependencyConfigurations("optional"))));
443:
444:                assertEquals(ModuleRevisionId.newInstance("cglib", "cglib",
445:                        "2.0.2"), dds[1].getDependencyRevisionId());
446:                assertEquals(new HashSet(Arrays.asList(new String[] {
447:                        "compile", "runtime" })), new HashSet(Arrays
448:                        .asList(dds[1].getModuleConfigurations())));
449:                assertEquals(new HashSet(Arrays.asList(new String[] {
450:                        "master(*)", "compile(*)" })), new HashSet(Arrays
451:                        .asList(dds[1].getDependencyConfigurations("compile"))));
452:                assertEquals(new HashSet(Arrays
453:                        .asList(new String[] { "runtime(*)" })), new HashSet(
454:                        Arrays.asList(dds[1]
455:                                .getDependencyConfigurations("runtime"))));
456:            }
457:
458:            public void testDependenciesWithScope() throws Exception {
459:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
460:                        .parseDescriptor(
461:                                settings,
462:                                getClass().getResource(
463:                                        "test-dependencies-with-scope.pom"),
464:                                false);
465:                assertNotNull(md);
466:
467:                assertEquals(ModuleRevisionId.newInstance("org.apache", "test",
468:                        "1.0"), md.getModuleRevisionId());
469:
470:                DependencyDescriptor[] dds = md.getDependencies();
471:                assertNotNull(dds);
472:                assertEquals(3, dds.length);
473:                assertEquals(ModuleRevisionId
474:                        .newInstance("odmg", "odmg", "3.0"), dds[0]
475:                        .getDependencyRevisionId());
476:                assertEquals(new HashSet(Arrays
477:                        .asList(new String[] { "runtime" })), new HashSet(
478:                        Arrays.asList(dds[0].getModuleConfigurations())));
479:                assertEquals(new HashSet(Arrays.asList(new String[] {
480:                        "compile(*)", "runtime(*)", "master(*)" })),
481:                        new HashSet(Arrays.asList(dds[0]
482:                                .getDependencyConfigurations("runtime"))));
483:
484:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
485:                        "commons-logging", "1.0.4"), dds[1]
486:                        .getDependencyRevisionId());
487:                assertEquals(new HashSet(Arrays.asList(new String[] {
488:                        "compile", "runtime" })), new HashSet(Arrays
489:                        .asList(dds[1].getModuleConfigurations())));
490:                assertEquals(new HashSet(Arrays.asList(new String[] {
491:                        "master(*)", "compile(*)" })), new HashSet(Arrays
492:                        .asList(dds[1].getDependencyConfigurations("compile"))));
493:                assertEquals(new HashSet(Arrays
494:                        .asList(new String[] { "runtime(*)" })), new HashSet(
495:                        Arrays.asList(dds[1]
496:                                .getDependencyConfigurations("runtime"))));
497:
498:                assertEquals(ModuleRevisionId.newInstance("cglib", "cglib",
499:                        "2.0.2"), dds[2].getDependencyRevisionId());
500:                assertEquals(new HashSet(Arrays.asList(new String[] {
501:                        "compile", "runtime" })), new HashSet(Arrays
502:                        .asList(dds[2].getModuleConfigurations())));
503:                assertEquals(new HashSet(Arrays.asList(new String[] {
504:                        "master(*)", "compile(*)" })), new HashSet(Arrays
505:                        .asList(dds[2].getDependencyConfigurations("compile"))));
506:                assertEquals(new HashSet(Arrays
507:                        .asList(new String[] { "runtime(*)" })), new HashSet(
508:                        Arrays.asList(dds[2]
509:                                .getDependencyConfigurations("runtime"))));
510:            }
511:
512:            public void testExclusion() throws Exception {
513:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
514:                        .parseDescriptor(settings,
515:                                getClass().getResource("test-exclusion.pom"),
516:                                false);
517:                assertNotNull(md);
518:
519:                assertEquals(ModuleRevisionId.newInstance("org.apache", "test",
520:                        "1.0"), md.getModuleRevisionId());
521:
522:                DependencyDescriptor[] dds = md.getDependencies();
523:                assertNotNull(dds);
524:                assertEquals(3, dds.length);
525:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
526:                        "commons-logging", "1.0.4"), dds[0]
527:                        .getDependencyRevisionId());
528:                assertEquals(new HashSet(Arrays.asList(new String[] {
529:                        "compile", "runtime" })), new HashSet(Arrays
530:                        .asList(dds[0].getModuleConfigurations())));
531:                assertEquals(new HashSet(Arrays.asList(new String[] {
532:                        "master(*)", "compile(*)" })), new HashSet(Arrays
533:                        .asList(dds[0].getDependencyConfigurations("compile"))));
534:                assertEquals(new HashSet(Arrays
535:                        .asList(new String[] { "runtime(*)" })), new HashSet(
536:                        Arrays.asList(dds[0]
537:                                .getDependencyConfigurations("runtime"))));
538:                assertEquals(0, dds[0].getAllExcludeRules().length);
539:
540:                assertEquals(ModuleRevisionId.newInstance("dom4j", "dom4j",
541:                        "1.6"), dds[1].getDependencyRevisionId());
542:                assertEquals(new HashSet(Arrays.asList(new String[] {
543:                        "compile", "runtime" })), new HashSet(Arrays
544:                        .asList(dds[1].getModuleConfigurations())));
545:                assertEquals(new HashSet(Arrays.asList(new String[] {
546:                        "master(*)", "compile(*)" })), new HashSet(Arrays
547:                        .asList(dds[1].getDependencyConfigurations("compile"))));
548:                assertEquals(new HashSet(Arrays
549:                        .asList(new String[] { "runtime(*)" })), new HashSet(
550:                        Arrays.asList(dds[1]
551:                                .getDependencyConfigurations("runtime"))));
552:                assertDependencyModulesExcludes(dds[1],
553:                        new String[] { "compile" }, new String[] { "jaxme-api",
554:                                "jaxen" });
555:                assertDependencyModulesExcludes(dds[1],
556:                        new String[] { "runtime" }, new String[] { "jaxme-api",
557:                                "jaxen" });
558:
559:                assertEquals(ModuleRevisionId.newInstance("cglib", "cglib",
560:                        "2.0.2"), dds[2].getDependencyRevisionId());
561:                assertEquals(new HashSet(Arrays.asList(new String[] {
562:                        "compile", "runtime" })), new HashSet(Arrays
563:                        .asList(dds[2].getModuleConfigurations())));
564:                assertEquals(new HashSet(Arrays.asList(new String[] {
565:                        "master(*)", "compile(*)" })), new HashSet(Arrays
566:                        .asList(dds[2].getDependencyConfigurations("compile"))));
567:                assertEquals(new HashSet(Arrays
568:                        .asList(new String[] { "runtime(*)" })), new HashSet(
569:                        Arrays.asList(dds[2]
570:                                .getDependencyConfigurations("runtime"))));
571:                assertEquals(0, dds[2].getAllExcludeRules().length);
572:            }
573:
574:            public void testWithPlugins() throws Exception {
575:                // test case for IVY-417
576:                ModuleDescriptor md = PomModuleDescriptorParser
577:                        .getInstance()
578:                        .parseDescriptor(settings,
579:                                getClass().getResource("mule-1.3.3.pom"), false);
580:                assertNotNull(md);
581:
582:                assertEquals(ModuleRevisionId.newInstance("org.mule", "mule",
583:                        "1.3.3"), md.getModuleRevisionId());
584:
585:                DependencyDescriptor[] dds = md.getDependencies();
586:                assertNotNull(dds);
587:                assertEquals(0, dds.length);
588:            }
589:
590:            public void testDependencyManagment() throws ParseException,
591:                    IOException {
592:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
593:                        .parseDescriptor(
594:                                settings,
595:                                getClass().getResource(
596:                                        "test-dependencieMgt.pom"), false);
597:                assertNotNull(md);
598:                assertEquals(ModuleRevisionId.newInstance("org.apache",
599:                        "test-depMgt", "1.0"), md.getModuleRevisionId());
600:
601:                DependencyDescriptor[] dds = md.getDependencies();
602:                assertNotNull(dds);
603:                assertEquals(1, dds.length);
604:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
605:                        "commons-logging", "1.0.4"), dds[0]
606:                        .getDependencyRevisionId());
607:                assertEquals(
608:                        "There is no special artifact when there is no classifier",
609:                        0, dds[0].getAllDependencyArtifacts().length);
610:
611:            }
612:
613:            public void testParentDependencyMgt() throws ParseException,
614:                    IOException {
615:                settings.setDictatorResolver(new MockResolver() {
616:                    public ResolvedModuleRevision getDependency(
617:                            DependencyDescriptor dd, ResolveData data)
618:                            throws ParseException {
619:                        try {
620:                            ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser
621:                                    .getInstance().parseDescriptor(
622:                                            settings,
623:                                            getClass().getResource(
624:                                                    "test-dependencieMgt.pom"),
625:                                            false);
626:                            return new ResolvedModuleRevision(null, null,
627:                                    moduleDescriptor, null);
628:                        } catch (IOException e) {
629:                            throw new AssertionError(e);
630:                        }
631:                    }
632:                });
633:
634:                ModuleDescriptor md = PomModuleDescriptorParser
635:                        .getInstance()
636:                        .parseDescriptor(
637:                                settings,
638:                                getClass().getResource(
639:                                        "test-parentDependencieMgt.pom"), false);
640:                assertNotNull(md);
641:                assertEquals(ModuleRevisionId.newInstance("org.apache",
642:                        "test-parentdep", "1.0"), md.getModuleRevisionId());
643:
644:                DependencyDescriptor[] dds = md.getDependencies();
645:                assertNotNull(dds);
646:                assertEquals(2, dds.length);
647:                assertEquals(ModuleRevisionId.newInstance("commons-collection",
648:                        "commons-collection", "1.0.5"), dds[0]
649:                        .getDependencyRevisionId());
650:                assertEquals(ModuleRevisionId.newInstance("commons-logging",
651:                        "commons-logging", "1.0.4"), dds[1]
652:                        .getDependencyRevisionId());
653:            }
654:
655:            public void testParentProperties() throws ParseException,
656:                    IOException {
657:                settings.setDictatorResolver(new MockResolver() {
658:                    public ResolvedModuleRevision getDependency(
659:                            DependencyDescriptor dd, ResolveData data)
660:                            throws ParseException {
661:                        try {
662:                            ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser
663:                                    .getInstance().parseDescriptor(
664:                                            settings,
665:                                            getClass().getResource(
666:                                                    "test-version.pom"), false);
667:                            return new ResolvedModuleRevision(null, null,
668:                                    moduleDescriptor, null);
669:                        } catch (IOException e) {
670:                            throw new AssertionError(e);
671:                        }
672:                    }
673:                });
674:
675:                ModuleDescriptor md = PomModuleDescriptorParser.getInstance()
676:                        .parseDescriptor(
677:                                settings,
678:                                getClass().getResource(
679:                                        "test-parent-properties.pom"), false);
680:                assertNotNull(md);
681:
682:                DependencyDescriptor[] dds = md.getDependencies();
683:                assertNotNull(dds);
684:                assertEquals(3, dds.length);
685:                //2 are inherited from parent.  Only the first one is important for this test
686:
687:                assertEquals(ModuleRevisionId.newInstance("org.apache",
688:                        "test-version-other", "5.76"), dds[0]
689:                        .getDependencyRevisionId());//present in the pom using a property defined in the parent
690:
691:            }
692:
693:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.