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