Unit test for dependency management with scope and classifier.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@721102 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2008-11-27 06:50:12 +00:00
parent 337021834b
commit 33962fbf54
10 changed files with 118 additions and 21 deletions

View File

@ -545,6 +545,10 @@ public class PomTransformer
Collections.sort(ips1, new Comparator<InterpolatorProperty>() Collections.sort(ips1, new Comparator<InterpolatorProperty>()
{ {
public int compare(InterpolatorProperty o, InterpolatorProperty o1) { public int compare(InterpolatorProperty o, InterpolatorProperty o1) {
if(o.getTag() == null || o1.getTag() == null)
{
return 0;
}
return PomInterpolatorTag.valueOf(o.getTag()).compareTo(PomInterpolatorTag.valueOf(o1.getTag())); return PomInterpolatorTag.valueOf(o.getTag()).compareTo(PomInterpolatorTag.valueOf(o1.getTag()));
} }
}); });

View File

@ -1,10 +0,0 @@
import org.apache.maven.shared.model.DomainModel;
public class EnforcerPomTest
{
public void testConstructionOfTheEnforcerPom()
throws Exception
{
DomainModel model = null;
}
}

View File

@ -0,0 +1,28 @@
package org.apache.maven.project.builder;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelProperty;
import java.util.List;
import java.io.IOException;
public class DefaultDomainModel implements DomainModel {
private List<ModelProperty> modelProperties;
public DefaultDomainModel(List<ModelProperty> modelProperties) {
this.modelProperties = modelProperties;
}
public List<ModelProperty> getModelProperties() throws IOException {
return modelProperties;
}
public String getEventHistory() {
return "";
}
public void setEventHistory(String s) {
}
}

View File

@ -0,0 +1,14 @@
package org.apache.maven.project.builder;
import org.apache.maven.shared.model.DomainModelFactory;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelProperty;
import java.util.List;
import java.io.IOException;
public class DefaultDomainModelFactory implements DomainModelFactory {
public DomainModel createDomainModel(List<ModelProperty> modelProperties) throws IOException {
return new DefaultDomainModel(modelProperties);
}
}

View File

@ -1,12 +1,68 @@
package org.apache.maven.project.builder; package org.apache.maven.project.builder;
import org.apache.maven.shared.model.DomainModel; import org.apache.maven.shared.model.*;
import org.apache.maven.shared.model.impl.DefaultModelDataSource;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.io.IOException;
import static org.junit.Assert.*;
public class EnforcerPomTest public class EnforcerPomTest
{ {
public void testConstructionOfTheEnforcerPom() @org.junit.Test
throws Exception public void dependencyManagementWithScopeAndClassifier() throws IOException
{ {
DomainModel model = null; List<ModelProperty> mp = new ArrayList<ModelProperty>();
mp.add(new ModelProperty(ProjectUri.xUri, null));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.xUri, null));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.xUri, null));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, null));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.groupId, "gid"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.artifactId, "aid"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.version, "v1"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.scope, "test"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.classifier, "tests"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.xUri, null));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.groupId, "gid"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.artifactId, "aid"));
mp.add(new ModelProperty(ProjectUri.DependencyManagement.Dependencies.Dependency.version, "v1"));
List<ModelProperty> mp2 = new ArrayList<ModelProperty>();
mp2.add(new ModelProperty(ProjectUri.xUri, null));
mp2.add(new ModelProperty(ProjectUri.Dependencies.xUri, null));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.xUri, null));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.groupId, "gid"));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid"));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.xUri, null));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.groupId, "gid"));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.artifactId, "aid"));
mp2.add(new ModelProperty(ProjectUri.Dependencies.Dependency.classifier, "tests"));
DomainModel childModel = new DefaultDomainModel(mp2);
DomainModel parentModel = new DefaultDomainModel(mp);
ModelTransformerContext ctx = new ModelTransformerContext(Arrays.asList(new ArtifactModelContainerFactory(),
new IdModelContainerFactory()));
ModelTransformer transformer = new PomTransformer(new DefaultDomainModelFactory());
DomainModel domainModel = ctx.transform( Arrays.asList(childModel, parentModel), transformer, transformer );
DefaultModelDataSource source = new DefaultModelDataSource();
source.init(domainModel.getModelProperties(), Arrays.asList(new ArtifactModelContainerFactory(), new IdModelContainerFactory()));
List<ModelContainer> containers = source.queryFor(ProjectUri.Dependencies.Dependency.xUri);
assertTrue(containers.size() == 1 );
assertTrue(contains(ProjectUri.Dependencies.Dependency.version, "v1", containers.get(0)));
}
private boolean contains(String name, String value, ModelContainer modelContainer) {
for(ModelProperty mp : modelContainer.getProperties()) {
if(mp.getUri().equals(name) && mp.getValue() != null && mp.getValue().equals(value)) {
return true;
}
}
return false;
} }
} }

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder; package org.apache.maven.project.builder.profile;
import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelContainerAction; import org.apache.maven.shared.model.ModelContainerAction;

View File

@ -1,6 +1,7 @@
package org.apache.maven.project.builder; package org.apache.maven.project.builder.profile;
import org.apache.maven.project.builder.profile.FileMatcher; import org.apache.maven.project.builder.profile.FileMatcher;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelProperty;

View File

@ -1,6 +1,7 @@
package org.apache.maven.project.builder; package org.apache.maven.project.builder.profile;
import org.apache.maven.project.builder.profile.JdkMatcher; import org.apache.maven.project.builder.profile.JdkMatcher;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelProperty;

View File

@ -1,6 +1,9 @@
package org.apache.maven.project.builder; package org.apache.maven.project.builder.profile;
import org.apache.maven.project.builder.profile.ProfileContext; import org.apache.maven.project.builder.profile.ProfileContext;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
import org.apache.maven.project.builder.IdModelContainerFactory;
import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.shared.model.DataSourceException;
import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainer;

View File

@ -1,6 +1,6 @@
package org.apache.maven.project.builder; package org.apache.maven.project.builder.profile;
import org.apache.maven.project.builder.profile.PropertyMatcher; import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainer;
import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelProperty;