1 18 package org.apache.roller.business; 19 20 import java.sql.Timestamp ; 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 import org.apache.roller.business.search.operations.AddEntryOperation; 25 import org.apache.roller.business.search.operations.RemoveEntryOperation; 26 import org.apache.roller.business.search.operations.SearchOperation; 27 import org.apache.roller.model.IndexManager; 28 import org.apache.roller.model.RollerFactory; 29 import org.apache.roller.pojos.UserData; 30 import org.apache.roller.pojos.WeblogEntryData; 31 import org.apache.roller.pojos.WebsiteData; 32 33 34 37 public class IndexManagerTest extends TestCase { 38 39 public IndexManagerTest(String name) { 40 super(name); 41 } 42 43 public static Test suite() { 44 return new TestSuite(IndexManagerTest.class); 45 } 46 47 public void testSearch() throws Exception { 48 IndexManager imgr = RollerFactory.getRoller().getIndexManager(); 49 50 WebsiteData website = new WebsiteData(); 51 website.setHandle("trekker"); 52 53 UserData user = new UserData(); 54 user.setUserName("nimoy"); 55 56 WeblogEntryData wd1 = new WeblogEntryData(); 57 wd1.setId("dummy1"); 58 wd1.setAnchor("dummy1"); 59 wd1.setCreator(user); 60 wd1.setUpdateTime(new Timestamp (System.currentTimeMillis())); 61 wd1.setPubTime(new Timestamp (System.currentTimeMillis())); 62 wd1.setTitle("The Tholian Web"); 63 wd1.setWebsite(website); 64 wd1.setText( 65 "When the Enterprise attempts to ascertain the fate of the " 66 +"U.S.S. Defiant which vanished 3 weeks ago, the warp engines " 67 +"begin to lose power, and Spock reports strange sensor readings."); 68 imgr.executeIndexOperationNow( 69 new AddEntryOperation((IndexManagerImpl) imgr, wd1)); 70 71 WeblogEntryData wd2 = new WeblogEntryData(); 72 wd2.setId("dummy2"); 73 wd2.setAnchor("dummy2"); 74 wd2.setCreator(user); 75 wd2.setUpdateTime(new Timestamp (System.currentTimeMillis())); 76 wd2.setPubTime(new Timestamp (System.currentTimeMillis())); 77 wd2.setTitle("A Piece of the Action"); 78 wd2.setWebsite(website); 79 wd2.setText( 80 "The crew of the Enterprise attempts to make contact with " 81 +"the inhabitants of planet Sigma Iotia II, and Uhura puts Kirk " 82 +"in communication with Boss Oxmyx."); 83 imgr.executeIndexOperationNow( 84 new AddEntryOperation((IndexManagerImpl) imgr, wd2)); 85 86 Thread.sleep(1000); 87 88 SearchOperation search = new SearchOperation(imgr); 89 search.setTerm("Enterprise"); 90 imgr.executeIndexOperationNow(search); 91 assertEquals(2, search.getResultsCount()); 92 93 SearchOperation search2 = new SearchOperation(imgr); 94 search2.setTerm("Tholian"); 95 imgr.executeIndexOperationNow(search2); 96 assertEquals(1, search2.getResultsCount()); 97 98 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 } 108 | Popular Tags |