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