1 package org.apache.archiva.repository.maven.dependency.tree;
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 junit.framework.TestCase;
22 import org.apache.archiva.configuration.ArchivaConfiguration;
23 import org.apache.archiva.configuration.Configuration;
24 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.apache.archiva.maven2.model.Artifact;
26 import org.apache.archiva.maven2.model.TreeEntry;
27 import org.apache.archiva.repository.RepositoryRegistry;
28 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.springframework.test.context.ContextConfiguration;
34 import javax.inject.Inject;
35 import javax.inject.Named;
36 import java.nio.file.Paths;
37 import java.util.Collections;
38 import java.util.List;
40 import static org.assertj.core.api.Assertions.assertThat;
42 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
43 @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
44 public class DependencyTreeBuilderTestMaven3
48 @Named( "dependencyTreeBuilder#maven3" )
49 private Maven3DependencyTreeBuilder builder;
51 private static final String TEST_REPO_ID = "test";
53 private static final String TEST_VERSION = "1.2.1";
55 private static final String TEST_ARTIFACT_ID = "archiva-common";
57 private static final String TEST_GROUP_ID = "org.apache.archiva";
61 @Named( "archivaConfiguration#test" )
62 ArchivaConfiguration config;
65 RepositoryRegistry repositoryRegistry;
74 Configuration configuration = new Configuration();
75 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
76 repoConfig.setId( TEST_REPO_ID );
77 repoConfig.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString() );
78 configuration.addManagedRepository( repoConfig );
80 config.getConfiguration().getProxyConnectors().clear();
81 config.save( configuration );
83 repositoryRegistry.reload();
85 //artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
89 private Artifact createArtifact( String groupId, String artifactId, String version )
91 return new Artifact( groupId, artifactId, version );
94 private String getId( Artifact artifact )
96 return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
100 public void testBuilderDependencies()
104 List<TreeEntry> treeEntries =
105 builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
108 Artifact artifact = new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" );
109 artifact.setFileExtension("jar");
110 assertThat( treeEntries ).isNotNull().isNotEmpty().contains(new TreeEntry(artifact) );
112 artifact = new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" );
113 artifact.setFileExtension("jar");
114 assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains(
115 new TreeEntry(artifact) );
119 public static class TestTreeEntry
124 public TestTreeEntry( Artifact a )
130 public int hashCode()
132 return this.a.hashCode();
136 public boolean equals( Object o )
138 Artifact artifact = ( (TreeEntry) o ).getArtifact();
139 return artifact.equals( this.a );