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