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