From 33962fbf543680d15b29873a13c6413b0eb95046 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Thu, 27 Nov 2008 06:50:12 +0000 Subject: [PATCH] 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 --- .../maven/project/builder/PomTransformer.java | 4 ++ .../src/test/java/EnforcerPomTest.java | 10 --- .../project/builder/DefaultDomainModel.java | 28 ++++++++ .../builder/DefaultDomainModelFactory.java | 14 ++++ .../project/builder/EnforcerPomTest.java | 64 +++++++++++++++++-- .../{ => profile}/DefaultModelContainer.java | 2 +- .../{ => profile}/FileMatcherTest.java | 3 +- .../builder/{ => profile}/JdkMatcherTest.java | 3 +- .../{ => profile}/ProfileContextTest.java | 5 +- .../{ => profile}/PropertyMatcherTest.java | 6 +- 10 files changed, 118 insertions(+), 21 deletions(-) delete mode 100644 maven-project-builder/src/test/java/EnforcerPomTest.java create mode 100644 maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java create mode 100644 maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java rename maven-project-builder/src/test/java/org/apache/maven/project/builder/{ => profile}/DefaultModelContainer.java (94%) rename maven-project-builder/src/test/java/org/apache/maven/project/builder/{ => profile}/FileMatcherTest.java (97%) rename maven-project-builder/src/test/java/org/apache/maven/project/builder/{ => profile}/JdkMatcherTest.java (96%) rename maven-project-builder/src/test/java/org/apache/maven/project/builder/{ => profile}/ProfileContextTest.java (89%) rename maven-project-builder/src/test/java/org/apache/maven/project/builder/{ => profile}/PropertyMatcherTest.java (95%) diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java index ae66ae6e44..b247226258 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java @@ -545,6 +545,10 @@ public class PomTransformer Collections.sort(ips1, new Comparator() { 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())); } }); diff --git a/maven-project-builder/src/test/java/EnforcerPomTest.java b/maven-project-builder/src/test/java/EnforcerPomTest.java deleted file mode 100644 index 3ed47aee28..0000000000 --- a/maven-project-builder/src/test/java/EnforcerPomTest.java +++ /dev/null @@ -1,10 +0,0 @@ -import org.apache.maven.shared.model.DomainModel; - -public class EnforcerPomTest -{ - public void testConstructionOfTheEnforcerPom() - throws Exception - { - DomainModel model = null; - } -} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java new file mode 100644 index 0000000000..b0a04786b2 --- /dev/null +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java @@ -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 modelProperties; + + public DefaultDomainModel(List modelProperties) { + this.modelProperties = modelProperties; + } + + public List getModelProperties() throws IOException { + return modelProperties; + } + + public String getEventHistory() { + return ""; + } + + public void setEventHistory(String s) { + + } +} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java new file mode 100644 index 0000000000..023ce63d77 --- /dev/null +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModelFactory.java @@ -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 modelProperties) throws IOException { + return new DefaultDomainModel(modelProperties); + } +} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java index 458dd74589..6709fb60a5 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/EnforcerPomTest.java @@ -1,12 +1,68 @@ 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 void testConstructionOfTheEnforcerPom() - throws Exception + @org.junit.Test + public void dependencyManagementWithScopeAndClassifier() throws IOException { - DomainModel model = null; + List mp = new ArrayList(); + 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 mp2 = new ArrayList(); + 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 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; } } diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultModelContainer.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/DefaultModelContainer.java similarity index 94% rename from maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultModelContainer.java rename to maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/DefaultModelContainer.java index 5199bd7bda..d3311eb380 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultModelContainer.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/DefaultModelContainer.java @@ -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.ModelContainerAction; diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/FileMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/FileMatcherTest.java similarity index 97% rename from maven-project-builder/src/test/java/org/apache/maven/project/builder/FileMatcherTest.java rename to maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/FileMatcherTest.java index 480057afe0..a64f436957 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/FileMatcherTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/FileMatcherTest.java @@ -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.ProjectUri; import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelProperty; diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/JdkMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java similarity index 96% rename from maven-project-builder/src/test/java/org/apache/maven/project/builder/JdkMatcherTest.java rename to maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java index ee7a624d17..93a36769ab 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/JdkMatcherTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/JdkMatcherTest.java @@ -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.ProjectUri; import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelProperty; diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/ProfileContextTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java similarity index 89% rename from maven-project-builder/src/test/java/org/apache/maven/project/builder/ProfileContextTest.java rename to maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java index a8b85e6ccd..07a2c05c56 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/ProfileContextTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/ProfileContextTest.java @@ -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.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.InterpolatorProperty; import org.apache.maven.shared.model.ModelContainer; diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PropertyMatcherTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/PropertyMatcherTest.java similarity index 95% rename from maven-project-builder/src/test/java/org/apache/maven/project/builder/PropertyMatcherTest.java rename to maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/PropertyMatcherTest.java index ec6c80f1a1..1ee0590753 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PropertyMatcherTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/profile/PropertyMatcherTest.java @@ -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.ModelContainer; import org.apache.maven.shared.model.ModelProperty; @@ -39,7 +39,7 @@ public class PropertyMatcherTest { modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.xUri , null)); modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.name , "foo")); modelProperties.add(new ModelProperty(ProjectUri.Profiles.Profile.Activation.Property.value , "bars")); - + ModelContainer modelContainer = new DefaultModelContainer(modelProperties); List props = new ArrayList();