http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/ant/types/ExclusionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/ant/types/ExclusionTest.java b/src/test/java/org/eclipse/aether/ant/types/ExclusionTest.java deleted file mode 100644 index 92ad368..0000000 --- a/src/test/java/org/eclipse/aether/ant/types/ExclusionTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.ant.types; - -import static org.junit.Assert.*; - -import org.eclipse.aether.ant.types.Exclusion; -import org.junit.Test; - -/** - */ -public class ExclusionTest -{ - - @Test - public void testSetCoordsGid() - { - Exclusion ex = new Exclusion(); - ex.setCoords( "gid" ); - - assertEquals( "gid", ex.getGroupId() ); - assertEquals( "*", ex.getArtifactId() ); - assertEquals( "*", ex.getExtension() ); - assertEquals( "*", ex.getClassifier() ); - } - - @Test - public void testSetCoordsGidAid() - { - Exclusion ex = new Exclusion(); - ex.setCoords( "gid:aid" ); - - assertEquals( "gid", ex.getGroupId() ); - assertEquals( "aid", ex.getArtifactId() ); - assertEquals( "*", ex.getExtension() ); - assertEquals( "*", ex.getClassifier() ); - } - - @Test - public void testSetCoordsGidAidExt() - { - Exclusion ex = new Exclusion(); - ex.setCoords( "gid:aid:ext" ); - - assertEquals( "gid", ex.getGroupId() ); - assertEquals( "aid", ex.getArtifactId() ); - assertEquals( "ext", ex.getExtension() ); - assertEquals( "*", ex.getClassifier() ); - } - - @Test - public void testSetCoordsGidAidExtCls() - { - Exclusion ex = new Exclusion(); - ex.setCoords( "gid:aid:ext:cls" ); - - assertEquals( "gid", ex.getGroupId() ); - assertEquals( "aid", ex.getArtifactId() ); - assertEquals( "ext", ex.getExtension() ); - assertEquals( "cls", ex.getClassifier() ); - - ex = new Exclusion(); - ex.setCoords( "gid:aid:ext:" ); - - assertEquals( "gid", ex.getGroupId() ); - assertEquals( "aid", ex.getArtifactId() ); - assertEquals( "ext", ex.getExtension() ); - assertEquals( "", ex.getClassifier() ); - } - -}
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/ant/types/PomTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/ant/types/PomTest.java b/src/test/java/org/eclipse/aether/ant/types/PomTest.java deleted file mode 100644 index 125d75b..0000000 --- a/src/test/java/org/eclipse/aether/ant/types/PomTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2011 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.ant.types; - -import static org.junit.Assert.*; - -import org.eclipse.aether.ant.types.Pom; -import org.junit.Test; - -/** - */ -public class PomTest -{ - - @Test - public void testSetCoordsGid() - { - Pom pom = new Pom(); - pom.setCoords( "gid:aid:ver" ); - - assertEquals( "gid", pom.getGroupId() ); - assertEquals( "aid", pom.getArtifactId() ); - assertEquals( "ver", pom.getVersion() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/AntBuildsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/AntBuildsTest.java b/src/test/java/org/eclipse/aether/internal/ant/AntBuildsTest.java new file mode 100644 index 0000000..c8b6a55 --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/AntBuildsTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import java.io.File; +import java.io.PrintStream; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.Project; +import org.eclipse.aether.internal.ant.ProjectWorkspaceReader; +import org.eclipse.aether.internal.test.util.TestFileUtils; + +public abstract class AntBuildsTest + extends BuildFileTest +{ + + private static final File BASE_DIR; + + protected static final File BUILD_DIR; + + static + { + BASE_DIR = new File( "" ).getAbsoluteFile(); + BUILD_DIR = new File( BASE_DIR, "target/ant" ); + } + + protected File projectDir; + + protected File localRepoDir; + + protected File distRepoDir; + + protected String getProjectDirName() + { + String name = getClass().getSimpleName(); + if ( name.endsWith( "Test" ) ) + { + name = name.substring( 0, name.length() - 4 ); + } + return name; + } + + protected void setUpProperties() + throws Exception + { + // hook for subclasses to set further system properties for the project to pick up + } + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + TestFileUtils.deleteFile( BUILD_DIR ); + + projectDir = new File( new File( BASE_DIR, "src/test/resources/ant" ), getProjectDirName() ); + localRepoDir = new File( BUILD_DIR, "local-repo" ); + distRepoDir = new File( BUILD_DIR, "dist-repo" ); + + System.setProperty( "project.dir", projectDir.getAbsolutePath() ); + System.setProperty( "build.dir", BUILD_DIR.getAbsolutePath() ); + System.setProperty( "maven.repo.local", localRepoDir.getAbsolutePath() ); + System.setProperty( "project.distrepo.url", distRepoDir.toURI().toString() ); + setUpProperties(); + + configureProject( new File( projectDir, "ant.xml" ).getAbsolutePath(), Project.MSG_VERBOSE ); + } + + @Override + protected void tearDown() + throws Exception + { + try + { + ProjectWorkspaceReader.dropInstance(); + TestFileUtils.deleteFile( BUILD_DIR ); + } + finally + { + super.tearDown(); + } + } + + @Override + public void configureProject( String filename, int logLevel ) + throws BuildException + { + super.configureProject( filename, logLevel ); + DefaultLogger logger = new DefaultLogger() + { + @Override + protected void printMessage( String message, PrintStream stream, int priority ) + { + message = System.currentTimeMillis() + " " + message; + super.printMessage( message, stream, priority ); + } + }; + logger.setMessageOutputLevel( logLevel ); + logger.setOutputPrintStream( System.out ); + logger.setErrorPrintStream( System.err ); + getProject().addBuildListener( logger ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/DeployTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/DeployTest.java b/src/test/java/org/eclipse/aether/internal/ant/DeployTest.java new file mode 100644 index 0000000..aaf814b --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/DeployTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.io.File; +import java.util.Arrays; + +/* + * still missing: + * - deploy snapshots/releases into correct repos + */ +public class DeployTest + extends AntBuildsTest +{ + + public void testDeployGlobalPom() + { + long min = System.currentTimeMillis(); + executeTarget( "testDeployGlobalPom" ); + long max = System.currentTimeMillis(); + + assertLogContaining( "Uploading" ); + + assertUpdatedFile( min, max, distRepoDir, "test/dummy/0.1-SNAPSHOT/maven-metadata.xml" ); + } + + public void testDeployOverrideGlobalPom() + { + long min = System.currentTimeMillis(); + executeTarget( "testDeployOverrideGlobalPom" ); + long max = System.currentTimeMillis(); + + assertLogContaining( "Uploading" ); + + assertUpdatedFile( min, max, distRepoDir, "test/other/0.1-SNAPSHOT/maven-metadata.xml" ); + } + + public void testDeployOverrideGlobalPomByRef() + { + long min = System.currentTimeMillis(); + executeTarget( "testDeployOverrideGlobalPomByRef" ); + long max = System.currentTimeMillis(); + + assertLogContaining( "Uploading" ); + + assertUpdatedFile( min, max, distRepoDir, "test/dummy/0.1-SNAPSHOT/maven-metadata.xml" ); + assertUpdatedFile( min, max, distRepoDir, "test/other/0.1-SNAPSHOT/maven-metadata.xml" ); + } + + public void testDeployAttachedArtifact() + { + executeTarget( "testDeployAttachedArtifact" ); + + assertLogContaining( "Uploading" ); + + File dir = new File(distRepoDir, "test/dummy/0.1-SNAPSHOT/" ); + String[] files = dir.list(); + assertThat( "attached artifact not found: " + Arrays.toString( files ), files, + hasItemInArray( endsWith( "-ant.xml" ) ) ); + } + + private void assertUpdatedFile( long min, long max, File repoPath, String path ) + { + File file = new File( repoPath, path ); + min = (min / 1000) * 1000; + max = ((max + 999) / 1000) * 1000; + assertThat( "File does not exist in default repo: " + file.getAbsolutePath(), file.exists() ); + assertThat( "Files were not updated for 1s before/after timestamp", file.lastModified(), + allOf( greaterThanOrEqualTo( min ), lessThanOrEqualTo( max ) ) ); + } +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/InstallTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/InstallTest.java b/src/test/java/org/eclipse/aether/internal/ant/InstallTest.java new file mode 100644 index 0000000..a915fac --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/InstallTest.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.io.File; +import java.io.IOException; + +public class InstallTest + extends AntBuildsTest +{ + + public void testInstallGlobalPom() + { + executeTarget( "testInstallGlobalPom" ); + long tstamp = System.currentTimeMillis(); + + assertLogContaining( "Installing" ); + + assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" ); + } + + public void testInstallOverrideGlobalPom() + { + executeTarget( "testInstallOverrideGlobalPom" ); + long tstamp = System.currentTimeMillis(); + + assertLogContaining( "Installing" ); + + assertUpdatedFile( tstamp, localRepoDir, "test/other/0.1-SNAPSHOT/other-0.1-SNAPSHOT.pom" ); + } + + public void testInstallOverrideGlobalPomByRef() + { + long tstamp = System.currentTimeMillis(); + executeTarget( "testInstallOverrideGlobalPomByRef" ); + + assertLogContaining( "Installing" ); + + assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" ); + assertUpdatedFile( tstamp, localRepoDir, "test/other/0.1-SNAPSHOT/other-0.1-SNAPSHOT.pom" ); + } + + public void testDefaultRepo() + { + executeTarget( "testDefaultRepo" ); + long tstamp = System.currentTimeMillis(); + + assertLogContaining( "Installing" ); + + assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" ); + assertUpdatedFile( tstamp, localRepoDir, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT-ant.xml" ); + } + + public void testCustomRepo() + throws IOException + { + File repoPath = new File( BUILD_DIR, "local-repo-custom" ); + + executeTarget( "testCustomRepo" ); + long tstamp = System.currentTimeMillis(); + + System.out.println( getLog() ); + assertLogContaining( "Installing" ); + + assertUpdatedFile( tstamp, repoPath, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT.pom" ); + assertUpdatedFile( tstamp, repoPath, "test/dummy/0.1-SNAPSHOT/dummy-0.1-SNAPSHOT-ant.xml" ); + } + + private void assertUpdatedFile( long tstamp, File repoPath, String path ) + { + File file = new File( repoPath, path ); + assertThat( "File does not exist in default repo: " + file.getAbsolutePath(), file.exists() ); + assertThat( "Files were not updated for 1s before/after timestamp", + file.lastModified(), + allOf( greaterThanOrEqualTo( ( ( tstamp - 500 ) / 1000 ) * 1000 ), + lessThanOrEqualTo( tstamp + 2000 ) ) ); + } +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/ProjectWorkspaceReaderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/ProjectWorkspaceReaderTest.java b/src/test/java/org/eclipse/aether/internal/ant/ProjectWorkspaceReaderTest.java new file mode 100644 index 0000000..fa2abae --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/ProjectWorkspaceReaderTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.io.File; + +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Test; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.internal.ant.ProjectWorkspaceReader; +import org.eclipse.aether.internal.ant.types.Pom; + +public class ProjectWorkspaceReaderTest +{ + + private ProjectWorkspaceReader reader; + + private Project project; + + @Before + public void setUp() + throws Exception + { + this.reader = new ProjectWorkspaceReader(); + + this.project = new Project(); + project.setProperty( "user.home", System.getProperty( "user.home" ) ); + } + + private Artifact artifact( String coords ) + { + return new DefaultArtifact( coords ); + } + + private File getFile( String name ) + { + return new File( "src/test/resources/ProjectWorkspaceReader", name ); + } + + @Test + public void testFindPom() + { + Pom pom = new Pom(); + pom.setProject( project ); + pom.setFile( getFile( "dummy-pom.xml" ) ); + + reader.addPom( pom ); + + assertEquals( pom.getFile(), reader.findArtifact( artifact( "test:dummy:pom:0.1-SNAPSHOT" ) ) ); + assertNull( reader.findArtifact( artifact( "unavailable:test:pom:0.1-SNAPSHOT" ) ) ); + } + + @Test + public void testFindArtifact() + { + Pom pom = new Pom(); + pom.setProject( project ); + pom.setFile( getFile( "dummy-pom.xml" ) ); + + reader.addPom( pom ); + + org.eclipse.aether.internal.ant.types.Artifact artifact = new org.eclipse.aether.internal.ant.types.Artifact(); + artifact.setProject( project ); + artifact.addPom( pom ); + artifact.setFile( getFile( "dummy-file.txt" ) ); + + reader.addArtifact( artifact ); + + assertEquals( artifact.getFile(), reader.findArtifact( artifact( "test:dummy:txt:0.1-SNAPSHOT" ) ) ); + assertNull( reader.findArtifact( artifact( "unavailable:test:jar:0.1-SNAPSHOT" ) ) ); + } + + @Test + public void testFindVersions() + { + Pom pom1 = new Pom(); + pom1.setProject( project ); + pom1.setCoords( "test:dummy:1-SNAPSHOT" ); + + org.eclipse.aether.internal.ant.types.Artifact artifact1 = new org.eclipse.aether.internal.ant.types.Artifact(); + artifact1.setProject( project ); + artifact1.addPom( pom1 ); + artifact1.setFile( getFile( "dummy-file.txt" ) ); + + reader.addArtifact( artifact1 ); + + Pom pom2 = new Pom(); + pom2.setProject( project ); + pom2.setCoords( "test:dummy:2-SNAPSHOT" ); + + org.eclipse.aether.internal.ant.types.Artifact artifact2 = new org.eclipse.aether.internal.ant.types.Artifact(); + artifact2.setProject( project ); + artifact2.addPom( pom2 ); + artifact2.setFile( getFile( "dummy-file.txt" ) ); + + reader.addArtifact( artifact2 ); + + assertThat( reader.findVersions( artifact( "test:dummy:txt:[0,)" ) ), + containsInAnyOrder( "1-SNAPSHOT", "2-SNAPSHOT" ) ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/ReactorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/ReactorTest.java b/src/test/java/org/eclipse/aether/internal/ant/ReactorTest.java new file mode 100644 index 0000000..753129e --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/ReactorTest.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.internal.ant.ProjectWorkspaceReader; + +public class ReactorTest + extends AntBuildsTest +{ + + private Artifact artifact( String coords ) + { + return new DefaultArtifact( coords ); + } + + public void testPom() + throws IOException + { + executeTarget( "testPom" ); + ProjectWorkspaceReader reader = ProjectWorkspaceReader.getInstance(); + File found = reader.findArtifact( artifact( "test:test:pom:0.1-SNAPSHOT" ) ); + assertNotNull( found ); + assertEquals( new File( projectDir, "pom1.xml" ), found.getAbsoluteFile() ); + } + + public void testArtifact() + throws IOException + { + executeTarget( "testArtifact" ); + ProjectWorkspaceReader reader = ProjectWorkspaceReader.getInstance(); + File found = reader.findArtifact( artifact( "test:test:pom:0.1-SNAPSHOT" ) ); + assertNotNull( found ); + assertEquals( new File( projectDir, "pom1.xml" ), found.getAbsoluteFile() ); + + found = reader.findArtifact( artifact( "test:test:xml:0.1-SNAPSHOT" ) ); + assertNotNull( found ); + assertEquals( new File( projectDir, "pom1.xml" ), found.getAbsoluteFile() ); + } + + public void testArtifactInMemoryPom() + throws IOException + { + executeTarget( "testArtifactInMemoryPom" ); + ProjectWorkspaceReader reader = ProjectWorkspaceReader.getInstance(); + File found = reader.findArtifact( artifact( "test:test:pom:0.1-SNAPSHOT" ) ); + assertNull( found ); + + found = reader.findArtifact( artifact( "test:test:xml:0.1-SNAPSHOT" ) ); + assertNotNull( found ); + assertEquals( new File( projectDir, "pom1.xml" ), found.getAbsoluteFile() ); + } + + public void testResolveArtifact() + throws IOException + { + executeTarget( "testResolveArtifact" ); + String prop = project.getProperty( "resolve.test:test:jar" ); + assertEquals( new File( projectDir, "pom1.xml" ).getAbsolutePath(), prop ); + } + + public void testResolveArtifactInMemoryPom() + throws IOException + { + executeTarget( "testResolveArtifactInMemoryPom" ); + String prop = project.getProperty( "resolve.test:test:jar" ); + assertEquals( new File( projectDir, "pom1.xml" ).getAbsolutePath(), prop ); + assertLogContaining( "The POM for test:test:jar:0.1-SNAPSHOT is missing, no dependency information available" ); + } + + public void testResolveVersionRange() + throws IOException + { + executeTarget( "testResolveVersionRange" ); + String prop = project.getProperty( "resolve.test:test:jar" ); + assertEquals( new File( projectDir, "pom1.xml" ).getAbsolutePath(), prop ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/ResolveTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/ResolveTest.java b/src/test/java/org/eclipse/aether/internal/ant/ResolveTest.java new file mode 100644 index 0000000..e68f684 --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/ResolveTest.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Map; + +import org.apache.tools.ant.types.Path; + +public class ResolveTest + extends AntBuildsTest +{ + + public void testResolveGlobalPom() + { + executeTarget( "testResolveGlobalPom" ); + + String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" ); + assertThat( "aether-api was not resolved as a property", prop, notNullValue() ); + assertThat( "aether-api was not resolved to default local repository", prop, + allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) ); + } + + public void testResolveOverrideGlobalPom() + { + executeTarget( "testResolveOverrideGlobalPom" ); + + String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" ); + assertThat( "aether-api was not resolved as a property", prop, notNullValue() ); + assertThat( "aether-api was not resolved to default local repository", prop, + allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) ); + } + + public void testResolveGlobalPomIntoOtherLocalRepo() + { + executeTarget( "testResolveGlobalPomIntoOtherLocalRepo" ); + + String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" ); + assertThat( "aether-api was not resolved as a property", prop, notNullValue() ); + assertThat( "aether-api was not resolved to default local repository", prop.replace( '\\', '/' ), + endsWith( "local-repo-custom/org/eclipse/aether/aether-api/0.9.0.M3/aether-api-0.9.0.M3.jar" ) ); + } + + public void testResolveCustomFileLayout() + throws IOException + { + File dir = new File( BUILD_DIR, "resolve-custom-layout" ); + executeTarget( "testResolveCustomFileLayout" ); + + assertThat( "aether-api was not saved with custom file layout", + new File( dir, "org.eclipse.aether/aether-api/org/eclipse/aether/jar" ).exists() ); + } + + public void testResolveAttachments() + throws IOException + { + File dir = new File( BUILD_DIR, "resolve-attachments" ); + executeTarget( "testResolveAttachments" ); + + File jdocDir = new File(dir, "javadoc"); + + assertThat( "aether-api-javadoc was not saved with custom file layout", + new File( jdocDir, "org.eclipse.aether-aether-api-javadoc.jar" ).exists() ); + + assertThat( "found non-javadoc files", Arrays.asList( jdocDir.list() ), everyItem( endsWith( "javadoc.jar" ) ) ); + + File sourcesDir = new File( dir, "sources" ); + assertThat( "aether-api-sources was not saved with custom file layout", + new File( sourcesDir, "org.eclipse.aether-aether-api-sources.jar" ).exists() ); + assertThat( "found non-sources files", Arrays.asList( sourcesDir.list() ), + everyItem( endsWith( "sources.jar" ) ) ); + } + + public void testResolvePath() + { + executeTarget( "testResolvePath" ); + Map<?, ?> refs = getProject().getReferences(); + Object obj = refs.get( "out" ); + assertThat( "ref 'out' is no path", obj, instanceOf( Path.class ) ); + Path path = (Path) obj; + String[] elements = path.list(); + assertThat( "no aether-api on classpath", elements, + hasItemInArray( allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) ) ); + } + + public void testResolveDepsFromFile() + { + executeTarget( "testResolveDepsFromFile" ); + + String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-spi:jar" ); + assertThat( "aether-spi was not resolved as a property", prop, notNullValue() ); + assertThat( "aether-spi was not resolved to default local repository", prop, + allOf( containsString( "aether-spi" ), endsWith( ".jar" ) ) ); + prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" ); + assertThat( "aether-api was resolved as a property", prop, nullValue() ); + } + + public void testResolveNestedDependencyCollections() + { + executeTarget( "testResolveNestedDependencyCollections" ); + + String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-spi:jar" ); + assertThat( "aether-spi was not resolved as a property", prop, notNullValue() ); + prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-util:jar" ); + assertThat( "aether-util was not resolved as a property", prop, notNullValue() ); + prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" ); + assertThat( "aether-api was resolved as a property", prop, nullValue() ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/SettingsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/SettingsTest.java b/src/test/java/org/eclipse/aether/internal/ant/SettingsTest.java new file mode 100644 index 0000000..8fdf0ed --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/SettingsTest.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.aether.internal.ant.AntRepoSys; + +public class SettingsTest + extends AntBuildsTest +{ + + public void testUserSettings() + { + executeTarget( "testUserSettings" ); + assertThat( "user settings not set", AntRepoSys.getInstance( getProject() ).getUserSettings().getName(), + equalTo( "userSettings.xml" ) ); + } + + public void testGlobalSettings() + { + executeTarget( "testGlobalSettings" ); + assertThat( "global settings not set", AntRepoSys.getInstance( getProject() ).getGlobalSettings().getName(), + equalTo( "globalSettings.xml" ) ); + } + + public void testBothSettings() + { + executeTarget( "testBothSettings" ); + assertThat( "global settings not set", AntRepoSys.getInstance( getProject() ).getGlobalSettings().getName(), + equalTo( "globalSettings.xml" ) ); + assertThat( "user settings not set", AntRepoSys.getInstance( getProject() ).getUserSettings().getName(), + equalTo( "userSettings.xml" ) ); + } + + public void testFallback() + throws IOException + { + executeTarget("setUp"); + assertThat( "no fallback to local settings", + AntRepoSys.getInstance( getProject() ).getUserSettings().getAbsolutePath(), endsWith( ".m2" + + File.separator + "settings.xml" ) ); + } +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/tasks/LayoutTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/tasks/LayoutTest.java b/src/test/java/org/eclipse/aether/internal/ant/tasks/LayoutTest.java new file mode 100644 index 0000000..62fe745 --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/tasks/LayoutTest.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant.tasks; + +import static org.junit.Assert.assertEquals; + +import org.apache.tools.ant.BuildException; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.internal.ant.tasks.Layout; +import org.junit.Test; + +/** + */ +public class LayoutTest +{ + + @Test( expected = BuildException.class ) + public void testUnknownVariable() + { + new Layout( "{unknown}" ); + } + + @Test + public void testGetPath() + { + Layout layout; + + layout = + new Layout( "{groupIdDirs}/{artifactId}/{baseVersion}/{artifactId}-{version}-{classifier}.{extension}" ); + assertEquals( "org/apache/maven/maven-model/3.0-SNAPSHOT/maven-model-3.0-20100720.132618-1.jar", + layout.getPath( new DefaultArtifact( "org.apache.maven:maven-model:3.0-20100720.132618-1" ) ) ); + + layout = new Layout( "{groupId}/{artifactId}-{version}-{classifier}.{extension}" ); + assertEquals( "org.apache.maven/maven-model-3.0-sources.jar", + layout.getPath( new DefaultArtifact( "org.apache.maven:maven-model:jar:sources:3.0" ) ) ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/types/DependencyTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/types/DependencyTest.java b/src/test/java/org/eclipse/aether/internal/ant/types/DependencyTest.java new file mode 100644 index 0000000..c750bf3 --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/types/DependencyTest.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant.types; + +import static org.junit.Assert.*; + +import org.eclipse.aether.internal.ant.types.Dependency; +import org.junit.Test; + +/** + */ +public class DependencyTest +{ + + @Test + public void testSetCoordsGidAidVer() + { + Dependency dep = new Dependency(); + dep.setCoords( "gid:aid:ver" ); + + assertEquals( "gid", dep.getGroupId() ); + assertEquals( "aid", dep.getArtifactId() ); + assertEquals( "ver", dep.getVersion() ); + assertEquals( "jar", dep.getType() ); + assertEquals( "", dep.getClassifier() ); + assertEquals( "compile", dep.getScope() ); + } + + @Test + public void testSetCoordsGidAidVerScope() + { + Dependency dep = new Dependency(); + dep.setCoords( "gid:aid:ver:scope" ); + + assertEquals( "gid", dep.getGroupId() ); + assertEquals( "aid", dep.getArtifactId() ); + assertEquals( "ver", dep.getVersion() ); + assertEquals( "jar", dep.getType() ); + assertEquals( "", dep.getClassifier() ); + assertEquals( "scope", dep.getScope() ); + } + + @Test + public void testSetCoordsGidAidVerTypeScope() + { + Dependency dep = new Dependency(); + dep.setCoords( "gid:aid:ver:type:scope" ); + + assertEquals( "gid", dep.getGroupId() ); + assertEquals( "aid", dep.getArtifactId() ); + assertEquals( "ver", dep.getVersion() ); + assertEquals( "type", dep.getType() ); + assertEquals( "", dep.getClassifier() ); + assertEquals( "scope", dep.getScope() ); + } + + @Test + public void testSetCoordsGidAidVerTypeClsScope() + { + Dependency dep = new Dependency(); + dep.setCoords( "gid:aid:ver:type:cls:scope" ); + + assertEquals( "gid", dep.getGroupId() ); + assertEquals( "aid", dep.getArtifactId() ); + assertEquals( "ver", dep.getVersion() ); + assertEquals( "type", dep.getType() ); + assertEquals( "cls", dep.getClassifier() ); + assertEquals( "scope", dep.getScope() ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/types/ExclusionTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/types/ExclusionTest.java b/src/test/java/org/eclipse/aether/internal/ant/types/ExclusionTest.java new file mode 100644 index 0000000..9c32a79 --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/types/ExclusionTest.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant.types; + +import static org.junit.Assert.*; + +import org.eclipse.aether.internal.ant.types.Exclusion; +import org.junit.Test; + +/** + */ +public class ExclusionTest +{ + + @Test + public void testSetCoordsGid() + { + Exclusion ex = new Exclusion(); + ex.setCoords( "gid" ); + + assertEquals( "gid", ex.getGroupId() ); + assertEquals( "*", ex.getArtifactId() ); + assertEquals( "*", ex.getExtension() ); + assertEquals( "*", ex.getClassifier() ); + } + + @Test + public void testSetCoordsGidAid() + { + Exclusion ex = new Exclusion(); + ex.setCoords( "gid:aid" ); + + assertEquals( "gid", ex.getGroupId() ); + assertEquals( "aid", ex.getArtifactId() ); + assertEquals( "*", ex.getExtension() ); + assertEquals( "*", ex.getClassifier() ); + } + + @Test + public void testSetCoordsGidAidExt() + { + Exclusion ex = new Exclusion(); + ex.setCoords( "gid:aid:ext" ); + + assertEquals( "gid", ex.getGroupId() ); + assertEquals( "aid", ex.getArtifactId() ); + assertEquals( "ext", ex.getExtension() ); + assertEquals( "*", ex.getClassifier() ); + } + + @Test + public void testSetCoordsGidAidExtCls() + { + Exclusion ex = new Exclusion(); + ex.setCoords( "gid:aid:ext:cls" ); + + assertEquals( "gid", ex.getGroupId() ); + assertEquals( "aid", ex.getArtifactId() ); + assertEquals( "ext", ex.getExtension() ); + assertEquals( "cls", ex.getClassifier() ); + + ex = new Exclusion(); + ex.setCoords( "gid:aid:ext:" ); + + assertEquals( "gid", ex.getGroupId() ); + assertEquals( "aid", ex.getArtifactId() ); + assertEquals( "ext", ex.getExtension() ); + assertEquals( "", ex.getClassifier() ); + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/1ec78d99/src/test/java/org/eclipse/aether/internal/ant/types/PomTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/eclipse/aether/internal/ant/types/PomTest.java b/src/test/java/org/eclipse/aether/internal/ant/types/PomTest.java new file mode 100644 index 0000000..adb4f73 --- /dev/null +++ b/src/test/java/org/eclipse/aether/internal/ant/types/PomTest.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant.types; + +import static org.junit.Assert.*; + +import org.eclipse.aether.internal.ant.types.Pom; +import org.junit.Test; + +/** + */ +public class PomTest +{ + + @Test + public void testSetCoordsGid() + { + Pom pom = new Pom(); + pom.setCoords( "gid:aid:ver" ); + + assertEquals( "gid", pom.getGroupId() ); + assertEquals( "aid", pom.getArtifactId() ); + assertEquals( "ver", pom.getVersion() ); + } + +}