FileDocCategorySizeDatePackage
TestSearchModel.javaAPI DocExample1733Wed Nov 20 17:21:36 GMT 2002com.oreilly.javaxp.junitperf

TestSearchModel.java

package com.oreilly.javaxp.junitperf;

import junit.framework.TestCase;

import java.util.List;

/**
 * @author Eric M. Burke
 * @version $Id: TestSearchModel.java,v 1.8 2002/11/20 20:09:02 jepc Exp $
 */
public class TestSearchModel extends TestCase {
    public TestSearchModel(String name) {
        super(name);
    }

    /**
     * @junitperf.loadtest numberOfUsers="100"
     *                     numberOfIterations="3"
     */
    public void testSynchronousSearch() {
        SearchModel sm = new PersonSearchModel();

        // perform a search
        List results = sm.search("eric");
        assertEquals("Number of results", 1, results.size());
        Person p = (Person) results.get(0);
        assertEquals("Result", "Eric", p.getFirstName());

        // do another search
        results = sm.search("*");
        assertEquals("Number of results", 4, results.size());
    }

    /**
     * @junitperf.timedtest maxElapsedTime="3000"
     *                      waitForCompletion="false"
     */
    public void testAsynchronousSearch() throws InterruptedException {
        MockSearchModelListener mockListener = new MockSearchModelListener();
        SearchModel sm = new PersonSearchModel();
        sm.search("eric", mockListener);

        synchronized (mockListener) {
            mockListener.wait(10000);
        }

        SearchModelEvent evt = mockListener.getSearchModelEvent();
        assertNotNull("Search timed out", evt);
        List results = evt.getSearchResult();
        assertEquals("Number of results", 1, results.size());
        Person p = (Person) results.get(0);
        assertEquals("Result", "Eric", p.getFirstName());
    }
}