package org.apache.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.apache.archiva.web.test.parent.AbstractArtifactManagementTest;
import org.testng.annotations.Test;

@Test( groups = { "artifactmanagement" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } )
public class ArtifactManagementTest
	extends AbstractArtifactManagementTest
{

	
	public void testAddArtifactNullValues()
	{
		goToAddArtifactPage();
		clickButtonWithValue( "Submit" );
		assertTextPresent( "Please add a file to upload." );
		assertTextPresent( "Invalid version." );
		assertTextPresent( "You must enter a groupId." );
		assertTextPresent( "You must enter an artifactId." );
		assertTextPresent( "You must enter a version" );
		assertTextPresent( "You must enter a packaging" );
	}
	
	@Test(dependsOnMethods = { "testAddArtifactNullValues" } )
	public void testAddArtifactNoGroupId()
	{
		addArtifact( " " , getArtifactId(), getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() );
		assertTextPresent( "You must enter a groupId." );
	}
	
	@Test(dependsOnMethods = { "testAddArtifactNoGroupId" } )
	public void testAddArtifactNoArtifactId()
	{
		
		addArtifact( getGroupId() , " ", getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() );
		assertTextPresent( "You must enter an artifactId." );
	}
	
	@Test(dependsOnMethods = { "testAddArtifactNoGroupId" } )
	public void testAddArtifactNoVersion()
	{
		addArtifact( getGroupId() , getArtifactId(), " ", getPackaging() , getArtifactFilePath(), getRepositoryId() );
		assertTextPresent( "You must enter a version." );
	}
	
	@Test(dependsOnMethods = { "testAddArtifactNoGroupId" } )
	public void testAddArtifactInvalidVersion()
	{
		addArtifact( getGroupId() , getArtifactId(), "asdf", getPackaging() , getArtifactFilePath(), getRepositoryId() );
		assertTextPresent( "Invalid version." );
	}
	
	@Test(dependsOnMethods = { "testAddArtifactNoGroupId" } )
	public void testAddArtifactNoPackaging()
	{
		addArtifact( getGroupId() , getArtifactId(), getVersion(), " " , getArtifactFilePath(), getRepositoryId() );
		assertTextPresent( "You must enter a packaging." );
	}
	
	@Test(dependsOnMethods = { "testAddArtifactNoGroupId" } )
	public void testAddArtifactNoFilePath()
	{
		addArtifact( getGroupId() , getArtifactId(), getVersion(), getPackaging() , " ", getRepositoryId() );
		assertTextPresent( "Please add a file to upload." );
	}
	
	public void testAddArtifactValidValues()
	{
		addArtifact( getGroupId() , getArtifactId(), getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() );
		assertTextPresent( "Artifact 'test:test:1.0' was successfully deployed to repository 'internal'" );
	}
		
	//MRM-747
	@Test(dependsOnMethods = { "testAddArtifactValidValues" } )
	public void testAddArtifactBlockRedeployments()
	{
            addArtifact( getGroupId() , getArtifactId(), getVersion(), getPackaging() , getArtifactFilePath(), getRepositoryId() );
            assertTextPresent( "Overwriting released artifacts in repository '" + getRepositoryId() + "' is not allowed." );
	}
	
	public void testDeleteArtifact()
	{
		//prep
		String groupId = getProperty( "GROUPID1" );
		String artifactId = getProperty( "ARTIFACTID1" );
		String version = getProperty( "VERSION1" );
		String packaging = getProperty( "PACKAGING1" );
		String repositoryId = getProperty( "REPOSITORYID1" );
		addArtifact( groupId , artifactId, version, packaging , getArtifactFilePath(), repositoryId );
		assertTextPresent( "Artifact 'delete:delete:1.0' was successfully deployed to repository 'internal'" );

		deleteArtifact( "delete", "delete", "1.0", "internal");
		assertTextPresent( "Artifact 'delete:delete:1.0' was successfully deleted from repository 'internal'" );
	}
	
	public void testDeleteArtifactNoGroupId()
	{
		deleteArtifact( " ", "delete", "1.0", "internal");
		assertTextPresent( "You must enter a groupId." );
	}
	
	public void testDeleteArtifactNoArtifactId()
	{
		deleteArtifact( "delete", " ", "1.0", "internal");
		assertTextPresent( "You must enter an artifactId." );
	}
	
	public void testDeleteArtifactNoVersion()
	{
		deleteArtifact( "delete", "delete", " ", "internal");
		assertTextPresent( "Invalid version." );
		assertTextPresent( "You must enter a version." );
	}
	
	public void testDeleteArtifactInvalidVersion()
	{
		deleteArtifact( "delete", "delete", "asdf", "internal");
		assertTextPresent( "Invalid version." );
	}
}

@@ -3230,24 +3230,117 @@
 Values()%0A%09%7B%0A
+%09%09// TODO: disable test on non *chrome browsers, there is no way to do file uploads (SEL-63)%0A
 %09%09addArtifac
@@ -3441,32 +3441,32 @@
 positoryId() );%0A
-
 %09%09assertTextPres
@@ -3681,16 +3681,119 @@
 ts()%0A%09%7B%0A
+            // TODO: disable test on non *chrome browsers, there is no way to do file uploads (SEL-63)%0A
         
@@ -4282,24 +4282,24 @@
 KAGING1%22 );%0A
-
 %09%09String rep
@@ -4342,16 +4342,89 @@
 ID1%22 );%0A
+%09%09// TODO: do this differently as it only works in Firefox's chrome mode%0A
 %09%09addArt

add some notes about tests that won't work in other browsers