Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 64BE2200CAC for ; Sun, 4 Jun 2017 20:06:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 63905160BE0; Sun, 4 Jun 2017 18:06:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3B8A2160BE6 for ; Sun, 4 Jun 2017 20:06:49 +0200 (CEST) Received: (qmail 98227 invoked by uid 500); 4 Jun 2017 18:06:48 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 97697 invoked by uid 99); 4 Jun 2017 18:06:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Jun 2017 18:06:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 69D96DFE5C; Sun, 4 Jun 2017 18:06:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: khmarbaise@apache.org To: commits@maven.apache.org Date: Sun, 04 Jun 2017 18:06:53 -0000 Message-Id: <4e5afe4a3f7646d0bb1e53c1532ed24a@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [07/50] maven git commit: [MNG-6182] ModelResolver interface enhancements. archived-at: Sun, 04 Jun 2017 18:06:50 -0000 [MNG-6182] ModelResolver interface enhancements. o Added unit tests for the 'ModelResolver' interface. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/f1ccecdd Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/f1ccecdd Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/f1ccecdd Branch: refs/heads/mvn-3.5.1/MNG-6174 Commit: f1ccecdd893eea0a320634a49bc6e56b776fb213 Parents: 55eeb32 Author: Christian Schulte Authored: Sun Mar 19 03:46:29 2017 +0100 Committer: Christian Schulte Committed: Sun Mar 19 04:01:34 2017 +0100 ---------------------------------------------------------------------- .../maven/project/ProjectModelResolverTest.java | 246 +++++++++++++++++++ .../internal/DefaultModelResolverTest.java | 222 +++++++++++++++++ 2 files changed, 468 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/f1ccecdd/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java ---------------------------------------------------------------------- diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java new file mode 100644 index 0000000..c21796b --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectModelResolverTest.java @@ -0,0 +1,246 @@ +package org.apache.maven.project; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Parent; +import org.apache.maven.model.resolution.ModelResolver; +import org.apache.maven.model.resolution.UnresolvableModelException; +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.impl.RemoteRepositoryManager; +import org.eclipse.aether.repository.RemoteRepository; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; +import static junit.framework.TestCase.assertTrue; +import static junit.framework.TestCase.fail; +import static org.codehaus.plexus.PlexusTestCase.getBasedir; + +/** + * Test cases for the project {@code ModelResolver} implementation. + * + * @author Christian Schulte + * @since 3.5.0-alpha-2 + */ +public class ProjectModelResolverTest extends AbstractMavenProjectTestCase +{ + + /** + * Creates a new {@code ProjectModelResolverTest} instance. + */ + public ProjectModelResolverTest() + { + super(); + } + + public void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "org.apache" ); + parent.setArtifactId( "apache" ); + parent.setVersion( "0" ); + + try + { + this.newModelResolver().resolveModel( parent ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertNotNull( e.getMessage() ); + assertTrue( e.getMessage().startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) ); + } + } + + public void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "org.apache" ); + parent.setArtifactId( "apache" ); + parent.setVersion( "[2.0,2.1)" ); + + try + { + this.newModelResolver().resolveModel( parent ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "No versions matched the requested parent version range '[2.0,2.1)'", + e.getMessage() ); + + } + } + + public void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "org.apache" ); + parent.setArtifactId( "apache" ); + parent.setVersion( "[1,)" ); + + try + { + this.newModelResolver().resolveModel( parent ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "The requested parent version range '[1,)' does not specify an upper bound", + e.getMessage() ); + + } + } + + public void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "org.apache" ); + parent.setArtifactId( "apache" ); + parent.setVersion( "1" ); + + assertNotNull( this.newModelResolver().resolveModel( parent ) ); + assertEquals( "1", parent.getVersion() ); + } + + public void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "org.apache" ); + parent.setArtifactId( "apache" ); + parent.setVersion( "(,2.0)" ); + + assertNotNull( this.newModelResolver().resolveModel( parent ) ); + assertEquals( "1", parent.getVersion() ); + } + + public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "org.apache" ); + dependency.setArtifactId( "apache" ); + dependency.setVersion( "0" ); + + try + { + this.newModelResolver().resolveModel( dependency ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertNotNull( e.getMessage() ); + assertTrue( e.getMessage().startsWith( "Could not find artifact org.apache:apache:pom:0 in central" ) ); + } + } + + public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "org.apache" ); + dependency.setArtifactId( "apache" ); + dependency.setVersion( "[2.0,2.1)" ); + + try + { + this.newModelResolver().resolveModel( dependency ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "No versions matched the requested dependency version range '[2.0,2.1)'", + e.getMessage() ); + + } + } + + public void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "org.apache" ); + dependency.setArtifactId( "apache" ); + dependency.setVersion( "[1,)" ); + + try + { + this.newModelResolver().resolveModel( dependency ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "The requested dependency version range '[1,)' does not specify an upper bound", + e.getMessage() ); + + } + } + + public void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "org.apache" ); + dependency.setArtifactId( "apache" ); + dependency.setVersion( "1" ); + + assertNotNull( this.newModelResolver().resolveModel( dependency ) ); + assertEquals( "1", dependency.getVersion() ); + } + + public void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "org.apache" ); + dependency.setArtifactId( "apache" ); + dependency.setVersion( "(,2.0)" ); + + assertNotNull( this.newModelResolver().resolveModel( dependency ) ); + assertEquals( "1", dependency.getVersion() ); + } + + private ModelResolver newModelResolver() throws Exception + { + final File localRepo = new File( this.getLocalRepository().getBasedir() ); + final DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession(); + repoSession.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) ); + + return new ProjectModelResolver( repoSession, null, lookup( RepositorySystem.class ), + lookup( RemoteRepositoryManager.class ), + this.getRemoteRepositories(), + ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT, null ); + + } + + private List getRemoteRepositories() + throws InvalidRepositoryException + { + final File repoDir = new File( getBasedir(), "src/test/remote-repo" ).getAbsoluteFile(); + final RemoteRepository remoteRepository = + new RemoteRepository.Builder( org.apache.maven.repository.RepositorySystem.DEFAULT_REMOTE_REPO_ID, + "default", repoDir.toURI().toASCIIString() ).build(); + + return Collections.singletonList( remoteRepository ); + } + +} http://git-wip-us.apache.org/repos/asf/maven/blob/f1ccecdd/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java ---------------------------------------------------------------------- diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java new file mode 100644 index 0000000..497cf6b --- /dev/null +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultModelResolverTest.java @@ -0,0 +1,222 @@ +package org.apache.maven.repository.internal; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.net.MalformedURLException; +import java.util.Arrays; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Parent; +import org.apache.maven.model.resolution.ModelResolver; +import org.apache.maven.model.resolution.UnresolvableModelException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.eclipse.aether.impl.ArtifactResolver; +import org.eclipse.aether.impl.RemoteRepositoryManager; +import org.eclipse.aether.impl.VersionRangeResolver; + +/** + * Test cases for the default {@code ModelResolver} implementation. + * + * @author Christian Schulte + * @since 3.5.0-alpha-2 + */ +public final class DefaultModelResolverTest extends AbstractRepositoryTestCase +{ + + /** + * Creates a new {@code DefaultModelResolverTest} instance. + */ + public DefaultModelResolverTest() + { + super(); + } + + public void testResolveParentThrowsUnresolvableModelExceptionWhenNotFound() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "ut.simple" ); + parent.setArtifactId( "artifact" ); + parent.setVersion( "0" ); + + try + { + this.newModelResolver().resolveModel( parent ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertNotNull( e.getMessage() ); + assertTrue( e.getMessage().startsWith( "Could not find artifact ut.simple:artifact:pom:0 in repo" ) ); + } + } + + public void testResolveParentThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "ut.simple" ); + parent.setArtifactId( "artifact" ); + parent.setVersion( "[2.0,2.1)" ); + + try + { + this.newModelResolver().resolveModel( parent ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "No versions matched the requested parent version range '[2.0,2.1)'", + e.getMessage() ); + + } + } + + public void testResolveParentThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "ut.simple" ); + parent.setArtifactId( "artifact" ); + parent.setVersion( "[1.0,)" ); + + try + { + this.newModelResolver().resolveModel( parent ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "The requested parent version range '[1.0,)' does not specify an upper bound", + e.getMessage() ); + + } + } + + public void testResolveParentSuccessfullyResolvesExistingParentWithoutRange() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "ut.simple" ); + parent.setArtifactId( "artifact" ); + parent.setVersion( "1.0" ); + + assertNotNull( this.newModelResolver().resolveModel( parent ) ); + assertEquals( "1.0", parent.getVersion() ); + } + + public void testResolveParentSuccessfullyResolvesExistingParentUsingHighestVersion() throws Exception + { + final Parent parent = new Parent(); + parent.setGroupId( "ut.simple" ); + parent.setArtifactId( "artifact" ); + parent.setVersion( "(,2.0)" ); + + assertNotNull( this.newModelResolver().resolveModel( parent ) ); + assertEquals( "1.0", parent.getVersion() ); + } + + public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNotFound() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "ut.simple" ); + dependency.setArtifactId( "artifact" ); + dependency.setVersion( "0" ); + + try + { + this.newModelResolver().resolveModel( dependency ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertNotNull( e.getMessage() ); + assertTrue( e.getMessage().startsWith( "Could not find artifact ut.simple:artifact:pom:0 in repo" ) ); + } + } + + public void testResolveDependencyThrowsUnresolvableModelExceptionWhenNoMatchingVersionFound() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "ut.simple" ); + dependency.setArtifactId( "artifact" ); + dependency.setVersion( "[2.0,2.1)" ); + + try + { + this.newModelResolver().resolveModel( dependency ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "No versions matched the requested dependency version range '[2.0,2.1)'", + e.getMessage() ); + + } + } + + public void testResolveDependencyThrowsUnresolvableModelExceptionWhenUsingRangesWithoutUpperBound() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "ut.simple" ); + dependency.setArtifactId( "artifact" ); + dependency.setVersion( "[1.0,)" ); + + try + { + this.newModelResolver().resolveModel( dependency ); + fail( "Expected 'UnresolvableModelException' not thrown." ); + } + catch ( final UnresolvableModelException e ) + { + assertEquals( "The requested dependency version range '[1.0,)' does not specify an upper bound", + e.getMessage() ); + + } + } + + public void testResolveDependencySuccessfullyResolvesExistingDependencyWithoutRange() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "ut.simple" ); + dependency.setArtifactId( "artifact" ); + dependency.setVersion( "1.0" ); + + assertNotNull( this.newModelResolver().resolveModel( dependency ) ); + assertEquals( "1.0", dependency.getVersion() ); + } + + public void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVersion() throws Exception + { + final Dependency dependency = new Dependency(); + dependency.setGroupId( "ut.simple" ); + dependency.setArtifactId( "artifact" ); + dependency.setVersion( "(,2.0)" ); + + assertNotNull( this.newModelResolver().resolveModel( dependency ) ); + assertEquals( "1.0", dependency.getVersion() ); + } + + private ModelResolver newModelResolver() throws ComponentLookupException, MalformedURLException + { + return new DefaultModelResolver( this.session, null, this.getClass().getName(), + lookup( ArtifactResolver.class ), lookup( VersionRangeResolver.class ), + lookup( RemoteRepositoryManager.class ), + Arrays.asList( newTestRepository() ) ); + + } + +}