1 package org.apache.maven.archiva.repository.project.filters;
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 org.apache.maven.archiva.model.ArchivaProjectModel;
23 import org.apache.maven.archiva.model.ArchivaRepository;
24 import org.apache.maven.archiva.model.Dependency;
25 import org.apache.maven.archiva.repository.project.ProjectModelException;
26 import org.apache.maven.archiva.repository.project.ProjectModelReader;
27 import org.apache.maven.archiva.repository.project.ProjectModelResolver;
28 import org.apache.maven.archiva.repository.project.filters.EffectiveProjectModelBuilder;
29 import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
30 import org.apache.maven.archiva.repository.project.resolvers.RepositoryProjectResolver;
31 import org.codehaus.plexus.PlexusTestCase;
34 import java.util.Iterator;
35 import java.util.List;
38 * EffectiveProjectModelBuilderTest
40 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
43 public class EffectiveProjectModelBuilderTest
44 extends PlexusTestCase
46 private static final String DEFAULT_REPOSITORY = "src/test/repositories/default-repository";
48 private ArchivaProjectModel createArchivaProjectModel( String path )
49 throws ProjectModelException
51 ProjectModelReader reader = new ProjectModel400Reader();
53 File pomFile = new File( getBasedir(), path );
55 return reader.read( pomFile );
58 private ProjectModelResolver createDefaultRepositoryResolver()
60 File defaultRepoDir = new File( getBasedir(), DEFAULT_REPOSITORY );
62 ArchivaRepository repo = new ArchivaRepository( "defaultTestRepo", "Default Test Repo", "file://"
63 + defaultRepoDir.getAbsolutePath() );
65 RepositoryProjectResolver resolver = new RepositoryProjectResolver( repo );
70 public void testBuildEffectiveProject()
73 EffectiveProjectModelBuilder builder = new EffectiveProjectModelBuilder();
74 builder.addProjectModelResolver( createDefaultRepositoryResolver() );
76 ArchivaProjectModel startModel = createArchivaProjectModel( DEFAULT_REPOSITORY
77 + "/org/apache/maven/archiva/archiva-model/1.0-SNAPSHOT/archiva-model-1.0-SNAPSHOT.pom" );
79 ArchivaProjectModel effectiveModel = builder.buildEffectiveProjectModel( startModel );
81 ArchivaProjectModel expectedModel = createArchivaProjectModel( "src/test/effective-poms/"
82 + "/archiva-model-effective.pom" );
84 assertModel( expectedModel, effectiveModel );
87 private void assertModel( ArchivaProjectModel expectedModel, ArchivaProjectModel effectiveModel )
89 assertEquals( "Equivalent Models", expectedModel, effectiveModel );
91 assertContainsSame( "Individuals", expectedModel.getIndividuals(), effectiveModel.getIndividuals() );
92 dumpDependencyList( "Expected", expectedModel.getDependencies() );
93 dumpDependencyList( "Effective", effectiveModel.getDependencies() );
94 assertContainsSame( "Dependencies", expectedModel.getDependencies(), effectiveModel.getDependencies() );
95 assertContainsSame( "DependencyManagement", expectedModel.getDependencyManagement(), effectiveModel
96 .getDependencyManagement() );
99 private void dumpDependencyList( String type, List deps )
101 System.out.println( ".\\ [" + type + "] Dependency List (size:" + deps.size() + ") \\.________________" );
102 Iterator it = deps.iterator();
103 while ( it.hasNext() )
105 Dependency dep = (Dependency) it.next();
106 System.out.println( " " + toDependencyKey( dep ) );
108 System.out.println( "" );
111 private String toDependencyKey( Dependency dep )
113 return "[" + dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getVersion() + ":" + dep.getClassifier()
114 + ":" + dep.getType() + "]";
117 private void assertContainsSame( String listId, List expectedList, List effectiveList )
119 if ( ( expectedList == null ) && ( effectiveList == null ) )
124 if ( ( expectedList == null ) && ( effectiveList != null ) )
126 fail( "Effective [" + listId + "] List is instantiated, while expected List is null." );
129 if ( ( expectedList != null ) && ( effectiveList == null ) )
131 fail( "Effective [" + listId + "] List is null, while expected List is instantiated." );
134 assertEquals( "[" + listId + "] List Size", expectedList.size(), expectedList.size() );
136 Iterator it = expectedList.iterator();
137 while ( it.hasNext() )
139 Object o = it.next();
140 assertTrue( "Should exist in Effective [" + listId + "] list: " + o, effectiveList.contains( o ) );