mirror of https://github.com/apache/maven.git
o Strengthened IT to monitor actual repository access
git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@953402 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fbc935e05c
commit
7be4a13465
|
@ -23,6 +23,21 @@ import org.apache.maven.it.Verifier;
|
||||||
import org.apache.maven.it.util.ResourceExtractor;
|
import org.apache.maven.it.util.ResourceExtractor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.mortbay.jetty.Handler;
|
||||||
|
import org.mortbay.jetty.Request;
|
||||||
|
import org.mortbay.jetty.Server;
|
||||||
|
import org.mortbay.jetty.handler.AbstractHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-768">MNG-768</a>.
|
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-768">MNG-768</a>.
|
||||||
|
@ -33,6 +48,7 @@ import java.io.File;
|
||||||
public class MavenITmng0768OfflineModeTest
|
public class MavenITmng0768OfflineModeTest
|
||||||
extends AbstractMavenIntegrationTestCase
|
extends AbstractMavenIntegrationTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public MavenITmng0768OfflineModeTest()
|
public MavenITmng0768OfflineModeTest()
|
||||||
{
|
{
|
||||||
super( ALL_MAVEN_VERSIONS );
|
super( ALL_MAVEN_VERSIONS );
|
||||||
|
@ -46,58 +62,116 @@ public class MavenITmng0768OfflineModeTest
|
||||||
{
|
{
|
||||||
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0768" );
|
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-0768" );
|
||||||
|
|
||||||
{
|
final List requestedUris = Collections.synchronizedList( new ArrayList() );
|
||||||
// phase 1: run build in online mode to fill local repo
|
|
||||||
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
|
||||||
verifier.setAutoclean( false );
|
|
||||||
verifier.deleteDirectory( "target" );
|
|
||||||
verifier.deleteArtifacts( "org.apache.maven.its.it0069" );
|
|
||||||
verifier.setLogFileName( "log1.txt" );
|
|
||||||
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
|
|
||||||
verifier.getCliOptions().add( "--settings" );
|
|
||||||
verifier.getCliOptions().add( "settings.xml" );
|
|
||||||
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
|
|
||||||
verifier.assertFilePresent( "target/compile.txt" );
|
|
||||||
verifier.verifyErrorFreeLog();
|
|
||||||
verifier.resetStreams();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Handler repoHandler = new AbstractHandler()
|
||||||
{
|
{
|
||||||
// phase 2: run build in offline mode to check it still passes
|
public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
|
||||||
// NOTE: We don't add the settings here to ensure Maven has no chance to access the required remote repo
|
throws IOException, ServletException
|
||||||
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
|
||||||
verifier.setAutoclean( false );
|
|
||||||
verifier.deleteDirectory( "target" );
|
|
||||||
verifier.getCliOptions().add( "-o" );
|
|
||||||
verifier.setLogFileName( "log2.txt" );
|
|
||||||
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
|
|
||||||
verifier.assertFilePresent( "target/compile.txt" );
|
|
||||||
verifier.verifyErrorFreeLog();
|
|
||||||
verifier.resetStreams();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// phase 3: delete test artifact and run build in offline mode to check it fails now
|
|
||||||
// NOTE: We add the settings again to offer Maven the bad choice of using the remote repo
|
|
||||||
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
|
||||||
verifier.setAutoclean( false );
|
|
||||||
verifier.deleteDirectory( "target" );
|
|
||||||
verifier.deleteArtifacts( "org.apache.maven.its.it0069" );
|
|
||||||
verifier.getCliOptions().add( "-o" );
|
|
||||||
verifier.getCliOptions().add( "--settings" );
|
|
||||||
verifier.getCliOptions().add( "settings.xml" );
|
|
||||||
verifier.setLogFileName( "log3.txt" );
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
|
System.out.println( "Handling " + request.getMethod() + " " + request.getRequestURL() );
|
||||||
|
|
||||||
|
requestedUris.add( request.getRequestURI() );
|
||||||
|
|
||||||
|
PrintWriter writer = response.getWriter();
|
||||||
|
|
||||||
|
response.setStatus( HttpServletResponse.SC_OK );
|
||||||
|
|
||||||
|
if ( request.getRequestURI().endsWith( ".pom" ) )
|
||||||
|
{
|
||||||
|
writer.println( "<project>" );
|
||||||
|
writer.println( " <modelVersion>4.0.0</modelVersion>" );
|
||||||
|
writer.println( " <groupId>org.apache.maven.its.mng0768</groupId>" );
|
||||||
|
writer.println( " <artifactId>dep</artifactId>" );
|
||||||
|
writer.println( " <version>0.1</version>" );
|
||||||
|
writer.println( "</project>" );
|
||||||
|
}
|
||||||
|
else if ( request.getRequestURI().endsWith( ".jar" ) )
|
||||||
|
{
|
||||||
|
writer.println( "empty" );
|
||||||
|
}
|
||||||
|
else if ( request.getRequestURI().endsWith( ".md5" ) || request.getRequestURI().endsWith( ".sha1" ) )
|
||||||
|
{
|
||||||
|
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
|
||||||
|
}
|
||||||
|
|
||||||
|
( (Request) request ).setHandled( true );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Server server = new Server( 0 );
|
||||||
|
server.setHandler( repoHandler );
|
||||||
|
server.start();
|
||||||
|
int port = server.getConnectors()[0].getLocalPort();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
{
|
||||||
|
// phase 1: run build in online mode to fill local repo
|
||||||
|
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
||||||
|
verifier.setAutoclean( false );
|
||||||
|
verifier.deleteDirectory( "target" );
|
||||||
|
verifier.deleteArtifacts( "org.apache.maven.its.mng0768" );
|
||||||
|
verifier.setLogFileName( "log1.txt" );
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.put( "@port@", Integer.toString( port ) );
|
||||||
|
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", props );
|
||||||
|
verifier.getCliOptions().add( "--settings" );
|
||||||
|
verifier.getCliOptions().add( "settings.xml" );
|
||||||
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
|
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
|
||||||
|
verifier.assertFilePresent( "target/compile.txt" );
|
||||||
verifier.verifyErrorFreeLog();
|
verifier.verifyErrorFreeLog();
|
||||||
fail( "Build did not fail to resolve missing dependency although Maven ought to work offline!" );
|
verifier.resetStreams();
|
||||||
}
|
}
|
||||||
catch( VerificationException e )
|
|
||||||
|
requestedUris.clear();
|
||||||
|
|
||||||
{
|
{
|
||||||
// expected, should fail
|
// phase 2: run build in offline mode to check it still passes, without network accesses
|
||||||
|
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
||||||
|
verifier.setAutoclean( false );
|
||||||
|
verifier.deleteDirectory( "target" );
|
||||||
|
verifier.getCliOptions().add( "-o" );
|
||||||
|
verifier.getCliOptions().add( "--settings" );
|
||||||
|
verifier.getCliOptions().add( "settings.xml" );
|
||||||
|
verifier.setLogFileName( "log2.txt" );
|
||||||
|
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
|
||||||
|
verifier.assertFilePresent( "target/compile.txt" );
|
||||||
|
verifier.verifyErrorFreeLog();
|
||||||
|
verifier.resetStreams();
|
||||||
}
|
}
|
||||||
verifier.resetStreams();
|
|
||||||
|
assertTrue( requestedUris.toString(), requestedUris.isEmpty() );
|
||||||
|
|
||||||
|
{
|
||||||
|
// phase 3: delete test artifact and run build in offline mode to check it fails now
|
||||||
|
// NOTE: Adding the settings again to offer Maven the bad choice of using the remote repo
|
||||||
|
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
|
||||||
|
verifier.setAutoclean( false );
|
||||||
|
verifier.deleteDirectory( "target" );
|
||||||
|
verifier.deleteArtifacts( "org.apache.maven.its.mng0768" );
|
||||||
|
verifier.getCliOptions().add( "-o" );
|
||||||
|
verifier.getCliOptions().add( "--settings" );
|
||||||
|
verifier.getCliOptions().add( "settings.xml" );
|
||||||
|
verifier.setLogFileName( "log3.txt" );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
verifier.executeGoal( "org.apache.maven.its.plugins:maven-it-plugin-dependency-resolution:2.1-SNAPSHOT:compile" );
|
||||||
|
verifier.verifyErrorFreeLog();
|
||||||
|
fail( "Build did not fail to resolve missing dependency although Maven ought to work offline!" );
|
||||||
|
}
|
||||||
|
catch( VerificationException e )
|
||||||
|
{
|
||||||
|
// expected, should fail
|
||||||
|
}
|
||||||
|
verifier.resetStreams();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue( requestedUris.toString(), requestedUris.isEmpty() );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
server.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ under the License.
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven.its.it0069</groupId>
|
<groupId>org.apache.maven.its.mng0768</groupId>
|
||||||
<artifactId>it</artifactId>
|
<artifactId>dep</artifactId>
|
||||||
<version>1.0.3</version>
|
<version>0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -1,36 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>org.apache.maven.its.it0069</groupId>
|
|
||||||
<artifactId>it</artifactId>
|
|
||||||
<version>1.0.3</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<repository>
|
|
||||||
<id>it0069</id>
|
|
||||||
<url>file:///${basedir}/repo</url>
|
|
||||||
</repository>
|
|
||||||
</distributionManagement>
|
|
||||||
</project>
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><metadata>
|
|
||||||
<groupId>org.apache.maven.its.it0069</groupId>
|
|
||||||
<artifactId>it</artifactId>
|
|
||||||
<version>1.0.3</version>
|
|
||||||
<versioning>
|
|
||||||
<versions>
|
|
||||||
<version>1.0.3</version>
|
|
||||||
</versions>
|
|
||||||
<lastUpdated>20080930194953</lastUpdated>
|
|
||||||
</versioning>
|
|
||||||
</metadata>
|
|
|
@ -26,7 +26,7 @@ under the License.
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>maven-core-it</id>
|
<id>maven-core-it</id>
|
||||||
<url>@baseurl@/repo</url>
|
<url>http://localhost:@port@/</url>
|
||||||
<releases>
|
<releases>
|
||||||
<checksumPolicy>ignore</checksumPolicy>
|
<checksumPolicy>ignore</checksumPolicy>
|
||||||
</releases>
|
</releases>
|
||||||
|
|
Loading…
Reference in New Issue