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 org.fest.assertions.api.Assertions;
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( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
44 public class DependencyTreeBuilderTestMaven3
48 @Named( value = "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( value = "archivaConfiguration#test" )
65 ArchivaConfiguration config;
73 Configuration configuration = new Configuration();
74 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
75 repoConfig.setId( TEST_REPO_ID );
76 repoConfig.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
77 configuration.addManagedRepository( repoConfig );
78 config.save( configuration );
80 //artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
84 private Artifact createArtifact( String groupId, String artifactId, String version )
86 return new Artifact( groupId, artifactId, version );
89 private String getId( Artifact artifact )
91 return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
95 public void testBuilderDependencies()
99 List<TreeEntry> treeEntries =
100 builder.buildDependencyTree( Collections.singletonList( TEST_REPO_ID ), TEST_GROUP_ID, TEST_ARTIFACT_ID,
103 Assertions.assertThat( treeEntries ).isNotNull().isNotEmpty().contains(
104 new TreeEntry( new Artifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, "", "" ) ) );
106 Assertions.assertThat( treeEntries.get( 0 ).getChilds() ).isNotNull().isNotEmpty().contains(
107 new TreeEntry( new Artifact( "commons-lang", "commons-lang", "2.2", "compile", "" ) ) );
111 public static class TestTreeEntry
116 public TestTreeEntry( Artifact a )
122 public int hashCode()
124 return this.a.hashCode();
128 public boolean equals( Object o )
130 Artifact artifact = ( (TreeEntry) o ).getArtifact();
131 return artifact.equals( this.a );