]> source.dussan.org Git - archiva.git/blob
b53857322b75e96d16752718d3e99af4f9082f1c
[archiva.git] /
1 package org.apache.maven.archiva.repository.metadata;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import org.apache.archiva.admin.model.beans.ManagedRepository;
23 import org.apache.commons.io.FileUtils;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.archiva.common.utils.VersionComparator;
26 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
27 import org.apache.archiva.model.ProjectReference;
28 import org.apache.archiva.model.VersionedReference;
29 import org.apache.archiva.policies.CachedFailuresPolicy;
30 import org.apache.archiva.policies.ChecksumPolicy;
31 import org.apache.archiva.policies.ReleasesPolicy;
32 import org.apache.archiva.policies.SnapshotsPolicy;
33 import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
34 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
35 import org.apache.maven.archiva.repository.MockConfiguration;
36 import org.apache.maven.archiva.repository.RemoteRepositoryContent;
37 import org.apache.maven.archiva.repository.layout.LayoutException;
38 import org.custommonkey.xmlunit.DetailedDiff;
39 import org.custommonkey.xmlunit.Diff;
40 import org.junit.Test;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.xml.sax.SAXException;
43
44 import java.io.File;
45 import java.io.IOException;
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.List;
49 import java.util.Set;
50 import javax.inject.Inject;
51 import javax.inject.Named;
52 import javax.xml.parsers.ParserConfigurationException;
53
54 import static org.junit.Assert.*;
55
56 /**
57  * MetadataToolsTest
58  *
59  * @version $Id$
60  */
61 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-metadata-tools-test.xml" } )
62 public class MetadataToolsTest
63     extends AbstractRepositoryLayerTestCase
64 {
65     @Inject @Named(value = "metadataTools#test")
66     private MetadataTools tools;
67
68     @Inject
69     @Named( value = "archivaConfiguration#mock" )
70     protected MockConfiguration config;
71
72     @Test
73     public void testGatherSnapshotVersionsA()
74         throws Exception
75     {
76         assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
77                                 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
78                                     "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
79                                     "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
80                                     "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } );
81     }
82
83     @Test
84     public void testGatherSnapshotVersionsAWithProxies()
85         throws Exception
86     {
87         // These proxied repositories do not need to exist for the purposes of this unit test,
88         // just the repository ids are important.
89         createProxyConnector( "test-repo", "apache-snapshots" );
90         createProxyConnector( "test-repo", "internal-snapshots" );
91         createProxyConnector( "test-repo", "snapshots.codehaus.org" );
92
93         assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
94                                 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
95                                     "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
96                                     "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
97                                     "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070315.033030-10"
98                                     /* Arrives in via snapshots.codehaus.org proxy */,
99                                     "1.0-alpha-11-20070316.175232-11" } );
100     }
101
102     @Test
103     public void testGetRepositorySpecificName()
104         throws Exception
105     {
106         RemoteRepositoryContent repoJavaNet =
107             createRemoteRepositoryContent( "maven2-repository.dev.java.net", "Java.net Repository for Maven 2",
108                                            "http://download.java.net/maven/2/", "default" );
109         RemoteRepositoryContent repoCentral =
110             createRemoteRepositoryContent( "central", "Central Global Repository", "http://repo1.maven.org/maven2/",
111                                            "default" );
112
113         String convertedName =
114             tools.getRepositorySpecificName( repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml" );
115         assertMetadataPath( "commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml",
116                             convertedName );
117
118         convertedName = tools.getRepositorySpecificName( repoCentral, "commons-lang/commons-lang/maven-metadata.xml" );
119         assertMetadataPath( "commons-lang/commons-lang/maven-metadata-central.xml", convertedName );
120     }
121
122     // TODO: replace with group tests
123 //    public void testUpdateProjectBadArtifact()
124 //        throws Exception
125 //    {
126 //        try
127 //        {
128 //            assertUpdatedProjectMetadata( "bad_artifact", null );
129 //            fail( "Should have thrown an IOException on a bad artifact." );
130 //        }
131 //        catch ( IOException e )
132 //        {
133 //            // Expected path
134 //        }
135 //    }
136
137     @Test
138     public void testUpdateProjectNonExistingVersion()
139         throws Exception
140     {
141         ManagedRepositoryContent testRepo = createTestRepoContent();
142         ProjectReference reference = new ProjectReference();
143         reference.setGroupId( "org.apache.archiva.metadata.tests" );
144         reference.setArtifactId( "missing_artifact" );
145
146         prepTestRepo( testRepo, reference );
147
148         // check metadata prior to update -- should contain the non-existing artifact version
149         assertProjectMetadata( testRepo, reference, "missing_artifact",
150                                new String[]{ "1.0-SNAPSHOT", "1.1-SNAPSHOT", "1.2-SNAPSHOT" }, "1.2-SNAPSHOT", null );
151
152         tools.updateMetadata( testRepo, reference );
153
154         // metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT
155         assertProjectMetadata( testRepo, reference, "missing_artifact", new String[]{ "1.0-SNAPSHOT", "1.2-SNAPSHOT" },
156                                "1.2-SNAPSHOT", null );
157     }
158
159     @Test
160     public void testUpdateProjectMissingMultipleVersions()
161         throws Exception
162     {
163         assertUpdatedProjectMetadata( "missing_metadata_b",
164                                       new String[]{ "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" },
165                                       "2.0-20070821-dev", "2.0-20070821-dev" );
166     }
167
168     @Test
169     public void testUpdateProjectMissingMultipleVersionsWithProxies()
170         throws Exception
171     {
172         // Attach the (bogus) proxies to the managed repo.
173         // These proxied repositories do not need to exist for the purposes of this unit test,
174         // just the repository ids are important.
175         createProxyConnector( "test-repo", "central" );
176         createProxyConnector( "test-repo", "java.net" );
177
178         assertUpdatedProjectMetadata( "proxied_multi",
179                                       new String[]{ "1.0-spec" /* in java.net */, "1.0" /* in managed, and central */,
180                                           "1.0.1" /* in central */, "1.1" /* in managed */, "2.0-proposal-beta"
181                                           /* in java.net */, "2.0-spec" /* in java.net */, "2.0"
182                                           /* in central, and java.net */, "2.0.1" /* in java.net */, "2.1"
183                                           /* in managed */, "3.0" /* in central */, "3.1" /* in central */ }, "3.1",
184                                       "3.1" );
185     }
186
187     @Test
188     public void testUpdateProjectSimpleYetIncomplete()
189         throws Exception
190     {
191         assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
192     }
193
194     @Test
195     public void testUpdateProjectSimpleYetMissing()
196         throws Exception
197     {
198         assertUpdatedProjectMetadata( "missing_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
199     }
200
201     @Test
202     public void testUpdateVersionSimple10()
203         throws Exception
204     {
205         assertUpdatedReleaseVersionMetadata( "missing_metadata_a", "1.0" );
206     }
207
208     @Test
209     public void testUpdateVersionSimple20()
210         throws Exception
211     {
212         assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0" );
213     }
214
215     @Test
216     public void testUpdateVersionSimple20NotSnapshot()
217         throws Exception
218     {
219         assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0-20070821-dev" );
220     }
221
222     @Test
223     public void testUpdateVersionSnapshotA()
224         throws Exception
225     {
226         assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" );
227     }
228
229     @Test
230     public void testToPathFromVersionReference()
231     {
232         VersionedReference reference = new VersionedReference();
233         reference.setGroupId( "com.foo" );
234         reference.setArtifactId( "foo-tool" );
235         reference.setVersion( "1.0" );
236
237         assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( reference ) );
238     }
239
240     @Test
241     public void testToPathFromProjectReference()
242     {
243         ProjectReference reference = new ProjectReference();
244         reference.setGroupId( "com.foo" );
245         reference.setArtifactId( "foo-tool" );
246
247         assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) );
248     }
249
250     @Test
251     public void testToProjectReferenceFooTools()
252         throws RepositoryMetadataException
253     {
254         assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" );
255     }
256
257     @Test
258     public void testToProjectReferenceAReallyLongPath()
259         throws RepositoryMetadataException
260     {
261         String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
262         String artifactId = "a";
263         String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/maven-metadata.xml";
264
265         assertProjectReference( groupId, artifactId, path );
266     }
267
268     @Test
269     public void testToProjectReferenceCommonsLang()
270         throws RepositoryMetadataException
271     {
272         String groupId = "commons-lang";
273         String artifactId = "commons-lang";
274         String path = "commons-lang/commons-lang/maven-metadata.xml";
275
276         assertProjectReference( groupId, artifactId, path );
277     }
278
279     private void assertProjectReference( String groupId, String artifactId, String path )
280         throws RepositoryMetadataException
281     {
282         ProjectReference reference = tools.toProjectReference( path );
283
284         assertNotNull( "Reference should not be null.", reference );
285         assertEquals( "ProjectReference.groupId", groupId, reference.getGroupId() );
286         assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() );
287     }
288
289     @Test
290     public void testToVersionedReferenceFooTool()
291         throws RepositoryMetadataException
292     {
293         String groupId = "com.foo";
294         String artifactId = "foo-tool";
295         String version = "1.0";
296         String path = "com/foo/foo-tool/1.0/maven-metadata.xml";
297
298         assertVersionedReference( groupId, artifactId, version, path );
299     }
300
301     @Test
302     public void testToVersionedReferenceAReallyLongPath()
303         throws RepositoryMetadataException
304     {
305         String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
306         String artifactId = "a";
307         String version = "1.1-alpha-1";
308         String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/1.1-alpha-1/maven-metadata.xml";
309
310         assertVersionedReference( groupId, artifactId, version, path );
311     }
312
313     @Test
314     public void testToVersionedReferenceCommonsLang()
315         throws RepositoryMetadataException
316     {
317         String groupId = "commons-lang";
318         String artifactId = "commons-lang";
319         String version = "2.1";
320         String path = "commons-lang/commons-lang/2.1/maven-metadata.xml";
321
322         assertVersionedReference( groupId, artifactId, version, path );
323     }
324
325     @Test
326     public void testToVersionedReferenceSnapshot()
327         throws RepositoryMetadataException
328     {
329         String groupId = "com.foo";
330         String artifactId = "foo-connector";
331         String version = "2.1-SNAPSHOT";
332         String path = "com/foo/foo-connector/2.1-SNAPSHOT/maven-metadata.xml";
333
334         assertVersionedReference( groupId, artifactId, version, path );
335     }
336
337     private void assertVersionedReference( String groupId, String artifactId, String version, String path )
338         throws RepositoryMetadataException
339     {
340         VersionedReference reference = tools.toVersionedReference( path );
341         assertNotNull( "Reference should not be null.", reference );
342
343         assertEquals( "VersionedReference.groupId", groupId, reference.getGroupId() );
344         assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() );
345         assertEquals( "VersionedReference.version", version, reference.getVersion() );
346     }
347
348     private void assertSnapshotVersions( String artifactId, String version, String[] expectedVersions )
349         throws Exception
350     {
351         File repoRootDir = new File( "src/test/repositories/metadata-repository" );
352
353         VersionedReference reference = new VersionedReference();
354         reference.setGroupId( "org.apache.archiva.metadata.tests" );
355         reference.setArtifactId( artifactId );
356         reference.setVersion( version );
357
358         ManagedRepository repo =
359             createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRootDir );
360         ManagedRepositoryContent repoContent =
361             applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class );
362         repoContent.setRepository( repo );
363
364         Set<String> testedVersionSet = tools.gatherSnapshotVersions( repoContent, reference );
365
366         // Sort the list (for asserts)
367         List<String> testedVersions = new ArrayList<String>();
368         testedVersions.addAll( testedVersionSet );
369         Collections.sort( testedVersions, new VersionComparator() );
370
371         // Test the expected array of versions, to the actual tested versions
372         assertEquals( "Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size() );
373
374         for ( int i = 0; i < expectedVersions.length; i++ )
375         {
376             String actualVersion = testedVersions.get( i );
377             assertEquals( "Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion );
378         }
379     }
380
381     private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
382                                  ProjectReference reference )
383         throws LayoutException, IOException, SAXException, ParserConfigurationException
384     {
385         File metadataFile = new File( repository.getRepoRoot(), tools.toPath( reference ) );
386         String actualMetadata = FileUtils.readFileToString( metadataFile, null );
387
388         DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadata, actualMetadata ) );
389         if ( !detailedDiff.similar() )
390         {
391             // If it isn't similar, dump the difference.
392             assertEquals( expectedMetadata, actualMetadata );
393         }
394     }
395
396     private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
397                                  VersionedReference reference )
398         throws LayoutException, IOException, SAXException, ParserConfigurationException
399     {
400         File metadataFile = new File( repository.getRepoRoot(), tools.toPath( reference ) );
401         String actualMetadata = FileUtils.readFileToString( metadataFile, null );
402
403         DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadata, actualMetadata ) );
404         if ( !detailedDiff.similar() )
405         {
406             // If it isn't similar, dump the difference.
407             assertEquals( expectedMetadata, actualMetadata );
408         }
409     }
410
411     private void assertMetadataPath( String expected, String actual )
412     {
413         assertEquals( "Repository Specific Metadata Path", expected, actual );
414     }
415
416     private void assertUpdatedProjectMetadata( String artifactId, String[] expectedVersions, String latestVersion,
417                                                String releaseVersion )
418         throws Exception
419     {
420         ManagedRepositoryContent testRepo = createTestRepoContent();
421         ProjectReference reference = new ProjectReference();
422         reference.setGroupId( "org.apache.archiva.metadata.tests" );
423         reference.setArtifactId( artifactId );
424
425         prepTestRepo( testRepo, reference );
426
427         tools.updateMetadata( testRepo, reference );
428
429         StringBuilder buf = new StringBuilder();
430         buf.append( "<metadata>\n" );
431         buf.append( "  <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
432         buf.append( "  <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
433         // buf.append( "  <version>1.0</version>\n" );
434
435         if ( expectedVersions != null )
436         {
437             buf.append( "  <versioning>\n" );
438             if ( latestVersion != null )
439             {
440                 buf.append( "    <latest>" ).append( latestVersion ).append( "</latest>\n" );
441             }
442             if ( releaseVersion != null )
443             {
444                 buf.append( "    <release>" ).append( releaseVersion ).append( "</release>\n" );
445             }
446
447             buf.append( "    <versions>\n" );
448             for ( int i = 0; i < expectedVersions.length; i++ )
449             {
450                 buf.append( "      <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
451             }
452             buf.append( "    </versions>\n" );
453             buf.append( "  </versioning>\n" );
454         }
455         buf.append( "</metadata>" );
456
457         assertMetadata( buf.toString(), testRepo, reference );
458     }
459
460     private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference,
461                                         String artifactId, String[] expectedVersions, String latestVersion,
462                                         String releaseVersion )
463         throws Exception
464     {
465         StringBuilder buf = new StringBuilder();
466         buf.append( "<metadata>\n" );
467         buf.append( "  <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
468         buf.append( "  <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
469
470         if ( expectedVersions != null )
471         {
472             buf.append( "  <versioning>\n" );
473             if ( latestVersion != null )
474             {
475                 buf.append( "    <latest>" ).append( latestVersion ).append( "</latest>\n" );
476             }
477             if ( releaseVersion != null )
478             {
479                 buf.append( "    <release>" ).append( releaseVersion ).append( "</release>\n" );
480             }
481
482             buf.append( "    <versions>\n" );
483             for ( int i = 0; i < expectedVersions.length; i++ )
484             {
485                 buf.append( "      <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
486             }
487             buf.append( "    </versions>\n" );
488             buf.append( "  </versioning>\n" );
489         }
490         buf.append( "</metadata>" );
491
492         assertMetadata( buf.toString(), testRepo, reference );
493     }
494
495     private void assertUpdatedReleaseVersionMetadata( String artifactId, String version )
496         throws Exception
497     {
498         ManagedRepositoryContent testRepo = createTestRepoContent();
499         VersionedReference reference = new VersionedReference();
500         reference.setGroupId( "org.apache.archiva.metadata.tests" );
501         reference.setArtifactId( artifactId );
502         reference.setVersion( version );
503
504         prepTestRepo( testRepo, reference );
505
506         tools.updateMetadata( testRepo, reference );
507
508         StringBuilder buf = new StringBuilder();
509         buf.append( "<metadata>\n" );
510         buf.append( "  <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
511         buf.append( "  <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
512         buf.append( "  <version>" ).append( reference.getVersion() ).append( "</version>\n" );
513         buf.append( "</metadata>" );
514
515         assertMetadata( buf.toString(), testRepo, reference );
516     }
517
518     private void assertUpdatedSnapshotVersionMetadata( String artifactId, String version, String expectedDate,
519                                                        String expectedTime, String expectedBuildNumber )
520         throws Exception
521     {
522         ManagedRepositoryContent testRepo = createTestRepoContent();
523         VersionedReference reference = new VersionedReference();
524         reference.setGroupId( "org.apache.archiva.metadata.tests" );
525         reference.setArtifactId( artifactId );
526         reference.setVersion( version );
527
528         prepTestRepo( testRepo, reference );
529
530         tools.updateMetadata( testRepo, reference );
531
532         StringBuilder buf = new StringBuilder();
533         buf.append( "<metadata>\n" );
534         buf.append( "  <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
535         buf.append( "  <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
536         buf.append( "  <version>" ).append( reference.getVersion() ).append( "</version>\n" );
537         buf.append( "  <versioning>\n" );
538         buf.append( "    <snapshot>\n" );
539         buf.append( "      <buildNumber>" ).append( expectedBuildNumber ).append( "</buildNumber>\n" );
540         buf.append( "      <timestamp>" );
541         buf.append( expectedDate ).append( "." ).append( expectedTime );
542         buf.append( "</timestamp>\n" );
543         buf.append( "    </snapshot>\n" );
544         buf.append( "    <lastUpdated>" ).append( expectedDate ).append( expectedTime ).append( "</lastUpdated>\n" );
545         buf.append( "  </versioning>\n" );
546         buf.append( "</metadata>" );
547
548         assertMetadata( buf.toString(), testRepo, reference );
549     }
550
551     private void createProxyConnector( String sourceRepoId, String targetRepoId )
552     {
553         ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
554         connectorConfig.setSourceRepoId( sourceRepoId );
555         connectorConfig.setTargetRepoId( targetRepoId );
556         connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.IGNORE );
557         connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS );
558         connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.ALWAYS );
559         connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.NO );
560
561         int count = config.getConfiguration().getProxyConnectors().size();
562         config.getConfiguration().addProxyConnector( connectorConfig );
563
564         // Proper Triggering ...
565         String prefix = "proxyConnectors.proxyConnector(" + count + ")";
566         config.triggerChange( prefix + ".sourceRepoId", connectorConfig.getSourceRepoId() );
567         config.triggerChange( prefix + ".targetRepoId", connectorConfig.getTargetRepoId() );
568         config.triggerChange( prefix + ".proxyId", connectorConfig.getProxyId() );
569         config.triggerChange( prefix + ".policies.releases", connectorConfig.getPolicy( "releases", "" ) );
570         config.triggerChange( prefix + ".policies.checksum", connectorConfig.getPolicy( "checksum", "" ) );
571         config.triggerChange( prefix + ".policies.snapshots", connectorConfig.getPolicy( "snapshots", "" ) );
572         config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) );
573     }
574
575     private ManagedRepositoryContent createTestRepoContent()
576         throws Exception
577     {
578         File repoRoot = new File( "target/metadata-tests/" + name.getMethodName() );
579         if ( repoRoot.exists() )
580         {
581             FileUtils.deleteDirectory( repoRoot );
582         }
583
584         repoRoot.mkdirs();
585
586         ManagedRepository repoConfig =
587             createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRoot );
588
589         ManagedRepositoryContent repoContent =
590             applicationContext.getBean( "managedRepositoryContent#default", ManagedRepositoryContent.class );
591         repoContent.setRepository( repoConfig );
592         return repoContent;
593     }
594
595     private void prepTestRepo( ManagedRepositoryContent repo, ProjectReference reference )
596         throws IOException
597     {
598         String groupDir = StringUtils.replaceChars( reference.getGroupId(), '.', '/' );
599         String path = groupDir + "/" + reference.getArtifactId();
600
601         File srcRepoDir = new File( "src/test/repositories/metadata-repository" );
602         File srcDir = new File( srcRepoDir, path );
603         File destDir = new File( repo.getRepoRoot(), path );
604
605         assertTrue( "Source Dir exists: " + srcDir, srcDir.exists() );
606         destDir.mkdirs();
607
608         FileUtils.copyDirectory( srcDir, destDir );
609     }
610
611     private void prepTestRepo( ManagedRepositoryContent repo, VersionedReference reference )
612         throws IOException
613     {
614         ProjectReference projectRef = new ProjectReference();
615         projectRef.setGroupId( reference.getGroupId() );
616         projectRef.setArtifactId( reference.getArtifactId() );
617
618         prepTestRepo( repo, projectRef );
619     }
620
621
622 }