1 package org.apache.archiva.repository.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
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
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;
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;
60 import static org.junit.Assert.*;
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
72 @Named ( "metadataTools#test" )
73 private MetadataTools tools;
76 @Named ( "archivaConfiguration#mock" )
77 protected MockConfiguration config;
80 public void testGatherSnapshotVersionsA()
83 removeProxyConnector( "test-repo", "apache-snapshots" );
84 removeProxyConnector( "test-repo", "internal-snapshots" );
85 removeProxyConnector( "test-repo", "snapshots.codehaus.org" );
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" } );
95 public void testGatherSnapshotVersionsAWithProxies()
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" );
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" } );
114 public void testGetRepositorySpecificName()
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/",
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",
129 convertedName = tools.getRepositorySpecificName( repoCentral, "commons-lang/commons-lang/maven-metadata.xml" );
130 assertMetadataPath( "commons-lang/commons-lang/maven-metadata-central.xml", convertedName );
133 // TODO: replace with group tests
134 // public void testUpdateProjectBadArtifact()
139 // assertUpdatedProjectMetadata( "bad_artifact", null );
140 // fail( "Should have thrown an IOException on a bad artifact." );
142 // catch ( IOException e )
149 public void testUpdateProjectNonExistingVersion()
152 ManagedRepositoryContent testRepo = createTestRepoContent();
153 ProjectReference reference = new ProjectReference();
154 reference.setGroupId( "org.apache.archiva.metadata.tests" );
155 reference.setArtifactId( "missing_artifact" );
157 prepTestRepo( testRepo, reference );
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 );
163 tools.updateMetadata( testRepo, reference );
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 );
171 public void testUpdateProjectMissingMultipleVersions()
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" );
180 public void testUpdateProjectMissingMultipleVersionsWithProxies()
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" );
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",
199 public void testUpdateProjectSimpleYetIncomplete()
202 assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
206 public void testUpdateProjectSimpleYetMissing()
209 assertUpdatedProjectMetadata( "missing_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
213 public void testUpdateVersionSimple10()
216 assertUpdatedReleaseVersionMetadata( "missing_metadata_a", "1.0" );
220 public void testUpdateVersionSimple20()
223 assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0" );
227 public void testUpdateVersionSimple20NotSnapshot()
230 assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0-20070821-dev" );
234 public void testUpdateVersionSnapshotA()
237 assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" );
241 public void testToPathFromVersionReference()
243 VersionedReference reference = new VersionedReference();
244 reference.setGroupId( "com.foo" );
245 reference.setArtifactId( "foo-tool" );
246 reference.setVersion( "1.0" );
248 assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( reference ) );
252 public void testToPathFromProjectReference()
254 ProjectReference reference = new ProjectReference();
255 reference.setGroupId( "com.foo" );
256 reference.setArtifactId( "foo-tool" );
258 assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) );
262 public void testToProjectReferenceFooTools()
263 throws RepositoryMetadataException
265 assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" );
269 public void testToProjectReferenceAReallyLongPath()
270 throws RepositoryMetadataException
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";
276 assertProjectReference( groupId, artifactId, path );
280 public void testToProjectReferenceCommonsLang()
281 throws RepositoryMetadataException
283 String groupId = "commons-lang";
284 String artifactId = "commons-lang";
285 String path = "commons-lang/commons-lang/maven-metadata.xml";
287 assertProjectReference( groupId, artifactId, path );
290 private void assertProjectReference( String groupId, String artifactId, String path )
291 throws RepositoryMetadataException
293 ProjectReference reference = tools.toProjectReference( path );
295 assertNotNull( "Reference should not be null.", reference );
296 assertEquals( "ProjectReference.groupId", groupId, reference.getGroupId() );
297 assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() );
301 public void testToVersionedReferenceFooTool()
302 throws RepositoryMetadataException
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";
309 assertVersionedReference( groupId, artifactId, version, path );
313 public void testToVersionedReferenceAReallyLongPath()
314 throws RepositoryMetadataException
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";
321 assertVersionedReference( groupId, artifactId, version, path );
325 public void testToVersionedReferenceCommonsLang()
326 throws RepositoryMetadataException
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";
333 assertVersionedReference( groupId, artifactId, version, path );
337 public void testToVersionedReferenceSnapshot()
338 throws RepositoryMetadataException
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";
345 assertVersionedReference( groupId, artifactId, version, path );
348 private void assertVersionedReference( String groupId, String artifactId, String version, String path )
349 throws RepositoryMetadataException
351 VersionedReference reference = tools.toVersionedReference( path );
352 assertNotNull( "Reference should not be null.", reference );
354 assertEquals( "VersionedReference.groupId", groupId, reference.getGroupId() );
355 assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() );
356 assertEquals( "VersionedReference.version", version, reference.getVersion() );
359 private void assertSnapshotVersions( String artifactId, String version, String[] expectedVersions )
362 Path repoRootDir = Paths.get( "src/test/repositories/metadata-repository" );
364 VersionedReference reference = new VersionedReference();
365 reference.setGroupId( "org.apache.archiva.metadata.tests" );
366 reference.setArtifactId( artifactId );
367 reference.setVersion( version );
369 MavenManagedRepository repo =
370 createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRootDir );
372 RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
374 ManagedRepositoryContent repoContent =
375 provider.createManagedContent( repo );
377 Set<String> testedVersionSet = tools.gatherSnapshotVersions( repoContent, reference );
379 // Sort the list (for asserts)
380 List<String> testedVersions = new ArrayList<>();
381 testedVersions.addAll( testedVersionSet );
382 Collections.sort( testedVersions, new VersionComparator() );
384 // Test the expected array of versions, to the actual tested versions
385 assertEquals( "Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size() );
387 for ( int i = 0; i < expectedVersions.length; i++ )
389 String actualVersion = testedVersions.get( i );
390 assertEquals( "Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion );
394 private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
395 ProjectReference reference )
396 throws LayoutException, IOException, SAXException, ParserConfigurationException
398 Path metadataFile = Paths.get( repository.getRepoRoot(), tools.toPath( reference ) );
399 String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
401 Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
402 if ( detailedDiff.hasDifferences() )
404 for ( Difference diff : detailedDiff.getDifferences() ) {
405 System.out.println( diff );
407 // If it isn't similar, dump the difference.
408 assertEquals( expectedMetadata, actualMetadata );
412 private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
413 VersionedReference reference )
414 throws LayoutException, IOException, SAXException, ParserConfigurationException
416 Path metadataFile = Paths.get( repository.getRepoRoot(), tools.toPath( reference ) );
417 String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
419 Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
420 if ( detailedDiff.hasDifferences() )
422 for ( Difference diff : detailedDiff.getDifferences() ) {
423 System.out.println( diff );
425 // If it isn't similar, dump the difference.
426 assertEquals( expectedMetadata, actualMetadata );
430 private void assertMetadataPath( String expected, String actual )
432 assertEquals( "Repository Specific Metadata Path", expected, actual );
435 private void assertUpdatedProjectMetadata( String artifactId, String[] expectedVersions, String latestVersion,
436 String releaseVersion )
439 ManagedRepositoryContent testRepo = createTestRepoContent();
440 ProjectReference reference = new ProjectReference();
441 reference.setGroupId( "org.apache.archiva.metadata.tests" );
442 reference.setArtifactId( artifactId );
444 prepTestRepo( testRepo, reference );
446 tools.updateMetadata( testRepo, reference );
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" );
454 if ( expectedVersions != null )
456 buf.append( " <versioning>\n" );
457 if ( latestVersion != null )
459 buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
461 if ( releaseVersion != null )
463 buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
466 buf.append( " <versions>\n" );
467 for ( int i = 0; i < expectedVersions.length; i++ )
469 buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
471 buf.append( " </versions>\n" );
472 buf.append( " </versioning>\n" );
474 buf.append( "</metadata>" );
476 assertMetadata( buf.toString(), testRepo, reference );
479 private void assertProjectMetadata( ManagedRepositoryContent testRepo, ProjectReference reference,
480 String artifactId, String[] expectedVersions, String latestVersion,
481 String releaseVersion )
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" );
489 if ( expectedVersions != null )
491 buf.append( " <versioning>\n" );
492 if ( latestVersion != null )
494 buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
496 if ( releaseVersion != null )
498 buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
501 buf.append( " <versions>\n" );
502 for ( int i = 0; i < expectedVersions.length; i++ )
504 buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
506 buf.append( " </versions>\n" );
507 buf.append( " </versioning>\n" );
509 buf.append( "</metadata>" );
511 assertMetadata( buf.toString(), testRepo, reference );
514 private void assertUpdatedReleaseVersionMetadata( String artifactId, String version )
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 );
523 prepTestRepo( testRepo, reference );
525 tools.updateMetadata( testRepo, reference );
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>" );
534 assertMetadata( buf.toString(), testRepo, reference );
537 private void assertUpdatedSnapshotVersionMetadata( String artifactId, String version, String expectedDate,
538 String expectedTime, String expectedBuildNumber )
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 );
547 prepTestRepo( testRepo, reference );
549 tools.updateMetadata( testRepo, reference );
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>" );
567 assertMetadata( buf.toString(), testRepo, reference );
570 private void removeProxyConnector( String sourceRepoId, String targetRepoId )
572 ProxyConnectorConfiguration toRemove = null;
573 for ( ProxyConnectorConfiguration pcc : config.getConfiguration().getProxyConnectors() )
575 if ( pcc.getTargetRepoId().equals( targetRepoId ) && pcc.getSourceRepoId().equals( sourceRepoId ) )
580 if ( toRemove != null )
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", "" ) );
594 private void createProxyConnector( String sourceRepoId, String targetRepoId )
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() );
604 int count = config.getConfiguration().getProxyConnectors().size();
605 config.getConfiguration().addProxyConnector( connectorConfig );
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", "" ) );
618 private ManagedRepositoryContent createTestRepoContent()
621 Path repoRoot = Paths.get( "target/metadata-tests/" + name.getMethodName() );
622 if ( Files.exists(repoRoot) )
624 org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRoot );
627 Files.createDirectories(repoRoot);
629 MavenManagedRepository repoConfig =
630 createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRoot );
632 RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
634 ManagedRepositoryContent repoContent =
635 provider.createManagedContent( repoConfig );
639 private void prepTestRepo( ManagedRepositoryContent repo, ProjectReference reference )
642 String groupDir = StringUtils.replaceChars( reference.getGroupId(), '.', '/' );
643 String path = groupDir + "/" + reference.getArtifactId();
645 Path srcRepoDir = Paths.get( "src/test/repositories/metadata-repository" );
646 Path srcDir = srcRepoDir.resolve( path );
647 Path destDir = Paths.get( repo.getRepoRoot(), path );
649 assertTrue( "Source Dir exists: " + srcDir, Files.exists(srcDir) );
650 Files.createDirectories(destDir);
652 FileUtils.copyDirectory( srcDir.toFile(), destDir.toFile() );
655 private void prepTestRepo( ManagedRepositoryContent repo, VersionedReference reference )
658 ProjectReference projectRef = new ProjectReference();
659 projectRef.setGroupId( reference.getGroupId() );
660 projectRef.setArtifactId( reference.getArtifactId() );
662 prepTestRepo( repo, projectRef );