KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > business > IndexManagerTest


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.business;
19
20 import java.sql.Timestamp JavaDoc;
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 /**
35  * Test Search Manager business layer operations.
36  */

37 public class IndexManagerTest extends TestCase {
38         
39     public IndexManagerTest(String JavaDoc 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 JavaDoc {
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 JavaDoc(System.currentTimeMillis()));
61         wd1.setPubTime(new Timestamp JavaDoc(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 JavaDoc(System.currentTimeMillis()));
76         wd2.setPubTime(new Timestamp JavaDoc(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         // Clean up
99
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