1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.search;
18
19 import java.net.URL;
20
21 import junit.awtui.TestRunner;
22 import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 import org.apache.jetspeed.services.resources.JetspeedResources;
26 import org.apache.jetspeed.test.HeadlessBaseTest;
27
28 /***
29 * Test Search Service
30 *
31 * @author <a href="paulsp@apache.org">Paul Spencer</a>
32 * @author <a href="taylor@apache.org">David Sean Taylor</a>
33 *
34 * @version $Id: TestSearch.java,v 1.1 2004/04/07 22:02:42 jford Exp $
35 */
36 public class TestSearch extends HeadlessBaseTest
37 {
38
39 /***
40 * Defines the testcase name for JUnit.
41 *
42 * @param name the testcase's name.
43 */
44 public TestSearch(String name)
45 {
46 super(name);
47 }
48
49 /***
50 * Start the tests.
51 *
52 * @param args the arguments. Not used
53 */
54 public static void main(String args[])
55 {
56 TestRunner.main(new String[] { TestSearch.class.getName() });
57 }
58
59 /***
60 * Creates the test suite.
61 *
62 * @return a test suite (<code>TestSuite</code>) that includes all methods
63 * starting with "test"
64 */
65 public static Test suite()
66 {
67
68 return new TestSuite(TestSearch.class);
69 }
70
71 public void testRemoveWebPage() throws Exception
72 {
73 System.out.println("search home = " + JetspeedResources.getString("services.SearchService.directory"));
74 URL jetspeedHomePage = new URL("http://jakarta.apache.org/jetspeed/");
75 assertNotNull("Created URL to Jetspeed Home Page", jetspeedHomePage);
76 assertTrue("Removing non-existent index entry", Search.remove(jetspeedHomePage) == false);
77 assertTrue("Adding to index", Search.add(jetspeedHomePage));
78 assertTrue("Removing from index", Search.remove(jetspeedHomePage));
79 }
80
81 public void testPutWebPage() throws Exception
82 {
83 System.out.println("search home = " + JetspeedResources.getString("services.SearchService.directory"));
84 URL jetspeedHomePage = new URL("http://jakarta.apache.org/jetspeed");
85 assertNotNull("Created URL to Jetspeed Home Page", jetspeedHomePage);
86 assertTrue("Adding to index", Search.add(jetspeedHomePage));
87 assertTrue("Adding to index", Search.add(new URL("http://www.google.com")));
88 assertTrue("Adding to index", Search.add(new URL("http://jakarta.apache.org")));
89 }
90
91 /***
92 *
93 * @throws Exception
94 */
95 public void testVerifyJetspeedSearch() throws Exception
96 {
97 ParsedObject result = null;
98 SearchResults results = Search.search("rss");
99 System.out.println("Query 'rss' hits = " + results.size());
100 assertTrue(" Hit count > 0", results.size() > 0);
101 for (int i = 0; i < results.size(); i++)
102 {
103 result = results.get(i);
104 System.out.println("Score = " + result.getScore());
105 System.out.println("title = " + result.getTitle());
106 System.out.println("summary = " + result.getDescription());
107 System.out.println("url = " + result.getURL());
108 }
109 }
110
111 public void testVerifyJetspeedSearch1() throws Exception
112 {
113 ParsedObject result = null;
114 SearchResults results = Search.search("Jetspeed");
115 System.out.println("Query 'Jetspeed' hits = " + results.size());
116 assertTrue(" Hit count > 0", results.size() > 0);
117 for (int i = 0; i < results.size(); i++)
118 {
119 result = results.get(i);
120 System.out.println("Score = " + result.getScore());
121 System.out.println("title = " + result.getTitle());
122 System.out.println("summary = " + result.getDescription());
123 System.out.println("url = " + result.getURL());
124 }
125 }
126
127 public void testVerifyJetspeedSearch2() throws Exception
128 {
129 ParsedObject result = null;
130 SearchResults results = Search.search("google");
131 System.out.println("Query 'goggle' hits = " + results.size());
132 assertTrue(" Hit count > 0", results.size() > 0);
133 for (int i = 0; i < results.size(); i++)
134 {
135 result = results.get(i);
136 System.out.println("Score = " + result.getScore());
137 System.out.println("title = " + result.getTitle());
138 System.out.println("summary = " + result.getDescription());
139 System.out.println("url = " + result.getURL());
140 }
141 }
142
143 }