1 package org.apache.maven.archiva.web.tags;
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 java.util.List;
24 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
25 import org.apache.archiva.metadata.repository.MetadataResolver;
26 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
27 import org.apache.maven.archiva.common.ArchivaException;
28 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
29 import org.apache.maven.archiva.configuration.Configuration;
30 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.maven.artifact.Artifact;
32 import org.apache.maven.artifact.factory.ArtifactFactory;
33 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
35 public class DependencyTreeTest
36 extends PlexusInSpringTestCase
38 private DependencyTree tree;
40 private ArtifactFactory artifactFactory;
42 private static final String TEST_VERSION = "version";
44 private static final String TEST_REPO_ID = "test-repo";
46 private static final String TEST_GROUP_ID = "groupId";
48 private static final String TEST_ARTIFACT_ID = "artifactId";
51 protected void setUp()
56 Configuration configuration = new Configuration();
57 ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
58 repoConfig.setId( TEST_REPO_ID );
59 repoConfig.setLocation( getTestPath( "src/test/repositories/test" ) );
60 configuration.addManagedRepository( repoConfig );
62 ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
63 archivaConfiguration.save( configuration );
65 tree = (DependencyTree) lookup( DependencyTree.class );
67 artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.class );
69 TestMetadataResolver metadataResolver = (TestMetadataResolver) lookup( MetadataResolver.class );
70 ProjectVersionMetadata metadata = new ProjectVersionMetadata();
71 metadata.setId( TEST_VERSION );
72 metadataResolver.setProjectVersion( TEST_REPO_ID, TEST_GROUP_ID, TEST_ARTIFACT_ID, metadata );
75 public void testTree()
76 throws ArchivaException
78 List<DependencyTree.TreeEntry> entries = tree.gatherTreeList( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
79 assertEquals( 8, entries.size() );
81 DependencyTree.TreeEntry artifactId = entries.get( 0 );
82 assertEquals( "<ul><li>", artifactId.getPre() );
83 assertEquals( createPomArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ), artifactId.getArtifact() );
84 assertEquals( "</li>", artifactId.getPost() );
86 DependencyTree.TreeEntry child1 = entries.get( 1 );
87 assertEquals( "<ul><li>", child1.getPre() );
88 assertEquals( createArtifact( TEST_GROUP_ID, "child1", "1.0" ), child1.getArtifact() );
89 assertEquals( "</li>", child1.getPost() );
91 DependencyTree.TreeEntry grandchild = entries.get( 2 );
92 assertEquals( "<ul><li>", grandchild.getPre() );
93 assertEquals( createArtifact( TEST_GROUP_ID, "grandchild1", "2.0" ), grandchild.getArtifact() );
94 assertEquals( "</li>", grandchild.getPost() );
96 DependencyTree.TreeEntry greatGrandchild = entries.get( 3 );
97 assertEquals( "<ul><li>", greatGrandchild.getPre() );
98 assertEquals( createArtifact( TEST_GROUP_ID, "great-grandchild", "3.0" ), greatGrandchild.getArtifact() );
99 assertEquals( "</li></ul></ul>", greatGrandchild.getPost() );
101 DependencyTree.TreeEntry child2 = entries.get( 4 );
102 assertEquals( "<li>", child2.getPre() );
103 assertEquals( createArtifact( TEST_GROUP_ID, "child2", "1.0" ), child2.getArtifact() );
104 assertEquals( "</li>", child2.getPost() );
106 DependencyTree.TreeEntry grandchild2 = entries.get( 5 );
107 assertEquals( "<ul><li>", grandchild2.getPre() );
108 assertEquals( createArtifact( TEST_GROUP_ID, "grandchild2", "2.0" ), grandchild2.getArtifact() );
109 assertEquals( "</li>", grandchild2.getPost() );
111 DependencyTree.TreeEntry grandchild3 = entries.get( 6 );
112 assertEquals( "<li>", grandchild3.getPre() );
113 assertEquals( createArtifact( TEST_GROUP_ID, "grandchild3", "2.0" ), grandchild3.getArtifact() );
114 assertEquals( "</li></ul>", grandchild3.getPost() );
116 DependencyTree.TreeEntry child3 = entries.get( 7 );
117 assertEquals( "<li>", child3.getPre() );
118 assertEquals( createArtifact( TEST_GROUP_ID, "child3", "1.0" ), child3.getArtifact() );
119 assertEquals( "</li></ul></ul>", child3.getPost() );
122 private Artifact createPomArtifact( String groupId, String artifactId, String version )
124 return artifactFactory.createProjectArtifact( groupId, artifactId, version );
127 private Artifact createArtifact( String groupId, String artifactId, String version )
129 return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );