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.AbstractSearchTest;
import org.testng.annotations.Test;

@Test( groups = { "search" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } )
public class SearchTest 
	extends AbstractSearchTest
{
	
	public void testSearchNonExistingArtifact()
		throws Exception
	{
		searchForArtifact( getProperty( "SEARCH_BAD_ARTIFACT" ) );
		assertTextPresent( "No results found" );
	}
    
	@Test (dependsOnMethods = { "testAddArtifactValidValues" } )
	public void testSearchExistingArtifact()
	{
		searchForArtifact( getProperty( "ARTIFACT_ARTIFACTID" ) );
		assertTextPresent( "Results" );
		assertTextPresent( "Hits: 1 to 1 of 1" );
		assertLinkPresent( "test" );
	}
	
	@Test (dependsOnMethods = { "testAddArtifactValidValues" } )
	public void testViewSearchedArtifact()
    {
		searchForArtifact( getProperty( "ARTIFACT_ARTIFACTID" ) );
		clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) );
		assertPage( "Apache Archiva \\ Browse Repository" );
		assertTextPresent( getProperty( "ARTIFACT_ARTIFACTID" ) );
		clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/"  );
		assertPage( "Apache Archiva \\ Browse Repository" );
    }
	
	public void testSearchNonExistingArtifactInAdvancedSearch()
    {
        searchForArtifactAdvancedSearch( null, getProperty( "SEARCH_BAD_ARTIFACT"), null, null, null, null );
        assertTextPresent( "No results found" );
    }

    public void testSearchNoSearchCriteriaSpecifiedInAdvancedSearch()
    {
        searchForArtifactAdvancedSearch( null, null, null, null, null, null );
        assertTextPresent( "Advanced Search - At least one search criteria must be provided." );
    }

   /* public void testSearchExistingArtifactUsingAdvancedSearchArtifactId()
    {
        searchForArtifactAdvancedSearch( null, getProperty( "ARTIFACT_ARTIFACTID" ), null, null, null, null );
		assertTextPresent( "Results" );
		assertTextPresent( "Hits: 1 to 1 of 1" );
		assertLinkPresent( "test" );   
    }*/
}


@@ -2515,18 +2515,81 @@
   %7D%0A%0A   
-/*
+ @Test (dependsOnMethods = %7B %22testAddArtifactValidValues%22 %7D )%0A   
  public 
@@ -2740,36 +2740,61 @@
 ACTID%22 ), null, 
-null
+getProperty( %22REPOSITORYID%22 )
 , null, null );%0A
@@ -2910,14 +2910,927 @@
   %0A    %7D
-*/
+%0A    %0A    @Test (dependsOnMethods = %7B %22testAddArtifactValidValues%22 %7D )%0A    public void testSearchExistingArtifactUsingAdvancedSearchGroupId()%0A    %7B%0A        searchForArtifactAdvancedSearch( getProperty( %22GROUPID%22 ), null, null, getProperty( %22REPOSITORYID%22 ), null, null );%0A        assertTextPresent( %22Results%22 );%0A        assertTextPresent( %22Hits: 1 to 1 of 1%22 );%0A        assertLinkPresent( %22test%22 );   %0A    %7D%0A    %0A    @Test (dependsOnMethods = %7B %22testAddManagedRepoValidValues%22, %22testAddArtifactValidValues%22 %7D )%0A    public void testSearchExistingArtifactUsingAdvancedSearchNoAccessToRepository()%0A    %7B%0A        searchForArtifactAdvancedSearch( null, getProperty( %22ARTIFACT_ARTIFACTID%22 ), null, %22managedrepo1%22, null, null );%0A        assertTextPresent( %22No results found%22 );%0A        assertTextNotPresent( %22Results%22 );%0A        assertTextNotPresent( %22Hits: 1 to 1 of 1%22 );%0A        assertLinkNotPresent( %22test%22 );   %0A    %7D
 %0A%7D%0A%0A

Create Selenium test for advanced search feature o add advanced search selenium test using different search criteria