1 package org.apache.archiva.repository.maven.metadata;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.utils.VersionComparator;
22 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
23 import org.apache.archiva.repository.ManagedRepositoryContent;
24 import org.apache.archiva.repository.maven.metadata.storage.mock.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.maven.AbstractRepositoryLayerTestCase;
32 import org.apache.archiva.repository.LayoutException;
33 import org.apache.archiva.repository.RemoteRepositoryContent;
34 import org.apache.archiva.repository.RepositoryContentProvider;
35 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
36 import org.apache.archiva.repository.metadata.base.MetadataTools;
37 import org.apache.archiva.repository.maven.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;
47 import javax.inject.Inject;
48 import javax.inject.Named;
49 import javax.xml.parsers.ParserConfigurationException;
50 import java.io.IOException;
51 import java.net.URISyntaxException;
52 import java.nio.charset.Charset;
53 import java.nio.file.Files;
54 import java.nio.file.Path;
55 import java.nio.file.Paths;
56 import java.util.ArrayList;
57 import java.util.Collections;
58 import java.util.List;
61 import static org.junit.Assert.*;
66 @SuppressWarnings( "deprecation" )
67 @ContextConfiguration (
68 { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-metadata-tools-test.xml" } )
69 public class MetadataToolsTest
70 extends AbstractRepositoryLayerTestCase
73 @Named ( "metadataTools#test" )
74 private MetadataTools tools;
77 @Named ( "archivaConfiguration#mock" )
78 protected MockConfiguration config;
80 private Path getRepositoryPath(String repoName) {
83 return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
85 catch ( URISyntaxException e )
87 throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
92 public void testGatherSnapshotVersionsA()
95 removeProxyConnector( "test-repo", "apache-snapshots" );
96 removeProxyConnector( "test-repo", "internal-snapshots" );
97 removeProxyConnector( "test-repo", "snapshots.codehaus.org" );
99 assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
100 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
101 "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
102 "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
103 "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } );
107 public void testGatherSnapshotVersionsAWithProxies()
110 // These proxied repositories do not need to exist for the purposes of this unit test,
111 // just the repository ids are important.
112 createProxyConnector( "test-repo", "apache-snapshots" );
113 createProxyConnector( "test-repo", "internal-snapshots" );
114 createProxyConnector( "test-repo", "snapshots.codehaus.org" );
116 assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
117 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
118 "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
119 "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
120 "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070315.033030-10"
121 /* Arrives in via snapshots.codehaus.org proxy */,
122 "1.0-alpha-11-20070316.175232-11" } );
126 public void testGetRepositorySpecificName()
129 RemoteRepositoryContent repoJavaNet =
130 createRemoteRepositoryContent( "maven2-repository.dev.java.net", "Java.net Repository for Maven 2",
131 "http://download.java.net/maven/2/", "default" );
132 RemoteRepositoryContent repoCentral =
133 createRemoteRepositoryContent( "central", "Central Global Repository", "http://repo1.maven.org/maven2/",
136 String convertedName =
137 tools.getRepositorySpecificName( repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml" );
138 assertMetadataPath( "commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml",
141 convertedName = tools.getRepositorySpecificName( repoCentral, "commons-lang/commons-lang/maven-metadata.xml" );
142 assertMetadataPath( "commons-lang/commons-lang/maven-metadata-central.xml", convertedName );
145 // TODO: replace with group tests
146 // public void testUpdateProjectBadArtifact()
151 // assertUpdatedProjectMetadata( "bad_artifact", null );
152 // fail( "Should have thrown an IOException on a bad artifact." );
154 // catch ( IOException e )
161 public void testUpdateProjectNonExistingVersion()
164 ManagedRepositoryContent testRepo = createTestRepoContent();
165 ProjectReference reference = new ProjectReference();
166 reference.setGroupId( "org.apache.archiva.metadata.tests" );
167 reference.setArtifactId( "missing_artifact" );
169 prepTestRepo( testRepo, reference );
171 // check metadata prior to update -- should contain the non-existing artifact version
172 assertProjectMetadata( testRepo, reference, "missing_artifact",
173 new String[]{ "1.0-SNAPSHOT", "1.1-SNAPSHOT", "1.2-SNAPSHOT" }, "1.2-SNAPSHOT", null );
175 tools.updateMetadata( testRepo, reference );
177 // metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT
178 assertProjectMetadata( testRepo, reference, "missing_artifact", new String[]{ "1.0-SNAPSHOT", "1.2-SNAPSHOT" },
179 "1.2-SNAPSHOT", null );
183 public void testUpdateProjectMissingMultipleVersions()
186 assertUpdatedProjectMetadata( "missing_metadata_b",
187 new String[]{ "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" },
188 "2.0-20070821-dev", "2.0-20070821-dev" );
192 public void testUpdateProjectMissingMultipleVersionsWithProxies()
195 // Attach the (bogus) proxies to the managed repo.
196 // These proxied repositories do not need to exist for the purposes of this unit test,
197 // just the repository ids are important.
198 createProxyConnector( "test-repo", "central" );
199 createProxyConnector( "test-repo", "java.net" );
201 assertUpdatedProjectMetadata( "proxied_multi",
202 new String[]{ "1.0-spec" /* in java.net */, "1.0" /* in managed, and central */,
203 "1.0.1" /* in central */, "1.1" /* in managed */, "2.0-proposal-beta"
204 /* in java.net */, "2.0-spec" /* in java.net */, "2.0"
205 /* in central, and java.net */, "2.0.1" /* in java.net */, "2.1"
206 /* in managed */, "3.0" /* in central */, "3.1" /* in central */ }, "3.1",
211 public void testUpdateProjectSimpleYetIncomplete()
214 assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
218 public void testUpdateProjectSimpleYetMissing()
221 assertUpdatedProjectMetadata( "missing_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
225 public void testUpdateVersionSimple10()
228 assertUpdatedReleaseVersionMetadata( "missing_metadata_a", "1.0" );
232 public void testUpdateVersionSimple20()
235 assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0" );
239 public void testUpdateVersionSimple20NotSnapshot()
242 assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0-20070821-dev" );
246 public void testUpdateVersionSnapshotA()
249 assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" );
253 public void testToPathFromVersionReference()
255 VersionedReference reference = new VersionedReference();
256 reference.setGroupId( "com.foo" );
257 reference.setArtifactId( "foo-tool" );
258 reference.setVersion( "1.0" );
260 assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( reference ) );
264 public void testToPathFromProjectReference()
266 ProjectReference reference = new ProjectReference();
267 reference.setGroupId( "com.foo" );
268 reference.setArtifactId( "foo-tool" );
270 assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) );
274 public void testToProjectReferenceFooTools()
275 throws RepositoryMetadataException
277 assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" );
281 public void testToProjectReferenceAReallyLongPath()
282 throws RepositoryMetadataException
284 String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
285 String artifactId = "a";
286 String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/maven-metadata.xml";
288 assertProjectReference( groupId, artifactId, path );
292 public void testToProjectReferenceCommonsLang()
293 throws RepositoryMetadataException
295 String groupId = "commons-lang";
296 String artifactId = "commons-lang";
297 String path = "commons-lang/commons-lang/maven-metadata.xml";
299 assertProjectReference( groupId, artifactId, path );
302 private void assertProjectReference( String groupId, String artifactId, String path )
303 throws RepositoryMetadataException
305 ProjectReference reference = tools.toProjectReference( path );
307 assertNotNull( "Reference should not be null.", reference );
308 assertEquals( "ProjectReference.groupId", groupId, reference.getGroupId() );
309 assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() );
313 public void testToVersionedReferenceFooTool()
314 throws RepositoryMetadataException
316 String groupId = "com.foo";
317 String artifactId = "foo-tool";
318 String version = "1.0";
319 String path = "com/foo/foo-tool/1.0/maven-metadata.xml";
321 assertVersionedReference( groupId, artifactId, version, path );
325 public void testToVersionedReferenceAReallyLongPath()
326 throws RepositoryMetadataException
328 String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
329 String artifactId = "a";
330 String version = "1.1-alpha-1";
331 String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/1.1-alpha-1/maven-metadata.xml";
333 assertVersionedReference( groupId, artifactId, version, path );
337 public void testToVersionedReferenceCommonsLang()
338 throws RepositoryMetadataException
340 String groupId = "commons-lang";
341 String artifactId = "commons-lang";
342 String version = "2.1";
343 String path = "commons-lang/commons-lang/2.1/maven-metadata.xml";
345 assertVersionedReference( groupId, artifactId, version, path );
349 public void testToVersionedReferenceSnapshot()
350 throws RepositoryMetadataException
352 String groupId = "com.foo";
353 String artifactId = "foo-connector";
354 String version = "2.1-SNAPSHOT";
355 String path = "com/foo/foo-connector/2.1-SNAPSHOT/maven-metadata.xml";
357 assertVersionedReference( groupId, artifactId, version, path );
360 private void assertVersionedReference( String groupId, String artifactId, String version, String path )
361 throws RepositoryMetadataException
363 VersionedReference reference = tools.toVersionedReference( path );
364 assertNotNull( "Reference should not be null.", reference );
366 assertEquals( "VersionedReference.groupId", groupId, reference.getGroupId() );
367 assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() );
368 assertEquals( "VersionedReference.version", version, reference.getVersion() );
371 private void assertSnapshotVersions( String artifactId, String version, String[] expectedVersions )
374 Path repoRootDir = getRepositoryPath( "metadata-repository" );
376 VersionedReference reference = new VersionedReference();
377 reference.setGroupId( "org.apache.archiva.metadata.tests" );
378 reference.setArtifactId( artifactId );
379 reference.setVersion( version );
381 MavenManagedRepository repo =
382 createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRootDir );
384 RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
386 ManagedRepositoryContent repoContent =
387 provider.createManagedContent( repo );
389 Set<String> testedVersionSet = tools.gatherSnapshotVersions( repoContent, reference );
391 // Sort the list (for asserts)
392 List<String> testedVersions = new ArrayList<>();
393 testedVersions.addAll( testedVersionSet );
394 Collections.sort( testedVersions, new VersionComparator() );
396 // Test the expected array of versions, to the actual tested versions
397 assertEquals( "Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size() );
399 for ( int i = 0; i < expectedVersions.length; i++ )
401 String actualVersion = testedVersions.get( i );
402 assertEquals( "Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion );
406 private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
407 ProjectReference reference )
408 throws LayoutException, IOException, SAXException, ParserConfigurationException
410 Path metadataFile = repository.getRepository().getAsset( "" ).getFilePath().resolve(tools.toPath( reference ) );
411 String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
413 Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
414 if ( detailedDiff.hasDifferences() )
416 for ( Difference diff : detailedDiff.getDifferences() ) {
417 System.out.println( diff );
419 // If it isn't similar, dump the difference.
420 assertEquals( expectedMetadata, actualMetadata );
424 private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
425 VersionedReference reference )
426 throws LayoutException, IOException, SAXException, ParserConfigurationException
428 Path metadataFile = repository.getRepository().getAsset("").getFilePath().resolve( tools.toPath( reference ) );
429 String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
431 Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
432 if ( detailedDiff.hasDifferences() )
434 for ( Difference diff : detailedDiff.getDifferences() ) {
435 System.out.println( diff );
437 // If it isn't similar, dump the difference.
438 assertEquals( expectedMetadata, actualMetadata );
442 private void assertMetadataPath( String expected, String actual )
444 assertEquals( "Repository Specific Metadata Path", expected, actual );
447 private void assertUpdatedProjectMetadata( String artifactId, String[] expectedVersions, String latestVersion,
448 String releaseVersion )
451 ManagedRepositoryContent testRepo = createTestRepoContent();
452 ProjectReference reference = new ProjectReference();
453 reference.setGroupId( "org.apache.archiva.metadata.tests" );
454 reference.setArtifactId( artifactId );
456 prepTestRepo( testRepo, reference );
458 tools.updateMetadata( testRepo, reference );
460 StringBuilder buf = new StringBuilder();
461 buf.append( "<metadata>\n" );
462 buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
463 buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
464 // buf.append( " <version>1.0</version>\n" );
466 if ( expectedVersions != null )
468 buf.append( " <versioning>\n" );
469 if ( latestVersion != null )
471 buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
473 if ( releaseVersion != null )
475 buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
478 buf.append( " <versions>\n" );
479 for ( int i = 0; i < expectedVersions.length; i++ )
481 buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
483 buf.append( " </versions>\n" );
484 buf.append( " </versioning>\n" );
486 buf.append( "</metadata>" );
488 assertMetadata( buf.toString(), testRepo, reference );
491 private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference,
492 String artifactId, String[] expectedVersions, String latestVersion,
493 String releaseVersion )
496 StringBuilder buf = new StringBuilder();
497 buf.append( "<metadata>\n" );
498 buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
499 buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
501 if ( expectedVersions != null )
503 buf.append( " <versioning>\n" );
504 if ( latestVersion != null )
506 buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
508 if ( releaseVersion != null )
510 buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
513 buf.append( " <versions>\n" );
514 for ( int i = 0; i < expectedVersions.length; i++ )
516 buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
518 buf.append( " </versions>\n" );
519 buf.append( " </versioning>\n" );
521 buf.append( "</metadata>" );
523 assertMetadata( buf.toString(), testRepo, reference );
526 private void assertUpdatedReleaseVersionMetadata( String artifactId, String version )
529 ManagedRepositoryContent testRepo = createTestRepoContent();
530 VersionedReference reference = new VersionedReference();
531 reference.setGroupId( "org.apache.archiva.metadata.tests" );
532 reference.setArtifactId( artifactId );
533 reference.setVersion( version );
535 prepTestRepo( testRepo, reference );
537 tools.updateMetadata( testRepo, reference );
539 StringBuilder buf = new StringBuilder();
540 buf.append( "<metadata>\n" );
541 buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
542 buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
543 buf.append( " <version>" ).append( reference.getVersion() ).append( "</version>\n" );
544 buf.append( "</metadata>" );
546 assertMetadata( buf.toString(), testRepo, reference );
549 private void assertUpdatedSnapshotVersionMetadata( String artifactId, String version, String expectedDate,
550 String expectedTime, String expectedBuildNumber )
553 ManagedRepositoryContent testRepo = createTestRepoContent();
554 VersionedReference reference = new VersionedReference();
555 reference.setGroupId( "org.apache.archiva.metadata.tests" );
556 reference.setArtifactId( artifactId );
557 reference.setVersion( version );
559 prepTestRepo( testRepo, reference );
561 tools.updateMetadata( testRepo, reference );
563 StringBuilder buf = new StringBuilder();
564 buf.append( "<metadata>\n" );
565 buf.append( " <groupId>" ).append( reference.getGroupId() ).append( "</groupId>\n" );
566 buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
567 buf.append( " <version>" ).append( reference.getVersion() ).append( "</version>\n" );
568 buf.append( " <versioning>\n" );
569 buf.append( " <snapshot>\n" );
570 buf.append( " <buildNumber>" ).append( expectedBuildNumber ).append( "</buildNumber>\n" );
571 buf.append( " <timestamp>" );
572 buf.append( expectedDate ).append( "." ).append( expectedTime );
573 buf.append( "</timestamp>\n" );
574 buf.append( " </snapshot>\n" );
575 buf.append( " <lastUpdated>" ).append( expectedDate ).append( expectedTime ).append( "</lastUpdated>\n" );
576 buf.append( " </versioning>\n" );
577 buf.append( "</metadata>" );
579 assertMetadata( buf.toString(), testRepo, reference );
582 private void removeProxyConnector( String sourceRepoId, String targetRepoId )
584 ProxyConnectorConfiguration toRemove = null;
585 for ( ProxyConnectorConfiguration pcc : config.getConfiguration().getProxyConnectors() )
587 if ( pcc.getTargetRepoId().equals( targetRepoId ) && pcc.getSourceRepoId().equals( sourceRepoId ) )
592 if ( toRemove != null )
594 config.getConfiguration().removeProxyConnector( toRemove );
595 String prefix = "proxyConnectors.proxyConnector(" + "1" + ")"; // XXX
596 config.triggerChange( prefix + ".sourceRepoId", toRemove.getSourceRepoId() );
597 config.triggerChange( prefix + ".targetRepoId", toRemove.getTargetRepoId() );
598 config.triggerChange( prefix + ".proxyId", toRemove.getProxyId() );
599 config.triggerChange( prefix + ".policies.releases", toRemove.getPolicy( "releases", "" ) );
600 config.triggerChange( prefix + ".policies.checksum", toRemove.getPolicy( "checksum", "" ) );
601 config.triggerChange( prefix + ".policies.snapshots", toRemove.getPolicy( "snapshots", "" ) );
602 config.triggerChange( prefix + ".policies.cache-failures", toRemove.getPolicy( "cache-failures", "" ) );
606 private void createProxyConnector( String sourceRepoId, String targetRepoId )
608 ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
609 connectorConfig.setSourceRepoId( sourceRepoId );
610 connectorConfig.setTargetRepoId( targetRepoId );
611 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.IGNORE.getId() );
612 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS.getId() );
613 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.ALWAYS.getId() );
614 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.NO.getId() );
616 int count = config.getConfiguration().getProxyConnectors().size();
617 config.getConfiguration().addProxyConnector( connectorConfig );
619 // Proper Triggering ...
620 String prefix = "proxyConnectors.proxyConnector(" + count + ")";
621 config.triggerChange( prefix + ".sourceRepoId", connectorConfig.getSourceRepoId() );
622 config.triggerChange( prefix + ".targetRepoId", connectorConfig.getTargetRepoId() );
623 config.triggerChange( prefix + ".proxyId", connectorConfig.getProxyId() );
624 config.triggerChange( prefix + ".policies.releases", connectorConfig.getPolicy( "releases", "" ) );
625 config.triggerChange( prefix + ".policies.checksum", connectorConfig.getPolicy( "checksum", "" ) );
626 config.triggerChange( prefix + ".policies.snapshots", connectorConfig.getPolicy( "snapshots", "" ) );
627 config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) );
630 private ManagedRepositoryContent createTestRepoContent()
633 Path repoRoot = Paths.get( "target/metadata-tests/" + name.getMethodName() );
634 if ( Files.exists(repoRoot) )
636 org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRoot );
639 Files.createDirectories(repoRoot);
641 MavenManagedRepository repoConfig =
642 createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRoot );
644 RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
646 ManagedRepositoryContent repoContent =
647 provider.createManagedContent( repoConfig );
651 private void prepTestRepo( ManagedRepositoryContent repo, ProjectReference reference )
654 String groupDir = StringUtils.replaceChars( reference.getGroupId(), '.', '/' );
655 String path = groupDir + "/" + reference.getArtifactId();
657 Path srcRepoDir = getRepositoryPath( "metadata-repository" );
658 Path srcDir = srcRepoDir.resolve( path );
659 Path destDir = repo.getRepository().getAsset( "" ).getFilePath().resolve( path );
661 assertTrue( "Source Dir exists: " + srcDir, Files.exists(srcDir) );
662 Files.createDirectories(destDir);
664 FileUtils.copyDirectory( srcDir.toFile(), destDir.toFile() );
667 private void prepTestRepo( ManagedRepositoryContent repo, VersionedReference reference )
670 ProjectReference projectRef = new ProjectReference();
671 projectRef.setGroupId( reference.getGroupId() );
672 projectRef.setArtifactId( reference.getArtifactId() );
674 prepTestRepo( repo, projectRef );