diff --git a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java index f915047..8b3b070 100644 --- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.Reader; -import java.util.Map; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Model; @@ -32,9 +31,7 @@ import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.utils.ReaderFactory; import org.apache.maven.shared.utils.io.FileUtils; -import org.apache.maven.shared.utils.io.IOUtil; import org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager; -import org.sonatype.aether.util.ChecksumUtils; import org.sonatype.aether.util.DefaultRepositorySystemSession; import static org.mockito.Mockito.mock; @@ -66,11 +63,6 @@ public void setUp() super.setUp(); FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) ); - -// LegacySupport legacySupport = lookup( LegacySupport.class ); -// RepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); -// MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); -// legacySupport.setSession( new MavenSession( getContainer(), repositorySession, executionRequest, null ) ); } public void testInstallFileTestEnvironment() @@ -166,29 +158,18 @@ public void testInstallFileWithGeneratePom() File installedPom = new File( getBasedir(), LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + "." + "pom" ); - Model model; + try ( Reader reader = ReaderFactory.newXmlReader( installedPom ) ) { + Model model = new MavenXpp3Reader().read( reader ); - Reader reader = null; - try - { - reader = ReaderFactory.newXmlReader( installedPom ); - model = new MavenXpp3Reader().read( reader ); - reader.close(); - reader = null; - } - finally - { - IOUtil.close( reader ); + assertEquals( "4.0.0", model.getModelVersion() ); + + assertEquals( (String) getVariableValueFromObject( mojo, "groupId" ), model.getGroupId() ); + + assertEquals( artifactId, model.getArtifactId() ); + + assertEquals( version, model.getVersion() ); } - assertEquals( "4.0.0", model.getModelVersion() ); - - assertEquals( (String) getVariableValueFromObject( mojo, "groupId" ), model.getGroupId() ); - - assertEquals( artifactId, model.getArtifactId() ); - - assertEquals( version, model.getVersion() ); - assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); } @@ -253,7 +234,7 @@ public void testInstallFileWithPomAsPackaging() assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); } - public void testInstallFileWithChecksum() + public void testInstallFile() throws Exception { File testPom = @@ -267,10 +248,6 @@ public void testInstallFileWithChecksum() assignValuesForParameter( mojo ); -// boolean createChecksum = (Boolean) getVariableValueFromObject( mojo, "createChecksum" ); -// -// assertTrue( createChecksum ); - mojo.execute(); String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" + @@ -278,19 +255,8 @@ public void testInstallFileWithChecksum() File installedArtifact = new File( localPath + "." + "jar" ); - //get the actual checksum of the artifact -// Map csums = ChecksumUtils.calc( file, Utils.CHECKSUM_ALGORITHMS ); -// for (Map.Entry csum : csums.entrySet()) { -// Object actualSum = csum.getValue(); -// File sum = new File( localPath + ".jar." + csum.getKey().toLowerCase().replace( "-", "" ) ); -// assertTrue( sum.exists() ); -// String generatedSum = FileUtils.fileRead( sum, "UTF-8" ); -// assertEquals( actualSum, generatedSum ); -// } - assertTrue( installedArtifact.exists() ); -// assertEquals( 9, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); } diff --git a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java index e211a18..63ac6fa 100644 --- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java @@ -58,14 +58,7 @@ public void setUp() { super.setUp(); - System.out.println( ">>>Cleaning local repo " + getBasedir() + "/" + LOCAL_REPO + "..." ); - FileUtils.deleteDirectory( new File( getBasedir() + "/" + LOCAL_REPO ) ); - -// LegacySupport legacySupport = lookup( LegacySupport.class ); -// RepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); -// MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); -// legacySupport.setSession( new MavenSession( getContainer(), repositorySession, executionRequest, null ) ); } public void testInstallTestEnvironment() @@ -250,7 +243,7 @@ public void testInstallIfPackagingIsPom() assertEquals( 4, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); } - public void testBasicInstallAndCreateChecksumIsTrue() + public void testBasicInstallAndCreate() throws Exception { File testPom = new File( getBasedir(), "target/test-classes/unit/basic-install-checksum/plugin-config.xml" ); @@ -270,10 +263,6 @@ public void testBasicInstallAndCreateChecksumIsTrue() artifact = (InstallArtifactStub) project.getArtifact(); -// boolean createChecksum = (Boolean) getVariableValueFromObject( mojo, "createChecksum" ); -// -// assertTrue( createChecksum ); - artifact.setFile( file ); mojo.execute(); @@ -302,31 +291,11 @@ public void testBasicInstallAndCreateChecksumIsTrue() String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion(); - //get the actual checksum of the pom -// Map csums = ChecksumUtils.calc( pom, Utils.CHECKSUM_ALGORITHMS ); -// for (Map.Entry csum : csums.entrySet()) { -// Object actualPomSum = csum.getValue(); -// File pomSum = new File( localPath + ".pom." + csum.getKey().toLowerCase().replace( "-", "" ) ); -// assertTrue( pomSum.exists() ); -// String generatedPomSum = FileUtils.fileRead( pomSum, "UTF-8" ); -// assertEquals( actualPomSum, generatedPomSum ); -// } - - //get the actual checksum of the artifact -// csums = ChecksumUtils.calc( file, Utils.CHECKSUM_ALGORITHMS ); -// for (Map.Entry csum : csums.entrySet()) { -// Object actualSum = csum.getValue(); -// File sum = new File( localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace( "-", "" ) ); -// assertTrue( sum.exists() ); -// String generatedSum = FileUtils.fileRead( sum, "UTF-8" ); -// assertEquals( actualSum, generatedSum ); -// } File installedArtifact = new File( localPath + "." + packaging ); assertTrue( installedArtifact.exists() ); -// assertEquals( 9, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); assertEquals( 5, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() ); } diff --git a/src/test/java/org/apache/maven/plugins/install/Utils.java b/src/test/java/org/apache/maven/plugins/install/Utils.java deleted file mode 100644 index 33c262c..0000000 --- a/src/test/java/org/apache/maven/plugins/install/Utils.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.apache.maven.plugins.install; - -/* - * 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.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -import org.apache.maven.plugin.MojoExecutionException; -import org.sonatype.aether.util.ChecksumUtils; - -/** - * A utility class to assist testing. - * - * @author Benjamin Bentmann - */ -public class Utils -{ - - public static final List CHECKSUM_ALGORITHMS = Arrays.asList( "MD5", "SHA-1" ); - - /** - * Verifies the checksum files in the local repo for the given file. - * - * @param file The file to verify its checksum with, must not be null. - * @throws MojoExecutionException In case the checksums were incorrect. - * @throws IOException If the files couldn't be read. - */ - public static void verifyChecksum( File file ) - throws MojoExecutionException, IOException - { - Map checksums = ChecksumUtils.calc( file, CHECKSUM_ALGORITHMS ); - for ( Map.Entry entry : checksums.entrySet() ) - { - File cksumFile = new File( file + "." + entry.getKey().toLowerCase().replace( "-", "" ) ); - String actualChecksum = ChecksumUtils.read( cksumFile ); - if ( !actualChecksum.equals( entry.getValue() ) ) - { - throw new MojoExecutionException( "Incorrect " + entry.getKey() + " checksum for file: " + file ); - } - } - } - -}