1 package org.apache.archiva.web.test;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
23 import java.io.Writer;
24 import java.io.FileWriter;
25 import java.io.FileReader;
26 import java.io.BufferedReader;
27 import java.util.List;
28 import java.util.Collections;
30 import org.apache.archiva.web.test.parent.AbstractArchivaTest;
31 import org.testng.Assert;
32 import org.testng.annotations.AfterTest;
33 import org.testng.annotations.BeforeSuite;
34 import org.testng.annotations.BeforeTest;
35 import org.testng.annotations.Test;
36 import org.jdom.Document;
37 import org.jdom.Element;
38 import org.jdom.input.SAXBuilder;
39 import org.jdom.output.XMLOutputter;
40 import org.jdom.xpath.XPath;
41 import org.codehaus.plexus.commandline.ExecutableResolver;
42 import org.codehaus.plexus.commandline.DefaultExecutableResolver;
43 import org.codehaus.plexus.util.cli.CommandLineUtils;
44 import org.codehaus.plexus.util.cli.Commandline;
45 import org.codehaus.plexus.util.cli.StreamConsumer;
46 import org.codehaus.plexus.util.cli.WriterStreamConsumer;
48 @Test( groups = { "about" }, alwaysRun = true )
49 public class ArchivaAdminTest
50 extends AbstractArchivaTest
52 public static final String PATH_TO_ARCHIVA_XML = "/target/appserver-base/conf/archiva.xml";
54 public static final String PATH_TO_SETTINGS_XML = "/target/local-repo/settings.xml";
56 public static final String NEW_LOCAL_REPO_VALUE = "/target/local-repo";
59 public void initializeArchiva()
63 getSelenium().open( baseUrl );
64 String title = getSelenium().getTitle();
65 if ( title.equals( "Apache Archiva \\ Create Admin User" ) )
68 String fullname = p.getProperty( "ADMIN_FULLNAME" );
69 String username = p.getProperty( "ADMIN_USERNAME" );
70 String mail = p.getProperty( "ADMIN_EMAIL" );
71 String password = p.getProperty( "ADMIN_PASSWORD" );
72 submitAdminData( fullname, mail, password );
73 assertAuthenticatedPage( username );
75 clickLinkWithText( "Logout" );
80 @BeforeTest( groups = { "about" } )
85 String newValue = getBasedir() + NEW_LOCAL_REPO_VALUE;
86 updateXml( new File( getBasedir(), PATH_TO_ARCHIVA_XML ), newValue );
87 updateXml( new File( getBasedir(), PATH_TO_SETTINGS_XML ), newValue );
91 * Update localRepository element value
97 private void updateXml( File f, String newValue )
100 SAXBuilder builder = new SAXBuilder();
101 FileReader reader = new FileReader( f );
102 Document document = builder.build( reader );
104 Element localRepository =
105 (Element) XPath.newInstance( "./" + "localRepository" ).selectSingleNode( document.getRootElement() );
106 localRepository.setText( newValue );
109 FileWriter writer = new FileWriter( f );
110 XMLOutputter output = new XMLOutputter();
111 output.output( document, writer );
114 /*private void clickRepositories()
117 submitLoginPage( getAdminUsername() , getAdminPassword() );
118 clickLinkWithText( "Repositories" );
119 assertPage( "Apache Archiva \\ Administration" );
120 assertTextPresent( "Administration - Repositories" );
123 private void removedManagedRepository( String id)
126 clickLinkWithLocator( "//a[contains(@href, '/admin/confirmDeleteRepository.action?repoid=" + id + "')]" );
127 clickButtonWithValue( "Delete Configuration and Contents" );
130 private int executeMaven( String workingDir, File outputFile )
134 ExecutableResolver executableResolver = new DefaultExecutableResolver();
136 String actualExecutable = "mvn";
137 File workingDirectory = new File( workingDir );
139 List path = executableResolver.getDefaultPath();
143 path = Collections.EMPTY_LIST;
146 File e = executableResolver.findExecutable( "mvn", path );
150 actualExecutable = e.getAbsolutePath();
153 File actualExecutableFile = new File( actualExecutable );
155 if ( !actualExecutableFile.exists() )
157 actualExecutable = "mvn";
161 Commandline cmd = new Commandline();
163 cmd.addSystemEnvironment();
165 cmd.addEnvironment( "MAVEN_TERMINATE_CMD", "on" );
167 cmd.setExecutable( actualExecutable );
169 cmd.setWorkingDirectory( workingDirectory.getAbsolutePath() );
171 cmd.createArgument().setValue( "clean" );
173 cmd.createArgument().setValue( "install" );
175 cmd.createArgument().setValue( "-s" );
177 cmd.createArgument().setValue( getBasedir() + "/target/local-repo/settings.xml" );
181 Writer writer = new FileWriter( outputFile );
183 StreamConsumer consumer = new WriterStreamConsumer( writer );
185 int exitCode = CommandLineUtils.executeCommandLine( cmd, consumer, consumer );
194 /* public void testBadDependency()
197 File outputFile = new File( getBasedir(), "/target/projects/bad-dependency/bad-dependency.log" );
198 int exitCode = executeMaven( getBasedir() + "/target/projects/bad-dependency", outputFile );
200 Assert.assertEquals( 1, exitCode );
202 File f = new File( getBasedir(),
203 "/target/local-repo/org/apache/maven/archiva/web/test/foo-bar/1.0-SNAPSHOT/foo-bar-1.0-SNAPSHOT.jar" );
204 Assert.assertTrue( !f.exists() );
206 BufferedReader reader = new BufferedReader( new FileReader( outputFile ) );
208 boolean foundSnapshot = false, foundBadDep = false;
210 while ( ( str = reader.readLine() ) != null )
212 //System.out.println( str );
214 "mvn install:install-file -DgroupId=org.apache.maven.archiva.web.test -DartifactId=foo-bar" ) != -1 )
216 foundSnapshot = true;
218 else if ( str.indexOf(
219 "mvn install:install-file -DgroupId=org.apache.maven.archiva.web.test -DartifactId=bad-dependency" ) !=
228 Assert.assertTrue( foundSnapshot );
229 Assert.assertTrue( foundBadDep );
232 public void displayLandingPage()
234 getSelenium().open( baseUrl );
235 getSelenium().waitForPageToLoad( maxWaitTimeInMs );
236 assertPage( "Apache Archiva \\ Quick Search" );
240 @AfterTest( groups = { "about" } )