# Testing Searches

There is a convenient test superclass for search services, `com.splwg.base.api.testers.SearchTestCase`. This test class only requires that you override two methods:

- `String getServiceName()` - this method specifies the service name (CILCACCS) for the search.
- `List getSearchTrials()` - this method should return a list of `SearchTrials`.

A search trial describes information about a particular invocation of a search. You need to describe the inputs (the input fields and the search type), and then describe the expected output for that given input:

- Some expected rows, in the order expected.

In order to properly test searches, the expected results are not required to contain every search result- if new rows are added by some other process, they will not cause the test to fail. The search results, however, must contain at least all the expected results, in the relative order they are added.

- Possibly some prohibited rows, which the search should not find.

In addition, there may be times when you want to guarantee a certain row NOT to be found in the search result. This can be accomplished by adding a prohibitedRow, in the same manner as expected rows are added to the trial.

The search test FW will then use inputs from each search trial to execute the search and compare the expected and prohibited results to the actual search results. It expects to find the expected rows in the order added, and should find all of them. Any different order or missing row results in a failure. What will not result in a test failure is if new rows have been added interspersed throughout the expected rows. These are fine. If a given search result row does not match the next expected result row, it is compared against the prohibited rows. If it matches any of them, the test fails.

The search framework will also examine the information about the search, and ensure that each search type (main, alternate, alternate2, ...) is executed at least once.

Here is a sample search test class:

    			package com.splwg.base.domain.batch.batchControl;

    			import com.splwg.base.api.lookup.SearchTypeLookup;
    			import com.splwg.base.api.testers.SearchTestCase;
    			import com.splwg.base.api.testers.SearchTestResult;
    			import com.splwg.base.api.testers.SearchTrial;

    			import java.util.ArrayList;
    			import java.util.List;

    			/**
    			 * @author bosorio
    			 * @version $Revision: #2 $
    			 */
    			public class BatchControlSearchService_Test
    			    extends SearchTestCase {

    			    //~ Methods ----------------------------------------------------------

    			    protected String getServiceName() {
    			        return "CILTBTCS";
    			    }

    			    /**
    			     * @see com.splwg.base.api.testers.SearchTestCase#getSearchTrials()
    			     */
    			    protected List getSearchTrials() {
    			        List list = new ArrayList();

    			        // Search using Main Criteria
    			        SearchTrial trial = new SearchTrial("Main search");
    			        trial.setSearchType(SearchTypeLookup.constants.MAIN);

    			        trial.addInput(BatchControlSearchService.INPUT_MAIN.BATCH_CD,
    			              "ADM");
    			        SearchTestResult expectedResult = trial.newExpectedResult();
    			        expectedResult.put(BatchControlSearchService.RESULT.BATCH_CD,
    			              "ADM");
    			        list.add(trial);

    			        // Search using Alternate Criteria

    			        trial = new SearchTrial("Search by description");
    			        trial.setSearchType(SearchTypeLookup.constants.ALTERNATE);

    			        trial.addInput(BatchControlSearchService.INPUT_ALT.DESCR,
    			              "AcCount D");
    			        expectedResult = trial.newExpectedResult();
    			        expectedResult.put(BatchControlSearchService.RESULT.BATCH_CD,
    			              "ADM");
    			        expectedResult.put(BatchControlSearchService.RESULT.DESCR,
    			              "Account debt monitor");
    			        list.add(trial);

    			        return list;
    			    }
    			}

Parent topic: Standard test cases