SearchEngineTest.java revision 494
260N/A/*
260N/A * CDDL HEADER START
260N/A *
260N/A * The contents of this file are subject to the terms of the
260N/A * Common Development and Distribution License (the "License").
260N/A * You may not use this file except in compliance with the License.
260N/A *
260N/A * See LICENSE.txt included in this distribution for the specific
260N/A * language governing permissions and limitations under the License.
260N/A *
260N/A * When distributing Covered Code, include this CDDL HEADER in each
260N/A * file and include the License file at LICENSE.txt.
260N/A * If applicable, add the following below this CDDL HEADER, with the
260N/A * fields enclosed by brackets "[]" replaced with your own identifying
260N/A * information: Portions Copyright [yyyy] [name of copyright owner]
260N/A *
260N/A * CDDL HEADER END
260N/A */
260N/A
260N/A/*
260N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
260N/A * Use is subject to license terms.
260N/A */
260N/Apackage org.opensolaris.opengrok.search;
260N/A
260N/Aimport org.junit.Test;
260N/Aimport static org.junit.Assert.*;
260N/A
260N/A/**
260N/A * Do basic testing of the SearchEngine
260N/A *
260N/A * @author Trond Norbye
260N/A */
364N/Apublic class SearchEngineTest {
260N/A
260N/A @Test
260N/A public void testIsValidQuery() {
260N/A SearchEngine instance = new SearchEngine();
344N/A assertFalse(instance.isValidQuery());
260N/A instance.setFile("foo");
260N/A assertTrue(instance.isValidQuery());
260N/A }
260N/A
260N/A @Test
260N/A public void testDefinition() {
260N/A SearchEngine instance = new SearchEngine();
260N/A assertNull(instance.getDefinition());
260N/A String defs = "This is a definition";
260N/A instance.setDefinition(defs);
260N/A assertEquals(defs, instance.getDefinition());
260N/A }
260N/A
260N/A @Test
260N/A public void testFile() {
260N/A SearchEngine instance = new SearchEngine();
260N/A assertNull(instance.getFile());
260N/A String file = "This is a File";
260N/A instance.setFile(file);
260N/A assertEquals(file, instance.getFile());
260N/A }
260N/A
260N/A @Test
260N/A public void testFreetext() {
260N/A SearchEngine instance = new SearchEngine();
260N/A assertNull(instance.getFreetext());
260N/A String freetext = "This is just a piece of text";
260N/A instance.setFreetext(freetext);
260N/A assertEquals(freetext, instance.getFreetext());
260N/A }
260N/A
272N/A @Test
260N/A public void testHistory() {
260N/A SearchEngine instance = new SearchEngine();
260N/A assertNull(instance.getHistory());
260N/A String hist = "This is a piece of history";
260N/A instance.setHistory(hist);
260N/A assertEquals(hist, instance.getHistory());
260N/A }
260N/A
260N/A @Test
260N/A public void testSymbol() {
260N/A SearchEngine instance = new SearchEngine();
260N/A assertNull(instance.getSymbol());
296N/A String sym = "This is a symbol";
260N/A instance.setSymbol(sym);
260N/A assertEquals(sym, instance.getSymbol());
260N/A }
260N/A
260N/A @Test
260N/A public void testGetQuery() throws Exception {
260N/A SearchEngine instance = new SearchEngine();
260N/A instance.setHistory("Once upon a time");
260N/A instance.setFile("Makefile");
261N/A instance.setDefinition("std::string");
260N/A instance.setSymbol("toString");
260N/A instance.setFreetext("OpenGrok");
260N/A assertTrue(instance.isValidQuery());
260N/A assertEquals("+full:opengrok +defs:\"std string\" +refs:toString +path:makefile +(+hist:once +hist:upon +hist:time)",
260N/A instance.getQuery());
260N/A }
260N/A}