[MNG-2477] add tests for the checksum requirements shown in the proposal - disabled. Implementing is incredibly difficult with the project <-> artifact coupling in place today


git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/branches/MNG-2477@682775 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng2477RepositorySecurityTest.java b/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng2477RepositorySecurityTest.java
index 294bd9e..ec02751 100644
--- a/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng2477RepositorySecurityTest.java
+++ b/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng2477RepositorySecurityTest.java
@@ -20,48 +20,112 @@
 package org.apache.maven.integrationtests;
 
 import java.io.File;
-import java.util.Collections;
+import java.io.IOException;
 
 import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.it.VerificationException;
 import org.apache.maven.it.Verifier;
 import org.apache.maven.it.util.FileUtils;
 import org.apache.maven.it.util.ResourceExtractor;
 
 /**
- * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3052">MNG-3052</a>. When a project dependency
- * declares its own repositories, they should be used to resolve that dependency's dependencies. This includes both
- * steps: determining the dependency artifact information (version, etc.) AND resolving the actual artifact itself.
- * NOTE: The SNAPSHOT versions are CRITICAL in this test, since they force the correct resolution of artifact metadata,
- * which depends on having the correct set of repositories present.
- * 
- * @author jdcasey
+ * This is a test set for the repository security features.
  */
 public class MavenITmng2477RepositorySecurityTest
     extends AbstractMavenIntegrationTestCase
 {
+    private File mainTestDir;
+
     public MavenITmng2477RepositorySecurityTest()
         throws InvalidVersionSpecificationException
     {
         super( "(2.0.100,)" ); // only test in 2.1+
     }
 
+    public void setUp()
+        throws IOException
+    {
+        mainTestDir =
+            ResourceExtractor.simpleExtractResources( getClass(), "/mng-2477-repository-security" ).getCanonicalFile();
+    }
+
+    /* Checksum tests are not yet implemented
+    public void testitMNG2477RequiredChecksums()
+        throws IOException, VerificationException
+    {
+        File testDir = new File( mainTestDir, "test-checksum" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+
+        verifier.executeGoal( "compile" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        verifier.assertArtifactPresent( "junit", "junit", "3.8.1", "pom" );
+        verifier.assertArtifactPresent( "junit", "junit", "3.8.1", "jar" );
+
+        verifier.assertArtifactPresent( "commons-logging", "commons-logging-api", "1.1", "pom" );
+        verifier.assertArtifactPresent( "commons-logging", "commons-logging-api", "1.1", "jar" );
+    }
+
+    public void testitMNG2477RequiredChecksumFail()
+        throws IOException, VerificationException
+    {
+        File testDir = new File( mainTestDir, "test-bad-checksum" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+
+        try
+        {
+            verifier.executeGoal( "compile" );
+            fail( "Execution should not succeed with an invalid checksum" );
+        }
+        catch ( VerificationException e )
+        {
+            // expected
+        }
+        finally
+        {
+            verifier.resetStreams();
+        }
+    }
+
+    public void testitMNG2477RequiredChecksumPomFail()
+        throws IOException, VerificationException
+    {
+        File testDir = new File( mainTestDir, "test-bad-pom-checksum" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+
+        try
+        {
+            verifier.executeGoal( "compile" );
+            fail( "Execution should not succeed with an invalid checksum" );
+        }
+        catch ( VerificationException e )
+        {
+            // expected
+        }
+        finally
+        {
+            verifier.resetStreams();
+        }
+    }*/
+
     public void testitMNG2477DeploymentPOMIsConvertedToModelv400()
         throws Exception
     {
-        File testDir =
-            ResourceExtractor.simpleExtractResources( getClass(), "/mng-2477-repository-security" ).getCanonicalFile();
+        File testDir = new File( mainTestDir, "test-deployment" );
 
         File repository = new File( testDir, "deployment-repository" );
         FileUtils.deleteDirectory( repository );
 
-        File file = new File( repository, "org/apache/maven/its/mng2477/test-project/1.0/test-project-1.0.pom" );
+        File file = new File( repository, "org/apache/maven/its/mng2477/test-deployment/1.0/test-deployment-1.0.pom" );
         assertFalse( file.exists() );
 
         Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        verifier.deleteArtifact( "org.apache.maven.its.mng2477", "test-project", "1.0", "pom" );
-        
-        verifier.setCliOptions( Collections.singletonList( "-X" ) );
-        
+        verifier.deleteArtifact( "org.apache.maven.its.mng2477", "test-deployment", "1.0", "pom" );
+
         verifier.executeGoal( "deploy" );
         verifier.verifyErrorFreeLog();
         verifier.resetStreams();
@@ -71,7 +135,7 @@
         // TODO: would be better to read it back as a model
         String contents = FileUtils.fileRead( file );
         assertFalse( contents.indexOf( "signaturePolicy" ) >= 0 );
-        // not implementeed yet
-        // assertTrue( contents.indexOf( "requiredChecksum value=\"99129f16442844f6a4a11ae22fbbee40b14d774f\" pom=\"16d74791c801c89b0071b1680ea0bc85c93417bb\"" ) >= 0 );
+        // not implemented yet
+//        assertTrue( contents.indexOf( "requiredChecksum value=\"99129f16442844f6a4a11ae22fbbee40b14d774f\" pom=\"16d74791c801c89b0071b1680ea0bc85c93417bb\"" ) >= 0 );
     }
 }
diff --git a/core-integration-tests/src/test/resources/mng-2477-repository-security/test-bad-checksum/pom.xml b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-bad-checksum/pom.xml
new file mode 100644
index 0000000..65a57aa
--- /dev/null
+++ b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-bad-checksum/pom.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.its.mng2477</groupId>
+  <version>1.0</version>
+  <artifactId>test-bad-checksum</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+      <requiredChecksum value="16d74791c801c89b0071b1680ea0bc85c93417bb" />
+    </dependency>
+  </dependencies>
+</project>
+
diff --git a/core-integration-tests/src/test/resources/mng-2477-repository-security/test-bad-pom-checksum/pom.xml b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-bad-pom-checksum/pom.xml
new file mode 100644
index 0000000..996d312
--- /dev/null
+++ b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-bad-pom-checksum/pom.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.its.mng2477</groupId>
+  <version>1.0</version>
+  <artifactId>test-bad-pom-checksum</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+      <requiredChecksum value="99129f16442844f6a4a11ae22fbbee40b14d774f" pom="99129f16442844f6a4a11ae22fbbee40b14d774f" />
+    </dependency>
+  </dependencies>
+</project>
+
diff --git a/core-integration-tests/src/test/resources/mng-2477-repository-security/test-checksum/pom.xml b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-checksum/pom.xml
new file mode 100644
index 0000000..543433f
--- /dev/null
+++ b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-checksum/pom.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?><project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.its.mng2477</groupId>
+  <version>1.0</version>
+  <artifactId>test-checksum</artifactId>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+      <requiredChecksum value="99129f16442844f6a4a11ae22fbbee40b14d774f" pom="16d74791c801c89b0071b1680ea0bc85c93417bb" />
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging-api</artifactId>
+      <version>1.1</version>
+      <requiredChecksum value="7d4cf5231d46c8524f9b9ed75bb2d1c69ab93322" />
+    </dependency>
+  </dependencies>
+</project>
+
diff --git a/core-integration-tests/src/test/resources/mng-2477-repository-security/pom.xml b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-deployment/pom.xml
similarity index 90%
rename from core-integration-tests/src/test/resources/mng-2477-repository-security/pom.xml
rename to core-integration-tests/src/test/resources/mng-2477-repository-security/test-deployment/pom.xml
index 4e48e63..c23fb4c 100644
--- a/core-integration-tests/src/test/resources/mng-2477-repository-security/pom.xml
+++ b/core-integration-tests/src/test/resources/mng-2477-repository-security/test-deployment/pom.xml
@@ -2,15 +2,15 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.maven.its.mng2477</groupId>
   <version>1.0</version>
-  <artifactId>test-project</artifactId>
-  <name>test-project</name>
+  <artifactId>test-deployment</artifactId>
+  <name>test-deployment</name>
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
-<!-- later
+<!-- TODO: not implemented
       <requiredChecksum value="99129f16442844f6a4a11ae22fbbee40b14d774f" pom="16d74791c801c89b0071b1680ea0bc85c93417bb" />
 -->
     </dependency>