Source Code Cross Referenced for FileSystemResolverTest.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.BufferedReader;
021:        import java.io.File;
022:        import java.io.FileReader;
023:        import java.util.Date;
024:        import java.util.GregorianCalendar;
025:
026:        import org.apache.ivy.core.cache.DefaultRepositoryCacheManager;
027:        import org.apache.ivy.core.event.EventManager;
028:        import org.apache.ivy.core.module.descriptor.Artifact;
029:        import org.apache.ivy.core.module.descriptor.DefaultArtifact;
030:        import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
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.search.ModuleEntry;
041:        import org.apache.ivy.core.search.OrganisationEntry;
042:        import org.apache.ivy.core.search.RevisionEntry;
043:        import org.apache.ivy.core.settings.IvySettings;
044:        import org.apache.ivy.core.sort.SortEngine;
045:        import org.apache.ivy.plugins.latest.LatestRevisionStrategy;
046:        import org.apache.ivy.plugins.latest.LatestTimeStrategy;
047:        import org.apache.ivy.plugins.resolver.util.ResolvedResource;
048:        import org.apache.ivy.util.CacheCleaner;
049:        import org.apache.ivy.util.FileUtil;
050:
051:        /**
052:         * 
053:         */
054:        public class FileSystemResolverTest extends
055:                AbstractDependencyResolverTest {
056:            //CheckStyle:MagicNumberCheck OFF
057:
058:            private static final String FS = System
059:                    .getProperty("file.separator");
060:
061:            private static final String IVY_PATTERN = "test" + FS
062:                    + "repositories" + FS + "1" + FS + "[organisation]" + FS
063:                    + "[module]" + FS + "ivys" + FS + "ivy-[revision].xml";
064:
065:            private IvySettings settings;
066:
067:            private ResolveEngine engine;
068:
069:            private ResolveData data;
070:
071:            private File cache;
072:
073:            private DefaultRepositoryCacheManager cacheManager;
074:
075:            public FileSystemResolverTest() {
076:                setupLastModified();
077:            }
078:
079:            protected void setUp() throws Exception {
080:                settings = new IvySettings();
081:                engine = new ResolveEngine(settings, new EventManager(),
082:                        new SortEngine(settings));
083:                cache = new File("build/cache");
084:                data = new ResolveData(engine, new ResolveOptions());
085:                cache.mkdirs();
086:                settings.setDefaultCache(cache);
087:                cacheManager = (DefaultRepositoryCacheManager) settings
088:                        .getDefaultRepositoryCacheManager();
089:            }
090:
091:            private void setupLastModified() {
092:                // change important last modified dates cause svn doesn't keep them
093:                long minute = 60 * 1000;
094:                long time = new GregorianCalendar().getTimeInMillis()
095:                        - (4 * minute);
096:                new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml")
097:                        .setLastModified(time);
098:                time += minute;
099:                new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.1.xml")
100:                        .setLastModified(time);
101:                time += minute;
102:                new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.1.xml")
103:                        .setLastModified(time);
104:                time += minute;
105:                new File("test/repositories/1/org1/mod1.1/ivys/ivy-2.0.xml")
106:                        .setLastModified(time);
107:            }
108:
109:            protected void tearDown() throws Exception {
110:                CacheCleaner.deleteDir(cache);
111:            }
112:
113:            public void testFixedRevision() throws Exception {
114:                FileSystemResolver resolver = new FileSystemResolver();
115:                resolver.setName("test");
116:                resolver.setSettings(settings);
117:                assertEquals("test", resolver.getName());
118:
119:                resolver.addIvyPattern(IVY_PATTERN);
120:                resolver
121:                        .addArtifactPattern("test/repositories/1/[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
122:
123:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
124:                        "mod1.1", "1.0");
125:                ResolvedModuleRevision rmr = resolver.getDependency(
126:                        new DefaultDependencyDescriptor(mrid, false), data);
127:                assertNotNull(rmr);
128:
129:                assertEquals(mrid, rmr.getId());
130:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
131:                        .getTime();
132:                assertEquals(pubdate, rmr.getPublicationDate());
133:
134:                // test to ask to download
135:                DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate,
136:                        "mod1.1", "jar", "jar");
137:                DownloadReport report = resolver.download(
138:                        new Artifact[] { artifact }, getDownloadOptions());
139:                assertNotNull(report);
140:
141:                assertEquals(1, report.getArtifactsReports().length);
142:
143:                ArtifactDownloadReport ar = report.getArtifactReport(artifact);
144:                assertNotNull(ar);
145:
146:                assertEquals(artifact, ar.getArtifact());
147:                assertEquals(DownloadStatus.SUCCESSFUL, ar.getDownloadStatus());
148:
149:                // test to ask to download again, should use cache
150:                report = resolver.download(new Artifact[] { artifact },
151:                        getDownloadOptions());
152:                assertNotNull(report);
153:
154:                assertEquals(1, report.getArtifactsReports().length);
155:
156:                ar = report.getArtifactReport(artifact);
157:                assertNotNull(ar);
158:
159:                assertEquals(artifact, ar.getArtifact());
160:                assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
161:            }
162:
163:            public void testFindIvyFileRefWithMultipleIvyPatterns()
164:                    throws Exception {
165:                // cfr IVY-676
166:                FileSystemResolver resolver = new FileSystemResolver();
167:                resolver.setName("test");
168:                resolver.setSettings(settings);
169:                resolver
170:                        .addIvyPattern("test/repositories/multi-ivypattern/ivy1/ivy-[revision].xml");
171:                resolver
172:                        .addIvyPattern("test/repositories/multi-ivypattern/ivy2/ivy-[revision].xml");
173:
174:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
175:                        "mod1.1", "1.0+");
176:                ResolvedResource ivyRef = resolver.findIvyFileRef(
177:                        new DefaultDependencyDescriptor(mrid, false), data);
178:
179:                // check that the found ivy file is the one from the first pattern!
180:                assertEquals(
181:                        "test/repositories/multi-ivypattern/ivy1/ivy-1.0.xml",
182:                        ivyRef.getResource().getName().replace('\\', '/'));
183:            }
184:
185:            private DownloadOptions getDownloadOptions() {
186:                return new DownloadOptions();
187:            }
188:
189:            public void testMaven2() throws Exception {
190:                FileSystemResolver resolver = new FileSystemResolver();
191:                resolver.setName("test");
192:                resolver.setSettings(settings);
193:                resolver.setM2compatible(true);
194:                assertEquals("test", resolver.getName());
195:
196:                resolver
197:                        .addIvyPattern("test/repositories/m2/"
198:                                + "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
199:                resolver
200:                        .addArtifactPattern("test/repositories/m2/"
201:                                + "[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
202:
203:                ModuleRevisionId mrid = ModuleRevisionId.newInstance(
204:                        "org.apache", "test", "1.0");
205:                ResolvedModuleRevision rmr = resolver.getDependency(
206:                        new DefaultDependencyDescriptor(mrid, false), data);
207:                assertNotNull(rmr);
208:
209:                mrid = ModuleRevisionId.newInstance("org.apache.unknown",
210:                        "test", "1.0");
211:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
212:                        mrid, false), data);
213:                assertNull(rmr);
214:                resolver.reportFailure();
215:            }
216:
217:            public void testChecksum() throws Exception {
218:                FileSystemResolver resolver = new FileSystemResolver();
219:                resolver.setName("test");
220:                resolver.setSettings(settings);
221:
222:                resolver
223:                        .addIvyPattern("test/repositories/checksums/[module]/[artifact]-[revision].[ext]");
224:                resolver
225:                        .addArtifactPattern("test/repositories/checksums/[module]/[artifact]-[revision].[ext]");
226:
227:                resolver.setChecksums("sha1, md5");
228:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("test",
229:                        "allright", "1.0");
230:                ResolvedModuleRevision rmr = resolver.getDependency(
231:                        new DefaultDependencyDescriptor(mrid, false), data);
232:                assertNotNull(rmr);
233:                DownloadReport dr = resolver.download(rmr.getDescriptor()
234:                        .getAllArtifacts(), getDownloadOptions());
235:                assertEquals(2, dr
236:                        .getArtifactsReports(DownloadStatus.SUCCESSFUL).length);
237:
238:                resolver.setChecksums("md5");
239:                mrid = ModuleRevisionId.newInstance("test", "badivycs", "1.0");
240:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
241:                        mrid, false), data);
242:                assertNull(rmr);
243:                resolver.setChecksums("none");
244:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
245:                        mrid, false), data);
246:                assertNotNull(rmr);
247:                dr = resolver.download(new Artifact[] { new DefaultArtifact(
248:                        mrid, rmr.getPublicationDate(), mrid.getName(), "jar",
249:                        "jar") }, getDownloadOptions());
250:                assertEquals(1, dr
251:                        .getArtifactsReports(DownloadStatus.SUCCESSFUL).length);
252:
253:                resolver.setChecksums("md5");
254:                mrid = ModuleRevisionId.newInstance("test", "badartcs", "1.0");
255:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
256:                        mrid, false), data);
257:                assertNotNull(rmr);
258:                dr = resolver.download(new Artifact[] { new DefaultArtifact(
259:                        mrid, rmr.getPublicationDate(), mrid.getName(), "jar",
260:                        "jar") }, getDownloadOptions());
261:                assertEquals(1,
262:                        dr.getArtifactsReports(DownloadStatus.FAILED).length);
263:
264:                resolver.setChecksums("");
265:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
266:                        mrid, false), data);
267:                assertNotNull(rmr);
268:                dr = resolver.download(new Artifact[] { new DefaultArtifact(
269:                        mrid, rmr.getPublicationDate(), mrid.getName(), "jar",
270:                        "jar") }, getDownloadOptions());
271:                assertEquals(1, dr
272:                        .getArtifactsReports(DownloadStatus.SUCCESSFUL).length);
273:            }
274:
275:            public void testCheckModified() throws Exception {
276:                FileSystemResolver resolver = new FileSystemResolver();
277:                resolver.setName("test");
278:                resolver.setSettings(settings);
279:                settings.addResolver(resolver);
280:                assertEquals("test", resolver.getName());
281:
282:                resolver.addIvyPattern("test" + FS + "repositories" + FS
283:                        + "checkmodified" + FS + "ivy-[revision].xml");
284:                File modify = new File(
285:                        "test/repositories/checkmodified/ivy-1.0.xml");
286:                FileUtil.copy(new File(
287:                        "test/repositories/checkmodified/ivy-1.0-before.xml"),
288:                        modify, null, true);
289:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
290:                        .getTime();
291:                modify.setLastModified(pubdate.getTime());
292:
293:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
294:                        "mod1.1", "1.0");
295:                ResolvedModuleRevision rmr = resolver.getDependency(
296:                        new DefaultDependencyDescriptor(mrid, false), data);
297:                assertNotNull(rmr);
298:
299:                assertEquals(mrid, rmr.getId());
300:                assertEquals(pubdate, rmr.getPublicationDate());
301:
302:                // updates ivy file in repository
303:                FileUtil.copy(new File(
304:                        "test/repositories/checkmodified/ivy-1.0-after.xml"),
305:                        modify, null, true);
306:                pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime();
307:                modify.setLastModified(pubdate.getTime());
308:
309:                // should not get the new version
310:                resolver.setCheckmodified(false);
311:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
312:                        mrid, false), data);
313:                assertNotNull(rmr);
314:
315:                assertEquals(mrid, rmr.getId());
316:                assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0)
317:                        .getTime(), rmr.getPublicationDate());
318:
319:                // should now get the new version
320:                resolver.setCheckmodified(true);
321:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
322:                        mrid, false), data);
323:                assertNotNull(rmr);
324:
325:                assertEquals(mrid, rmr.getId());
326:                assertEquals(pubdate, rmr.getPublicationDate());
327:            }
328:
329:            public void testNoRevision() throws Exception {
330:                FileSystemResolver resolver = new FileSystemResolver();
331:                resolver.setName("test");
332:                resolver.setSettings(settings);
333:                settings.addResolver(resolver);
334:                assertEquals("test", resolver.getName());
335:
336:                resolver.addIvyPattern("test" + FS + "repositories" + FS
337:                        + "norevision" + FS + "ivy-[module].xml");
338:                resolver.addArtifactPattern("test" + FS + "repositories" + FS
339:                        + "norevision" + FS + "[artifact].[ext]");
340:                File modify = new File(
341:                        "test/repositories/norevision/ivy-mod1.1.xml");
342:                File artifact = new File(
343:                        "test/repositories/norevision/mod1.1.jar");
344:
345:                // 'publish' 'before' version
346:                FileUtil.copy(new File(
347:                        "test/repositories/norevision/ivy-mod1.1-before.xml"),
348:                        modify, null, true);
349:                FileUtil.copy(new File(
350:                        "test/repositories/norevision/mod1.1-before.jar"),
351:                        artifact, null, true);
352:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
353:                        .getTime();
354:                modify.setLastModified(pubdate.getTime());
355:
356:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
357:                        "mod1.1", "latest.integration");
358:                ResolvedModuleRevision rmr = resolver.getDependency(
359:                        new DefaultDependencyDescriptor(mrid, false), data);
360:                assertNotNull(rmr);
361:
362:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1",
363:                        "1.0"), rmr.getId());
364:                assertEquals(pubdate, rmr.getPublicationDate());
365:
366:                Artifact[] artifacts = rmr.getDescriptor().getArtifacts(
367:                        "default");
368:                File archiveFileInCache = cacheManager
369:                        .getArchiveFileInCache(artifacts[0]);
370:                resolver.download(artifacts, getDownloadOptions());
371:                assertTrue(archiveFileInCache.exists());
372:                BufferedReader r = new BufferedReader(new FileReader(
373:                        archiveFileInCache));
374:                assertEquals("before", r.readLine());
375:                r.close();
376:
377:                // updates ivy file and artifact in repository
378:                FileUtil.copy(new File(
379:                        "test/repositories/norevision/ivy-mod1.1-after.xml"),
380:                        modify, null, true);
381:                FileUtil.copy(new File(
382:                        "test/repositories/norevision/mod1.1-after.jar"),
383:                        artifact, null, true);
384:                pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime();
385:                modify.setLastModified(pubdate.getTime());
386:                // no need to update new artifact timestamp cause it isn't used
387:
388:                // should get the new version even if checkModified is false, beacause we ask a
389:                // latest.integration
390:                resolver.setCheckmodified(false);
391:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
392:                        mrid, false), data);
393:                assertNotNull(rmr);
394:
395:                assertEquals(ModuleRevisionId.newInstance("org1", "mod1.1",
396:                        "1.1"), rmr.getId());
397:                assertEquals(pubdate, rmr.getPublicationDate());
398:
399:                artifacts = rmr.getDescriptor().getArtifacts("default");
400:                archiveFileInCache = cacheManager
401:                        .getArchiveFileInCache(artifacts[0]);
402:
403:                assertFalse(archiveFileInCache.exists());
404:
405:                // should download the new artifact
406:                artifacts = rmr.getDescriptor().getArtifacts("default");
407:                resolver.download(artifacts, getDownloadOptions());
408:                assertTrue(archiveFileInCache.exists());
409:                r = new BufferedReader(new FileReader(archiveFileInCache));
410:                assertEquals("after", r.readLine());
411:                r.close();
412:            }
413:
414:            public void testChanging() throws Exception {
415:                FileSystemResolver resolver = new FileSystemResolver();
416:                resolver.setName("test");
417:                resolver.setSettings(settings);
418:                settings.addResolver(resolver);
419:                assertEquals("test", resolver.getName());
420:
421:                resolver.addIvyPattern("test" + FS + "repositories" + FS
422:                        + "checkmodified" + FS + "ivy-[revision].xml");
423:                resolver.addArtifactPattern("test" + FS + "repositories" + FS
424:                        + "checkmodified" + FS + "[artifact]-[revision].[ext]");
425:                File modify = new File(
426:                        "test/repositories/checkmodified/ivy-1.0.xml");
427:                File artifact = new File(
428:                        "test/repositories/checkmodified/mod1.1-1.0.jar");
429:
430:                // 'publish' 'before' version
431:                FileUtil.copy(new File(
432:                        "test/repositories/checkmodified/ivy-1.0-before.xml"),
433:                        modify, null, true);
434:                FileUtil
435:                        .copy(
436:                                new File(
437:                                        "test/repositories/checkmodified/mod1.1-1.0-before.jar"),
438:                                artifact, null, true);
439:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
440:                        .getTime();
441:                modify.setLastModified(pubdate.getTime());
442:
443:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
444:                        "mod1.1", "1.0");
445:                ResolvedModuleRevision rmr = resolver.getDependency(
446:                        new DefaultDependencyDescriptor(mrid, false), data);
447:                assertNotNull(rmr);
448:
449:                assertEquals(mrid, rmr.getId());
450:                assertEquals(pubdate, rmr.getPublicationDate());
451:
452:                Artifact[] artifacts = rmr.getDescriptor().getArtifacts(
453:                        "default");
454:                resolver.download(artifacts, getDownloadOptions());
455:                File archiveFileInCache = cacheManager
456:                        .getArchiveFileInCache(artifacts[0]);
457:                assertTrue(archiveFileInCache.exists());
458:                BufferedReader r = new BufferedReader(new FileReader(
459:                        archiveFileInCache));
460:                assertEquals("before", r.readLine());
461:                r.close();
462:
463:                // updates ivy file and artifact in repository
464:                FileUtil.copy(new File(
465:                        "test/repositories/checkmodified/ivy-1.0-after.xml"),
466:                        modify, null, true);
467:                FileUtil
468:                        .copy(
469:                                new File(
470:                                        "test/repositories/checkmodified/mod1.1-1.0-after.jar"),
471:                                artifact, null, true);
472:                pubdate = new GregorianCalendar(2005, 4, 1, 11, 0, 0).getTime();
473:                modify.setLastModified(pubdate.getTime());
474:                // no need to update new artifact timestamp cause it isn't used
475:
476:                // should not get the new version: checkmodified is false and edpendency is not told to be a
477:                // changing one
478:                resolver.setCheckmodified(false);
479:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
480:                        mrid, false), data);
481:                assertNotNull(rmr);
482:
483:                assertEquals(mrid, rmr.getId());
484:                assertEquals(new GregorianCalendar(2004, 10, 1, 11, 0, 0)
485:                        .getTime(), rmr.getPublicationDate());
486:
487:                assertTrue(archiveFileInCache.exists());
488:                r = new BufferedReader(new FileReader(archiveFileInCache));
489:                assertEquals("before", r.readLine());
490:                r.close();
491:
492:                // should now get the new version cause we say it's a changing one
493:                rmr = resolver.getDependency(new DefaultDependencyDescriptor(
494:                        mrid, false, true), data);
495:                assertNotNull(rmr);
496:
497:                assertEquals(mrid, rmr.getId());
498:                assertEquals(pubdate, rmr.getPublicationDate());
499:
500:                assertFalse(archiveFileInCache.exists());
501:
502:                artifacts = rmr.getDescriptor().getArtifacts("default");
503:                resolver.download(artifacts, getDownloadOptions());
504:                assertTrue(archiveFileInCache.exists());
505:                r = new BufferedReader(new FileReader(archiveFileInCache));
506:                assertEquals("after", r.readLine());
507:                r.close();
508:            }
509:
510:            public void testLatestTime() throws Exception {
511:                FileSystemResolver resolver = new FileSystemResolver();
512:                resolver.setName("test");
513:                resolver.setSettings(settings);
514:                assertEquals("test", resolver.getName());
515:
516:                resolver.addIvyPattern(IVY_PATTERN);
517:                resolver
518:                        .addArtifactPattern("test/repositories/1/"
519:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
520:
521:                resolver.setLatestStrategy(new LatestTimeStrategy());
522:
523:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
524:                        "mod1.1", "2.0");
525:                ResolvedModuleRevision rmr = resolver.getDependency(
526:                        new DefaultDependencyDescriptor(ModuleRevisionId
527:                                .newInstance("org1", "mod1.1",
528:                                        "latest.integration"), false), data);
529:                assertNotNull(rmr);
530:
531:                assertEquals(mrid, rmr.getId());
532:                Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0)
533:                        .getTime();
534:                assertEquals(pubdate, rmr.getPublicationDate());
535:            }
536:
537:            public void testLatestRevision() throws Exception {
538:                FileSystemResolver resolver = new FileSystemResolver();
539:                resolver.setName("test");
540:                resolver.setSettings(settings);
541:                assertEquals("test", resolver.getName());
542:
543:                resolver.addIvyPattern(IVY_PATTERN);
544:                resolver
545:                        .addArtifactPattern("test/repositories/1/"
546:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
547:
548:                resolver.setLatestStrategy(new LatestRevisionStrategy());
549:
550:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
551:                        "mod1.1", "2.0");
552:                ResolvedModuleRevision rmr = resolver.getDependency(
553:                        new DefaultDependencyDescriptor(ModuleRevisionId
554:                                .newInstance("org1", "mod1.1",
555:                                        "latest.integration"), false), data);
556:                assertNotNull(rmr);
557:
558:                assertEquals(mrid, rmr.getId());
559:                Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0)
560:                        .getTime();
561:                assertEquals(pubdate, rmr.getPublicationDate());
562:            }
563:
564:            public void testRelativePath() throws Exception {
565:                FileSystemResolver resolver = new FileSystemResolver();
566:                resolver.setName("test");
567:                resolver.setSettings(settings);
568:                assertEquals("test", resolver.getName());
569:
570:                resolver.addIvyPattern(new File("src/java").getAbsolutePath()
571:                        + "/../../" + IVY_PATTERN);
572:                resolver
573:                        .addArtifactPattern("src/../test/repositories/1/"
574:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
575:
576:                resolver.setLatestStrategy(new LatestRevisionStrategy());
577:
578:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
579:                        "mod1.1", "2.0");
580:                ResolvedModuleRevision rmr = resolver.getDependency(
581:                        new DefaultDependencyDescriptor(ModuleRevisionId
582:                                .newInstance("org1", "mod1.1",
583:                                        "latest.integration"), false), data);
584:                assertNotNull(rmr);
585:
586:                assertEquals(mrid, rmr.getId());
587:                Date pubdate = new GregorianCalendar(2005, 1, 15, 11, 0, 0)
588:                        .getTime();
589:                assertEquals(pubdate, rmr.getPublicationDate());
590:            }
591:
592:            public void testFormattedLatestTime() throws Exception {
593:                FileSystemResolver resolver = new FileSystemResolver();
594:                resolver.setName("test");
595:                resolver.setSettings(settings);
596:                assertEquals("test", resolver.getName());
597:
598:                resolver.addIvyPattern(IVY_PATTERN);
599:                resolver
600:                        .addArtifactPattern("test/repositories/1/"
601:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
602:
603:                resolver.setLatestStrategy(new LatestTimeStrategy());
604:
605:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
606:                        "mod1.1", "1.1");
607:                ResolvedModuleRevision rmr = resolver.getDependency(
608:                        new DefaultDependencyDescriptor(ModuleRevisionId
609:                                .newInstance("org1", "mod1.1", "1+"), false),
610:                        data);
611:                assertNotNull(rmr);
612:
613:                assertEquals(mrid, rmr.getId());
614:                Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0)
615:                        .getTime();
616:                assertEquals(pubdate, rmr.getPublicationDate());
617:            }
618:
619:            public void testFormattedLatestRevision() throws Exception {
620:                FileSystemResolver resolver = new FileSystemResolver();
621:                resolver.setName("test");
622:                resolver.setSettings(settings);
623:                assertEquals("test", resolver.getName());
624:
625:                resolver.addIvyPattern(IVY_PATTERN);
626:                resolver
627:                        .addArtifactPattern("test/repositories/1/"
628:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
629:
630:                resolver.setLatestStrategy(new LatestRevisionStrategy());
631:
632:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
633:                        "mod1.1", "1.1");
634:                ResolvedModuleRevision rmr = resolver.getDependency(
635:                        new DefaultDependencyDescriptor(ModuleRevisionId
636:                                .newInstance("org1", "mod1.1", "1+"), false),
637:                        data);
638:                assertNotNull(rmr);
639:
640:                assertEquals(mrid, rmr.getId());
641:                Date pubdate = new GregorianCalendar(2005, 0, 2, 11, 0, 0)
642:                        .getTime();
643:                assertEquals(pubdate, rmr.getPublicationDate());
644:            }
645:
646:            public void testPublish() throws Exception {
647:                try {
648:                    FileSystemResolver resolver = new FileSystemResolver();
649:                    resolver.setName("test");
650:                    resolver.setSettings(settings);
651:                    assertEquals("test", resolver.getName());
652:
653:                    resolver.addIvyPattern("test" + FS + "repositories" + FS
654:                            + "1" + FS + "[organisation]" + FS + "[module]"
655:                            + FS + "[revision]" + FS + "[artifact].[ext]");
656:                    resolver
657:                            .addArtifactPattern("test/repositories/1/"
658:                                    + "[organisation]/[module]/[type]s/[artifact]-[revision].[ext]");
659:
660:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
661:                            "myorg", "mymodule", "myrevision");
662:                    Artifact ivyArtifact = new DefaultArtifact(mrid,
663:                            new Date(), "ivy", "ivy", "xml");
664:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
665:                            "myartifact", "mytype", "myext");
666:                    File src = new File("test/repositories/ivysettings.xml");
667:                    resolver.beginPublishTransaction(mrid, false);
668:                    resolver.publish(ivyArtifact, src, false);
669:                    resolver.publish(artifact, src, false);
670:                    resolver.commitPublishTransaction();
671:
672:                    assertTrue(new File(
673:                            "test/repositories/1/myorg/mymodule/myrevision/ivy.xml")
674:                            .exists());
675:                    assertTrue(new File(
676:                            "test/repositories/1/myorg/mymodule/mytypes/myartifact-myrevision.myext")
677:                            .exists());
678:                } finally {
679:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
680:                }
681:            }
682:
683:            public void testPublishTransaction() throws Exception {
684:                try {
685:                    FileSystemResolver resolver = new FileSystemResolver();
686:                    resolver.setName("test");
687:                    resolver.setSettings(settings);
688:
689:                    resolver
690:                            .addIvyPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact].[ext]");
691:                    resolver
692:                            .addArtifactPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
693:
694:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
695:                            "myorg", "mymodule", "myrevision");
696:                    Artifact ivyArtifact = new DefaultArtifact(mrid,
697:                            new Date(), "ivy", "ivy", "xml");
698:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
699:                            "myartifact", "mytype", "myext");
700:                    File src = new File("test/repositories/ivysettings.xml");
701:
702:                    resolver.beginPublishTransaction(mrid, false);
703:
704:                    // files should not be available until the transaction is committed
705:                    resolver.publish(ivyArtifact, src, false);
706:                    assertFalse(new File(
707:                            "test/repositories/1/myorg/mymodule/myrevision/ivy.xml")
708:                            .exists());
709:
710:                    resolver.publish(artifact, src, false);
711:                    assertFalse(new File(
712:                            "test/repositories/1/myorg/mymodule/mytypes/myartifact-myrevision.myext")
713:                            .exists());
714:
715:                    resolver.commitPublishTransaction();
716:
717:                    assertTrue(new File(
718:                            "test/repositories/1/myorg/mymodule/myrevision/ivy.xml")
719:                            .exists());
720:                    assertTrue(new File(
721:                            "test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
722:                            .exists());
723:                } finally {
724:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
725:                }
726:            }
727:
728:            public void testAbortTransaction() throws Exception {
729:                try {
730:                    FileSystemResolver resolver = new FileSystemResolver();
731:                    resolver.setName("test");
732:                    resolver.setSettings(settings);
733:
734:                    resolver
735:                            .addIvyPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact].[ext]");
736:                    resolver
737:                            .addArtifactPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
738:
739:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
740:                            "myorg", "mymodule", "myrevision");
741:                    Artifact ivyArtifact = new DefaultArtifact(mrid,
742:                            new Date(), "ivy", "ivy", "xml");
743:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
744:                            "myartifact", "mytype", "myext");
745:                    File src = new File("test/repositories/ivysettings.xml");
746:                    resolver.beginPublishTransaction(mrid, false);
747:                    resolver.publish(ivyArtifact, src, false);
748:                    resolver.publish(artifact, src, false);
749:                    resolver.abortPublishTransaction();
750:
751:                    assertFalse(new File(
752:                            "test/repositories/1/myorg/mymodule/myrevision/ivy.xml")
753:                            .exists());
754:                    assertFalse(new File(
755:                            "test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
756:                            .exists());
757:                } finally {
758:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
759:                }
760:            }
761:
762:            public void testUnsupportedTransaction() throws Exception {
763:                try {
764:                    FileSystemResolver resolver = new FileSystemResolver();
765:                    resolver.setName("test");
766:                    resolver.setSettings(settings);
767:                    resolver.setTransactional("true");
768:
769:                    resolver.addArtifactPattern(
770:                    // this pattern is not supported for transaction publish
771:                            "test/repositories/1/[organisation]/[module]/[artifact]-[revision].[ext]");
772:
773:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
774:                            "myorg", "mymodule", "myrevision");
775:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
776:                            "myartifact", "mytype", "myext");
777:                    File src = new File("test/repositories/ivysettings.xml");
778:                    try {
779:                        resolver.beginPublishTransaction(mrid, false);
780:
781:                        resolver.publish(artifact, src, false);
782:                        fail("publishing with transaction=true and an unsupported pattern should raise an exception");
783:                    } catch (IllegalStateException ex) {
784:                        assertTrue(ex.getMessage().indexOf("transactional") != -1);
785:                    }
786:                } finally {
787:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
788:                }
789:            }
790:
791:            public void testUnsupportedTransaction2() throws Exception {
792:                try {
793:                    FileSystemResolver resolver = new FileSystemResolver();
794:                    resolver.setName("test");
795:                    resolver.setSettings(settings);
796:                    resolver.setTransactional("true");
797:
798:                    // the two patterns are inconsistent and thus not supported for transactions
799:                    resolver
800:                            .addIvyPattern("test/repositories/1/[organisation]-[module]/[revision]/[artifact]-[revision].[ext]");
801:                    resolver
802:                            .addArtifactPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
803:
804:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
805:                            "myorg", "mymodule", "myrevision");
806:                    Artifact ivyArtifact = new DefaultArtifact(mrid,
807:                            new Date(), "ivy", "ivy", "xml");
808:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
809:                            "myartifact", "mytype", "myext");
810:                    File src = new File("test/repositories/ivysettings.xml");
811:                    try {
812:                        resolver.beginPublishTransaction(mrid, false);
813:                        resolver.publish(ivyArtifact, src, false);
814:                        resolver.publish(artifact, src, false);
815:                        fail("publishing with transaction=true and an unsupported combination of patterns should raise an exception");
816:                    } catch (IllegalStateException ex) {
817:                        assertTrue(ex.getMessage().indexOf("transactional") != -1);
818:                    }
819:                } finally {
820:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
821:                }
822:            }
823:
824:            public void testUnsupportedTransaction3() throws Exception {
825:                try {
826:                    FileSystemResolver resolver = new FileSystemResolver();
827:                    resolver.setName("test");
828:                    resolver.setSettings(settings);
829:                    resolver.setTransactional("true");
830:
831:                    resolver
832:                            .addArtifactPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
833:
834:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
835:                            "myorg", "mymodule", "myrevision");
836:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
837:                            "myartifact", "mytype", "myext");
838:                    File src = new File("test/repositories/ivysettings.xml");
839:                    try {
840:                        // overwrite transaction not supported
841:                        resolver.beginPublishTransaction(mrid, true);
842:
843:                        resolver.publish(artifact, src, true);
844:                        fail("publishing with transaction=true and overzrite mode should raise an exception");
845:                    } catch (IllegalStateException ex) {
846:                        assertTrue(ex.getMessage().indexOf("transactional") != -1);
847:                    }
848:                } finally {
849:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
850:                }
851:            }
852:
853:            public void testDisableTransaction() throws Exception {
854:                try {
855:                    FileSystemResolver resolver = new FileSystemResolver();
856:                    resolver.setName("test");
857:                    resolver.setSettings(settings);
858:                    resolver.setTransactional("false");
859:
860:                    resolver
861:                            .addIvyPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact].[ext]");
862:                    resolver
863:                            .addArtifactPattern("test/repositories/1/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]");
864:
865:                    ModuleRevisionId mrid = ModuleRevisionId.newInstance(
866:                            "myorg", "mymodule", "myrevision");
867:                    Artifact ivyArtifact = new DefaultArtifact(mrid,
868:                            new Date(), "ivy", "ivy", "xml");
869:                    Artifact artifact = new DefaultArtifact(mrid, new Date(),
870:                            "myartifact", "mytype", "myext");
871:                    File src = new File("test/repositories/ivysettings.xml");
872:                    resolver.beginPublishTransaction(mrid, false);
873:
874:                    // with transactions disabled the file should be available as soon as they are published
875:                    resolver.publish(ivyArtifact, src, false);
876:                    assertTrue(new File(
877:                            "test/repositories/1/myorg/mymodule/myrevision/ivy.xml")
878:                            .exists());
879:
880:                    resolver.publish(artifact, src, false);
881:                    assertTrue(new File(
882:                            "test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
883:                            .exists());
884:
885:                    resolver.commitPublishTransaction();
886:
887:                    assertTrue(new File(
888:                            "test/repositories/1/myorg/mymodule/myrevision/ivy.xml")
889:                            .exists());
890:                    assertTrue(new File(
891:                            "test/repositories/1/myorg/mymodule/myrevision/myartifact-myrevision.myext")
892:                            .exists());
893:                } finally {
894:                    FileUtil.forceDelete(new File("test/repositories/1/myorg"));
895:                }
896:            }
897:
898:            public void testListing() throws Exception {
899:                FileSystemResolver resolver = new FileSystemResolver();
900:                resolver.setName("test");
901:                resolver.setSettings(settings);
902:                assertEquals("test", resolver.getName());
903:
904:                resolver.addIvyPattern(IVY_PATTERN);
905:                resolver
906:                        .addArtifactPattern("test/repositories/1/"
907:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[ext]");
908:
909:                OrganisationEntry[] orgs = resolver.listOrganisations();
910:                ResolverTestHelper.assertOrganisationEntriesContains(resolver,
911:                        new String[] { "org1", "org2", "org6", "org9",
912:                                "orgfailure", "yourorg", "IVY-644" }, orgs);
913:
914:                OrganisationEntry org = ResolverTestHelper.getEntry(orgs,
915:                        "org1");
916:                ModuleEntry[] mods = resolver.listModules(org);
917:                ResolverTestHelper.assertModuleEntries(resolver, org,
918:                        new String[] { "mod1.1", "mod1.2", "mod1.3", "mod1.4",
919:                                "mod1.5", "mod1.6" }, mods);
920:
921:                ModuleEntry mod = ResolverTestHelper.getEntry(mods, "mod1.1");
922:                RevisionEntry[] revs = resolver.listRevisions(mod);
923:                ResolverTestHelper.assertRevisionEntries(resolver, mod,
924:                        new String[] { "1.0", "1.0.1", "1.1", "2.0" }, revs);
925:
926:                mod = ResolverTestHelper.getEntry(mods, "mod1.2");
927:                revs = resolver.listRevisions(mod);
928:                ResolverTestHelper.assertRevisionEntries(resolver, mod,
929:                        new String[] { "1.0", "1.1", "2.0", "2.1", "2.2" },
930:                        revs);
931:            }
932:
933:            public void testDownloadWithUseOriginIsTrue() throws Exception {
934:                FileSystemResolver resolver = new FileSystemResolver();
935:                resolver.setName("test");
936:                resolver.setSettings(settings);
937:                ((DefaultRepositoryCacheManager) resolver
938:                        .getRepositoryCacheManager()).setUseOrigin(true);
939:                assertEquals("test", resolver.getName());
940:
941:                resolver.addIvyPattern(IVY_PATTERN);
942:                resolver
943:                        .addArtifactPattern("test/repositories/1/"
944:                                + "[organisation]/[module]/[type]s/[artifact]-[revision].[type]");
945:
946:                ModuleRevisionId mrid = ModuleRevisionId.newInstance("org1",
947:                        "mod1.1", "1.0");
948:                ResolvedModuleRevision rmr = resolver.getDependency(
949:                        new DefaultDependencyDescriptor(mrid, false), data);
950:                assertNotNull(rmr);
951:
952:                assertEquals(mrid, rmr.getId());
953:                Date pubdate = new GregorianCalendar(2004, 10, 1, 11, 0, 0)
954:                        .getTime();
955:                assertEquals(pubdate, rmr.getPublicationDate());
956:
957:                // test to ask to download
958:                DefaultArtifact artifact = new DefaultArtifact(mrid, pubdate,
959:                        "mod1.1", "jar", "jar");
960:                DownloadReport report = resolver.download(
961:                        new Artifact[] { artifact }, getDownloadOptions());
962:                assertNotNull(report);
963:
964:                assertEquals(1, report.getArtifactsReports().length);
965:
966:                ArtifactDownloadReport ar = report.getArtifactReport(artifact);
967:                assertNotNull(ar);
968:
969:                assertEquals(artifact, ar.getArtifact());
970:                assertEquals(DownloadStatus.NO, ar.getDownloadStatus());
971:            }
972:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.