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