Source Code Cross Referenced for URLResolverTest.java in  » Code-Analyzer » apache-ivy » org » apache » ivy » plugins » resolver » 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.resolver 
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.resolver;
019:
020:        import java.io.File;
021:        import java.util.Date;
022:        import java.util.GregorianCalendar;
023:
024:        import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
025:        import org.apache.ivy.core.event.EventManager;
026:        import org.apache.ivy.core.module.descriptor.Artifact;
027:        import org.apache.ivy.core.module.descriptor.DefaultArtifact;
028:        import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
029:        import org.apache.ivy.core.module.descriptor.DefaultIncludeRule;
030:        import org.apache.ivy.core.module.id.ArtifactId;
031:        import org.apache.ivy.core.module.id.ModuleRevisionId;
032:        import org.apache.ivy.core.report.ArtifactDownloadReport;
033:        import org.apache.ivy.core.report.DownloadReport;
034:        import org.apache.ivy.core.report.DownloadStatus;
035:        import org.apache.ivy.core.resolve.DownloadOptions;
036:        import org.apache.ivy.core.resolve.ResolveData;
037:        import org.apache.ivy.core.resolve.ResolveEngine;
038:        import org.apache.ivy.core.resolve.ResolveOptions;
039:        import org.apache.ivy.core.resolve.ResolvedModuleRevision;
040:        import org.apache.ivy.core.settings.IvySettings;
041:        import org.apache.ivy.core.sort.SortEngine;
042:        import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
043:        import org.apache.tools.ant.Project;
044:        import org.apache.tools.ant.taskdefs.Delete;
045:
046:        /**
047:         * Tests URLResolver. Http tests are based upon ibiblio site.
048:         */
049:        public class URLResolverTest extends AbstractDependencyResolverTest {
050:            // remote.test
051:            private IvySettings _settings;
052:
053:            private ResolveEngine _engine;
054:
055:            private ResolveData _data;
056:
057:            private File _cache;
058:
059:            protected void setUp() throws Exception {
060:                _settings = new IvySettings();
061:                _engine = new ResolveEngine(_settings, new EventManager(),
062:                        new SortEngine(_settings));
063:                _cache = new File("build/cache");
064:                _data = new ResolveData(_engine, new ResolveOptions());
065:                _cache.mkdirs();
066:                _settings.setDefaultCache(_cache);
067:            }
068:
069:            protected void tearDown() throws Exception {
070:                Delete del = new Delete();
071:                del.setProject(new Project());
072:                del.setDir(_cache);
073:                del.execute();
074:            }
075:
076:            public void testFile() throws Exception {
077:                URLResolver resolver = new URLResolver();
078:                resolver.setSettings(_settings);
079:                String rootpath = new File("test/repositories/1")
080:                        .getAbsolutePath();
081:                resolver.addIvyPattern("file:" + rootpath
082:                        + "/[organisation]/[module]/ivys/ivy-[revision].xml");
083:                resolver
084:                        .addArtifactPattern("file:"
085:                                + rootpath
086:                                + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
087:                resolver.setName("test");
088:                assertEquals("test", resolver.getName());
089:
090:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
091:                        "mod1.1", "1.0");
092:                ResolvedModuleRevision rmr = resolver.getDependency(
093:                        new DefaultDependencyDescriptor(mrid, false), _data);
094:                assertNotNull(rmr);
095:
096:                assertEquals(mrid, rmr.getId());
097:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
098:                        .getTime();
099:                assertEquals(pubdate, rmr.getPublicationDate());
100:
101:                // test to ask to download
102:                DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate,
103:                        "mod1.1", "jar", "jar");
104:                DownloadReport report = resolver.download(
105:                        new Artifact[] { artifact }, downloadOptions());
106:                assertNotNull(report);
107:
108:                assertEquals(1, report.getArtifactsReports().length);
109:
110:                ArtifactDownloadReport ar = report.getArtifactReport(artifact);
111:                assertNotNull(ar);
112:
113:                assertEquals(artifact, ar.getArtifact());
114:                assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
115:
116:                // test to ask to download again, should use cache
117:                report = resolver.download(new Artifact[] { artifact },
118:                        downloadOptions());
119:                assertNotNull(report);
120:
121:                assertEquals(1, report.getArtifactsReports().length);
122:
123:                ar = report.getArtifactReport(artifact);
124:                assertNotNull(ar);
125:
126:                assertEquals(artifact, ar.getArtifact());
127:                assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
128:            }
129:
130:            public void testLatestFile() throws Exception {
131:                URLResolver resolver = new URLResolver();
132:                resolver.setSettings(_settings);
133:                String rootpath = new File("test/repositories/1")
134:                        .getAbsolutePath().replaceAll("\\\\", "/");
135:                resolver.addIvyPattern("file:" + rootpath
136:                        + "/[organisation]/[module]/ivys/ivy-[revision].xml");
137:                resolver
138:                        .addArtifactPattern("file:"
139:                                + rootpath
140:                                + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
141:                resolver.setName("test");
142:                assertEquals("test", resolver.getName());
143:
144:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
145:                        "mod1.1", "2.0");
146:                ResolvedModuleRevision rmr = resolver.getDependency(
147:                        new DefaultDependencyDescriptor(ModuleRevisionId
148:                                .newInstance("org1", "mod1.1",
149:                                        "latest.integration"), false), _data);
150:                assertNotNull(rmr);
151:
152:                assertEquals(mrid, rmr.getId());
153:                Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0)
154:                        .getTime();
155:                assertEquals(pubdate, rmr.getPublicationDate());
156:            }
157:
158:            public void testIBiblio() throws Exception {
159:                String ibiblioRoot = IBiblioHelper.getIBiblioMirror();
160:                if (ibiblioRoot == null) {
161:                    return;
162:                }
163:
164:                URLResolver resolver = new URLResolver();
165:                resolver.setSettings(_settings);
166:                resolver.addArtifactPattern(ibiblioRoot
167:                        + "/[module]/[type]s/[artifact]-[revision].[type]");
168:                resolver.setName("test");
169:                assertEquals("test", resolver.getName());
170:
171:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
172:                        "commons-fileupload", "1.0");
173:                ResolvedModuleRevision rmr = resolver.getDependency(
174:                        new DefaultDependencyDescriptor(mrid, false), _data);
175:                assertNotNull(rmr);
176:                assertEquals(mrid, rmr.getId());
177:
178:                DefaultArtifact artifact = new DefaultArtifact(mrid, rmr
179:                        .getPublicationDate(), "commons-fileupload", "jar",
180:                        "jar");
181:                DownloadReport report = resolver.download(
182:                        new Artifact[] { artifact }, downloadOptions());
183:                assertNotNull(report);
184:
185:                assertEquals(1, report.getArtifactsReports().length);
186:
187:                ArtifactDownloadReport ar = report.getArtifactReport(artifact);
188:                assertNotNull(ar);
189:
190:                assertEquals(artifact, ar.getArtifact());
191:                assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
192:
193:                // test to ask to download again, should use cache
194:                report = resolver.download(new Artifact[] { artifact },
195:                        downloadOptions());
196:                assertNotNull(report);
197:
198:                assertEquals(1, report.getArtifactsReports().length);
199:
200:                ar = report.getArtifactReport(artifact);
201:                assertNotNull(ar);
202:
203:                assertEquals(artifact, ar.getArtifact());
204:                assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
205:            }
206:
207:            public void testIBiblioArtifacts() throws Exception {
208:                String ibiblioRoot = IBiblioHelper.getIBiblioMirror();
209:                if (ibiblioRoot == null) {
210:                    return;
211:                }
212:
213:                URLResolver resolver = new URLResolver();
214:                resolver.setSettings(_settings);
215:                resolver.addArtifactPattern(ibiblioRoot
216:                        + "/[module]/[type]s/[artifact]-[revision].[type]");
217:                resolver.setName("test");
218:                assertEquals("test", resolver.getName());
219:
220:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache",
221:                        "nanning", "0.9");
222:                DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
223:                        mrid, false);
224:                dd.addIncludeRule("default", new DefaultIncludeRule(
225:                        new ArtifactId(mrid.getModuleId(), "nanning-profiler",
226:                                "jar", "jar"), ExactPatternMatcher.INSTANCE,
227:                        null));
228:                dd.addIncludeRule("default", new DefaultIncludeRule(
229:                        new ArtifactId(mrid.getModuleId(), "nanning-trace",
230:                                "jar", "jar"), ExactPatternMatcher.INSTANCE,
231:                        null));
232:                ResolvedModuleRevision rmr = resolver.getDependency(dd, _data);
233:                assertNotNull(rmr);
234:                assertEquals(mrid, rmr.getId());
235:
236:                DefaultArtifact profiler = new DefaultArtifact(mrid, rmr
237:                        .getPublicationDate(), "nanning-profiler", "jar", "jar");
238:                DefaultArtifact trace = new DefaultArtifact(mrid, rmr
239:                        .getPublicationDate(), "nanning-trace", "jar", "jar");
240:                DownloadReport report = resolver.download(new Artifact[] {
241:                        profiler, trace }, downloadOptions());
242:                assertNotNull(report);
243:
244:                assertEquals(2, report.getArtifactsReports().length);
245:
246:                ArtifactDownloadReport ar = report.getArtifactReport(profiler);
247:                assertNotNull(ar);
248:
249:                assertEquals(profiler, ar.getArtifact());
250:                assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
251:
252:                ar = report.getArtifactReport(trace);
253:                assertNotNull(ar);
254:
255:                assertEquals(trace, ar.getArtifact());
256:                assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
257:
258:                // test to ask to download again, should use cache
259:                report = resolver.download(new Artifact[] { profiler, trace },
260:                        downloadOptions());
261:                assertNotNull(report);
262:
263:                assertEquals(2, report.getArtifactsReports().length);
264:
265:                ar = report.getArtifactReport(profiler);
266:                assertNotNull(ar);
267:
268:                assertEquals(profiler, ar.getArtifact());
269:                assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
270:
271:                ar = report.getArtifactReport(trace);
272:                assertNotNull(ar);
273:
274:                assertEquals(trace, ar.getArtifact());
275:                assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
276:            }
277:
278:            public void testLatestIBiblio() throws Exception {
279:                String ibiblioRoot = IBiblioHelper.getIBiblioMirror();
280:                if (ibiblioRoot == null) {
281:                    return;
282:                }
283:
284:                URLResolver resolver = new URLResolver();
285:                resolver.setSettings(_settings);
286:                resolver.addArtifactPattern(ibiblioRoot
287:                        + "/[module]/[type]s/[artifact]-[revision].[type]");
288:                resolver.setName("test");
289:                assertEquals("test", resolver.getName());
290:
291:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
292:                        "objectweb", "asm", "1.4+");
293:                ResolvedModuleRevision rmr = resolver.getDependency(
294:                        new DefaultDependencyDescriptor(mrid, false), _data);
295:                assertNotNull(rmr);
296:                assertEquals("1.4.3", rmr.getId().getRevision());
297:            }
298:
299:            public void testVersionRangeIBiblio() throws Exception {
300:                String ibiblioRoot = IBiblioHelper.getIBiblioMirror();
301:                if (ibiblioRoot == null) {
302:                    return;
303:                }
304:
305:                URLResolver resolver = new URLResolver();
306:                resolver.setSettings(_settings);
307:                resolver.setAlwaysCheckExactRevision(true);
308:                resolver.addIvyPattern(ibiblioRoot
309:                        + "/[module]/poms/[module]-[revision].pom");
310:                resolver.addArtifactPattern(ibiblioRoot
311:                        + "/[module]/[type]s/[artifact]-[revision].[type]");
312:                resolver.setName("test");
313:                assertEquals("test", resolver.getName());
314:
315:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("asm",
316:                        "asm", "[1.4,1.5]");
317:                ResolvedModuleRevision rmr = resolver.getDependency(
318:                        new DefaultDependencyDescriptor(mrid, false), _data);
319:                assertNotNull(rmr);
320:                assertEquals("1.4.4", rmr.getId().getRevision());
321:            }
322:
323:            public void testUnknown() throws Exception {
324:                String ibiblioRoot = IBiblioHelper.getIBiblioMirror();
325:                if (ibiblioRoot == null) {
326:                    return;
327:                }
328:
329:                URLResolver resolver = new URLResolver();
330:                resolver.setSettings(_settings);
331:                resolver.addIvyPattern(ibiblioRoot
332:                        + "/[module]/ivys/ivy-[revision].xml");
333:                resolver
334:                        .addArtifactPattern(ibiblioRoot
335:                                + "/maven/[module]/[type]s/[artifact]-[revision].[type]");
336:                resolver.setName("test");
337:
338:                assertNull(resolver.getDependency(
339:                        new DefaultDependencyDescriptor(ModuleRevisionId
340:                                .newInstance("unknown", "unknown", "1.0"),
341:                                false), _data));
342:            }
343:
344:            public void testDownloadWithUseOriginIsTrue() throws Exception {
345:                URLResolver resolver = new URLResolver();
346:                resolver.setSettings(_settings);
347:                String rootpath = new File("test/repositories/1")
348:                        .getAbsolutePath();
349:                resolver.addIvyPattern("file:" + rootpath
350:                        + "/[organisation]/[module]/ivys/ivy-[revision].xml");
351:                resolver
352:                        .addArtifactPattern("file:"
353:                                + rootpath
354:                                + "/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
355:                resolver.setName("test");
356:                ((DefaultRepositoryCacheManager) resolver
357:                        .getRepositoryCacheManager()).setUseOrigin(true);
358:                assertEquals("test", resolver.getName());
359:
360:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
361:                        "mod1.1", "1.0");
362:                ResolvedModuleRevision rmr = resolver.getDependency(
363:                        new DefaultDependencyDescriptor(mrid, false), _data);
364:                assertNotNull(rmr);
365:
366:                assertEquals(mrid, rmr.getId());
367:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
368:                        .getTime();
369:                assertEquals(pubdate, rmr.getPublicationDate());
370:
371:                // test to ask to download
372:                DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate,
373:                        "mod1.1", "jar", "jar");
374:                DownloadReport report = resolver.download(
375:                        new Artifact[] { artifact }, new DownloadOptions());
376:                assertNotNull(report);
377:
378:                assertEquals(1, report.getArtifactsReports().length);
379:
380:                ArtifactDownloadReport ar = report.getArtifactReport(artifact);
381:                assertNotNull(ar);
382:
383:                assertEquals(artifact, ar.getArtifact());
384:                assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
385:
386:                // test to ask to download again, should use cache
387:                // report = resolver.download(new Artifact[] {artifact}, _data.getIvy(), _cache);
388:                // assertNotNull(report);
389:                //        
390:                // assertEquals(1, report.getArtifactsReports().length);
391:                //        
392:                // ar = report.getArtifactReport(artifact);
393:                // assertNotNull(ar);
394:                //        
395:                // assertEquals(artifact, ar.getArtifact());
396:                // assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
397:                //    	
398:            }
399:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.