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.test.utils.ArchivaSpringJUnit4ClassRunner;
30 import static org.assertj.core.api.Assertions.assertThat;
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;
39 import java.util.Collections;
40 import java.util.List;
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;
52 private PlexusSisuBridge plexusSisuBridge;
54 private static final String TEST_REPO_ID = "test";
56 private static final String TEST_VERSION = "1.2.1";
58 private static final String TEST_ARTIFACT_ID = "archiva-common";
60 private static final String TEST_GROUP_ID = "org.apache.archiva";
64 @Named( "archivaConfiguration#test" )
65 ArchivaConfiguration config;
74 Configuration configuration = new Configuration();
75 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
76 repoConfig.setId( TEST_REPO_ID );
77 repoConfig.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
78 configuration.addManagedRepository( repoConfig );
79 config.save( configuration );
81 //artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
85 private Artifact createArtifact( String groupId, String artifactId, String version )
87 return new Artifact( groupId, artifactId, version );
90 private String getId( Artifact artifact )
92 return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
96 public void testBuilderDependencies()
100 List<TreeEntry> treeEntries =
101 builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
104 assertThat( treeEntries ).isNotNull().isNotEmpty().contains(
105 new TreeEntry( new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" ) ) );
107 assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains(
108 new TreeEntry( new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" ) ) );
112 public static class TestTreeEntry
117 public TestTreeEntry( Artifact a )
123 public int hashCode()
125 return this.a.hashCode();
129 public boolean equals( Object o )
131 Artifact artifact = ( (TreeEntry) o ).getArtifact();
132 return artifact.equals( this.a );