001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: package org.apache.roller.business;
019:
020: import java.sql.Timestamp;
021: import junit.framework.Test;
022: import junit.framework.TestCase;
023: import junit.framework.TestSuite;
024: import org.apache.roller.business.search.IndexManagerImpl;
025: import org.apache.roller.business.search.operations.AddEntryOperation;
026: import org.apache.roller.business.search.operations.RemoveEntryOperation;
027: import org.apache.roller.business.search.operations.SearchOperation;
028: import org.apache.roller.business.search.IndexManager;
029: import org.apache.roller.business.RollerFactory;
030: import org.apache.roller.pojos.UserData;
031: import org.apache.roller.pojos.WeblogEntryData;
032: import org.apache.roller.pojos.WebsiteData;
033:
034: /**
035: * Test Search Manager business layer operations.
036: */
037: public class IndexManagerTest extends TestCase {
038:
039: public IndexManagerTest(String name) {
040: super (name);
041: }
042:
043: public static Test suite() {
044: return new TestSuite(IndexManagerTest.class);
045: }
046:
047: public void testSearch() throws Exception {
048: IndexManager imgr = RollerFactory.getRoller().getIndexManager();
049:
050: WebsiteData website = new WebsiteData();
051: website.setHandle("trekker");
052:
053: UserData user = new UserData();
054: user.setUserName("nimoy");
055:
056: WeblogEntryData wd1 = new WeblogEntryData();
057: wd1.setId("dummy1");
058: wd1.setAnchor("dummy1");
059: wd1.setCreator(user);
060: wd1.setUpdateTime(new Timestamp(System.currentTimeMillis()));
061: wd1.setPubTime(new Timestamp(System.currentTimeMillis()));
062: wd1.setTitle("The Tholian Web");
063: wd1.setWebsite(website);
064: wd1
065: .setText("When the Enterprise attempts to ascertain the fate of the "
066: + "U.S.S. Defiant which vanished 3 weeks ago, the warp engines "
067: + "begin to lose power, and Spock reports strange sensor readings.");
068: imgr.executeIndexOperationNow(new AddEntryOperation(
069: (IndexManagerImpl) imgr, wd1));
070:
071: WeblogEntryData wd2 = new WeblogEntryData();
072: wd2.setId("dummy2");
073: wd2.setAnchor("dummy2");
074: wd2.setCreator(user);
075: wd2.setUpdateTime(new Timestamp(System.currentTimeMillis()));
076: wd2.setPubTime(new Timestamp(System.currentTimeMillis()));
077: wd2.setTitle("A Piece of the Action");
078: wd2.setWebsite(website);
079: wd2
080: .setText("The crew of the Enterprise attempts to make contact with "
081: + "the inhabitants of planet Sigma Iotia II, and Uhura puts Kirk "
082: + "in communication with Boss Oxmyx.");
083: imgr.executeIndexOperationNow(new AddEntryOperation(
084: (IndexManagerImpl) imgr, wd2));
085:
086: Thread.sleep(1000);
087:
088: SearchOperation search = new SearchOperation(imgr);
089: search.setTerm("Enterprise");
090: imgr.executeIndexOperationNow(search);
091: assertEquals(2, search.getResultsCount());
092:
093: SearchOperation search2 = new SearchOperation(imgr);
094: search2.setTerm("Tholian");
095: imgr.executeIndexOperationNow(search2);
096: assertEquals(1, search2.getResultsCount());
097:
098: // Clean up
099: imgr.removeEntryIndexOperation(wd1);
100: imgr.removeEntryIndexOperation(wd2);
101:
102: SearchOperation search3 = new SearchOperation(imgr);
103: search3.setTerm("Enterprise");
104: imgr.executeIndexOperationNow(search3);
105: assertEquals(0, search3.getResultsCount());
106: }
107: }
|