1 package org.apache.archiva.dependency.tree.maven2;
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 junit.framework.TestCase;
23 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
24 import org.apache.archiva.configuration.ArchivaConfiguration;
25 import org.apache.archiva.configuration.Configuration;
26 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.archiva.maven2.model.Artifact;
28 import org.apache.archiva.maven2.model.TreeEntry;
29 import org.apache.archiva.repository.RepositoryRegistry;
30 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.springframework.test.context.ContextConfiguration;
36 import javax.inject.Inject;
37 import javax.inject.Named;
38 import java.nio.file.Paths;
39 import java.util.Collections;
40 import java.util.List;
42 import static org.assertj.core.api.Assertions.assertThat;
44 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
45 @ContextConfiguration( { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
46 public class DependencyTreeBuilderTestMaven3
50 @Named( "dependencyTreeBuilder#maven3" )
51 private Maven3DependencyTreeBuilder builder;
54 private PlexusSisuBridge plexusSisuBridge;
56 private static final String TEST_REPO_ID = "test";
58 private static final String TEST_VERSION = "1.2.1";
60 private static final String TEST_ARTIFACT_ID = "archiva-common";
62 private static final String TEST_GROUP_ID = "org.apache.archiva";
66 @Named( "archivaConfiguration#test" )
67 ArchivaConfiguration config;
70 RepositoryRegistry repositoryRegistry;
79 Configuration configuration = new Configuration();
80 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
81 repoConfig.setId( TEST_REPO_ID );
82 repoConfig.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString() );
83 configuration.addManagedRepository( repoConfig );
85 config.getConfiguration().getProxyConnectors().clear();
86 config.save( configuration );
88 repositoryRegistry.reload();
90 //artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
94 private Artifact createArtifact( String groupId, String artifactId, String version )
96 return new Artifact( groupId, artifactId, version );
99 private String getId( Artifact artifact )
101 return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
105 public void testBuilderDependencies()
109 List<TreeEntry> treeEntries =
110 builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
113 Artifact artifact = new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" );
114 artifact.setFileExtension("jar");
115 assertThat( treeEntries ).isNotNull().isNotEmpty().contains(new TreeEntry(artifact) );
117 artifact = new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" );
118 artifact.setFileExtension("jar");
119 assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains(
120 new TreeEntry(artifact) );
124 public static class TestTreeEntry
129 public TestTreeEntry( Artifact a )
135 public int hashCode()
137 return this.a.hashCode();
141 public boolean equals( Object o )
143 Artifact artifact = ( (TreeEntry) o ).getArtifact();
144 return artifact.equals( this.a );