MRM-325 Added tests for maven connection to archiva

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@534696 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2007-05-03 02:47:26 +00:00
parent 1ce5fc6f8b
commit 42b4801878
22 changed files with 603 additions and 1 deletions

View File

@ -30,6 +30,11 @@
<packaging>pom</packaging>
<name>Archiva Web :: Application Tests</name>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-command-line</artifactId>
<version>1.0-alpha-2</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>archiva-webapp</artifactId>
@ -42,6 +47,23 @@
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.4</version>
</dependency>
<!-- Dependency for MavenConnectionTest -->
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1</version>
</dependency>
<!-- Dependencies below are provided by the appserver -->
<dependency>
@ -120,6 +142,15 @@
<copy todir="${project.build.directory}/index">
<fileset dir="src/test/resources/index" />
</copy>
<copy todir="${project.build.directory}/snapshots">
<fileset dir="src/test/resources/snapshots" />
</copy>
<copy todir="${project.build.directory}/projects">
<fileset dir="src/test/resources/projects" />
</copy>
<copy todir="${project.build.directory}/local-repo">
<fileset dir="src/test/resources/local-repo" />
</copy>
</tasks>
</configuration>
</execution>

View File

@ -0,0 +1,397 @@
package org.apache.maven.archiva.web.test;
/*
* 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 org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.StreamConsumer;
import org.codehaus.plexus.util.cli.WriterStreamConsumer;
import org.codehaus.plexus.commandline.ExecutableResolver;
import org.codehaus.plexus.commandline.DefaultExecutableResolver;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import java.io.File;
import java.io.Writer;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.List;
import java.util.Collections;
/**
* Test maven connection to archiva
*
* @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
*/
public class MavenConnectionTest
extends AbstractArchivaTestCase
{
public static final String PATH_TO_ARCHIVA_XML = "/target/appserver-base/conf/archiva.xml";
public static final String PATH_TO_SETTINGS_XML = "/target/local-repo/settings.xml";
public static final String NEW_LOCAL_REPO_VALUE = "/target/local-repo";
/**
* @throws Exception
*/
public void setUp()
throws Exception
{
super.setUp();
String newValue = getBasedir() + NEW_LOCAL_REPO_VALUE;
updateXml( new File( getBasedir(), PATH_TO_ARCHIVA_XML ), newValue );
updateXml( new File( getBasedir(), PATH_TO_SETTINGS_XML ), newValue );
}
/**
* Update localRepository element value
*
* @param f
* @param newValue
* @throws Exception
*/
private void updateXml( File f, String newValue )
throws Exception
{
SAXBuilder builder = new SAXBuilder();
FileReader reader = new FileReader( f );
Document document = builder.build( reader );
Element localRepository =
(Element) XPath.newInstance( "./" + "localRepository" ).selectSingleNode( document.getRootElement() );
localRepository.setText( newValue );
// re-write xml file
FileWriter writer = new FileWriter( f );
XMLOutputter output = new XMLOutputter();
output.output( document, writer );
}
private void clickManagedRepositories()
{
goToLoginPage();
submitLoginPage( adminUsername, adminPassword );
clickLinkWithText( "Managed Repositories" );
assertPage( "Administration" );
assertTextPresent( "Administration" );
}
private void removeManagedRepository( String id )
{
clickManagedRepositories();
clickLinkWithLocator( "//a[contains(@href, '/admin/deleteRepository!input.action?repoId=" + id + "')]" );
clickLinkWithLocator( "deleteRepository_operationdelete-contents", false );
clickButtonWithValue( "Go" );
assertPage( "Administration" );
}
/**
* Click Settings from the navigation menu
*/
private void clickProxiedRepositories()
{
goToLoginPage();
submitLoginPage( adminUsername, adminPassword );
clickLinkWithText( "Proxied Repositories" );
assertPage( "Administration" );
assertTextPresent( "Proxied Repositories" );
}
/**
* Remove the created test repo
*/
protected void removeProxiedRepository()
{
if ( !isLinkPresent( "Login" ) )
{
logout();
}
clickProxiedRepositories();
if ( isTextPresent( "Delete Repository " ) )
{
clickLinkWithText( "Delete Repository" );
assertPage( "Configuration" );
clickLinkWithLocator( "deleteProxiedRepository_operationdelete-entry", false );
clickButtonWithValue( "Go" );
assertPage( "Administration" );
assertTextNotPresent( "Test Proxied Repository" );
}
logout();
}
/**
* Execute 'mvn' from commandline
*
* @param workingDir
* @param outputFile
* @return
* @throws Exception
*/
private int executeMaven( String workingDir, File outputFile )
throws Exception
{
ExecutableResolver executableResolver = new DefaultExecutableResolver();
String actualExecutable = "mvn";
File workingDirectory = new File( workingDir );
List path = executableResolver.getDefaultPath();
if ( path == null )
{
path = Collections.EMPTY_LIST;
}
File e = executableResolver.findExecutable( "mvn", path );
if ( e != null )
{
actualExecutable = e.getAbsolutePath();
}
File actualExecutableFile = new File( actualExecutable );
if ( !actualExecutableFile.exists() )
{
actualExecutable = "mvn";
}
// Set command line
Commandline cmd = new Commandline();
cmd.addSystemEnvironment();
cmd.addEnvironment( "MAVEN_TERMINATE_CMD", "on" );
cmd.setExecutable( actualExecutable );
cmd.setWorkingDirectory( workingDirectory.getAbsolutePath() );
cmd.createArgument().setValue( "clean" );
cmd.createArgument().setValue( "install" );
cmd.createArgument().setValue( "-s" );
cmd.createArgument().setValue( getBasedir() + "/target/local-repo/settings.xml" );
// Excute command
Writer writer = new FileWriter( outputFile );
StreamConsumer consumer = new WriterStreamConsumer( writer );
int exitCode = CommandLineUtils.executeCommandLine( cmd, consumer, consumer );
writer.flush();
writer.close();
return exitCode;
}
public void testBadDependency()
throws Exception
{
File outputFile = new File( getBasedir(), "/target/projects/bad-dependency/bad-dependency.log" );
int exitCode = executeMaven( getBasedir() + "/target/projects/bad-dependency", outputFile );
assertEquals( 1, exitCode );
File f = new File( getBasedir(),
"/target/local-repo/org/apache/mavem/archiva/web/test/foo-bar/1.0-SNAPSHOT/foo-bar-1.0-SNAPSHOT.jar" );
assertTrue( !f.exists() );
BufferedReader reader = new BufferedReader( new FileReader( outputFile ) );
String str;
boolean foundSnapshot = false, foundBadDep = false;
while ( ( str = reader.readLine() ) != null )
{
//System.out.println( str );
if ( str.indexOf(
"mvn install:install-file -DgroupId=org.apache.maven.archiva.web.test -DartifactId=foo-bar" ) != -1 )
{
foundSnapshot = true;
}
else if ( str.indexOf(
"mvn install:install-file -DgroupId=org.apache.maven.archiva.web.test -DartifactId=bad-dependency" ) !=
-1 )
{
foundBadDep = true;
}
}
reader.close();
assertTrue( foundSnapshot );
assertTrue( foundBadDep );
}
/*
@todo: commented out since tests are currently failing due to MRM-323
public void testDownloadArtifactFromManagedRepo()
throws Exception
{
clickManagedRepositories();
clickLinkWithText( "Add Repository" );
assertTextPresent( "Configuration" );
setFieldValue( "addRepository_id", "snapshots" );
setFieldValue( "urlName", "snapshots" );
setFieldValue( "addRepository_name", "snapshots-repository" );
setFieldValue( "addRepository_directory", getBasedir() + "/target/snapshots" );
clickButtonWithValue( "Add Repository" );
assertPage( "Administration" );
clickLinkWithText( "User Management" );
clickLinkWithLocator( "//a[contains(@href, '/security/useredit.action?username=admin')]" );
clickLinkWithText( "Edit Roles" );
checkField( "addRolesToUser_addSelectedRolesRepository Observer - snapshots" );
checkField( "addRolesToUser_addSelectedRolesRepository Manager - snapshots" );
clickButtonWithValue( "Add Selected Roles" );
assertPage( "[Admin] User List" );
logout();
File outputFile = new File( getBasedir(), "/target/projects/bad-dependency/bad-dependency2.log" );
int exitCode = executeMaven( getBasedir() + "/target/projects/bad-dependency",
outputFile );
assertEquals( 0, exitCode );
File f = new File( getBasedir(),
"/target/local-repo/org/apache/maven/archiva/web/test/foo-bar-1.0-SNAPSHOT.jar" );
assertTrue( f.exists() );
BufferedReader reader = new BufferedReader( new FileReader( outputFile ) );
String str;
while( ( str = reader.readLine() ) != null)
{
System.out.println( str );
}
reader.close();
removeManagedRepository( "snapshots" );
}
public void testDownloadArtifactFromProxiedRepo()
throws Exception
{
//add managed repository
clickManagedRepositories();
clickLinkWithText( "Add Repository" );
assertTextPresent( "Configuration" );
setFieldValue( "addRepository_id", "repository" );
setFieldValue( "urlName", "repository" );
setFieldValue( "addRepository_name", "repository" );
setFieldValue( "addRepository_directory", getBasedir() + "/target/repository" );
clickButtonWithValue( "Add Repository" );
waitPage();
assertPage( "Administration" );
clickLinkWithText( "User Management" );
clickLinkWithLocator( "//a[contains(@href, '/security/useredit.action?username=admin')]" );
clickLinkWithText( "Edit Roles" );
checkField( "addRolesToUser_addSelectedRolesRepository Observer - repository" );
checkField( "addRolesToUser_addSelectedRolesRepository Manager - repository" );
clickButtonWithValue( "Add Selected Roles" );
assertPage( "[Admin] User List" );
logout();
//add proxied repository
clickProxiedRepositories();
clickLinkWithText( "Add Repository" );
assertPage( "Configuration" );
setFieldValue( "id", "central" );
setFieldValue( "name", "Central Repository" );
setFieldValue( "url", "http://mirrors.ibiblio.org/pub/mirrors/maven2" );
clickButtonWithValue( "Add Repository" );
waitPage();
assertPage( "Administration" );
assertTextPresent( "Central Repository" );
assertLinkPresent( "Edit Repository" );
logout();
File outputFile = new File( getBasedir(), "/target/projects/dependency-in-proxied/dependency-in-proxied.log" );
int exitCode = executeMaven( getBasedir() + "/target/projects/dependency-in-proxied",
outputFile );
assertEquals( 0, exitCode );
File f = new File( getBasedir(),"/target/repository/com/lowagie/itext/1.3/itext-1.3.jar" );
assertTrue( f.exists() );
f = new File( getBasedir(), "/target/local-repo/com/lowagie/itext/1.3/itext-1.3.jar" );
assertTrue( f.exists() );
BufferedReader reader = new BufferedReader( new FileReader( outputFile ) );
String str;
while( ( str = reader.readLine() ) != null)
{
System.out.println( str );
}
reader.close();
removeProxiedRepository();
removeManagedRepository( "repository" );
}
*/
/**
* @throws Exception
*/
public void tearDown()
throws Exception
{
super.tearDown();
}
}

View File

@ -1 +1,3 @@
<configuration />
<configuration>
<localRepository></localRepository>
</configuration>

View File

@ -0,0 +1,44 @@
<settings>
<localRepository></localRepository>
<servers>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin1</password>
</server>
</servers>
<profiles>
<profile>
<id>repositories</id>
<repositories>
<repository>
<id>snapshots</id>
<name>snapshots-repository</name>
<url>http://localhost:9696/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<name>snapshots-repository</name>
<url>http://localhost:9696/archiva/repository/snapshot/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>repositories</activeProfile>
</activeProfiles>
</settings>

View File

@ -0,0 +1,41 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>bad-dependency</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Bad Dependency</name>
<dependencies>
<dependency>
<groupId>org.apache.maven.archiva.web.test</groupId>
<artifactId>bad-dependency</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.archiva.web.test</groupId>
<artifactId>foo-bar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,41 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.archiva</groupId>
<artifactId>dependency-in-proxied</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Dependency In Proxied</name>
<dependencies>
<!--dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-jxr</artifactId>
<version>2.1</version>
</dependency-->
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,7 @@
#Last Scan Information, managed by Archiva. DO NOT EDIT
#Thu Apr 19 17:04:36 PHT 2007
scan.included.files=12
scan.skipped.files=0
scan.finished.timestamp=1176973476967
scan.consumed.files=20
scan.started.timestamp=1176973467414

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.archiva.web.test</groupId>
<artifactId>foo-bar</artifactId>
<version>1.0-SNAPSHOT</version>
<distributionManagement>
<status>deployed</status>
</distributionManagement>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.apache.maven.archiva.web.test</groupId>
<artifactId>foo-bar</artifactId>
<version>1.0-SNAPSHOT</version>
<versioning>
<snapshot>
<buildNumber>1</buildNumber>
</snapshot>
<lastUpdated>20070425105840</lastUpdated>
</versioning>
</metadata>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.apache.maven.archiva.web.test</groupId>
<artifactId>foo-bar</artifactId>
<version>1.0-SNAPSHOT</version>
<versioning>
<versions>
<version>1.0-SNAPSHOT</version>
</versions>
<lastUpdated>20070425105840</lastUpdated>
</versioning>
</metadata>