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