1 package org.kuali.ole.docstore.discovery.service;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.kuali.ole.docstore.discovery.BaseTestCase;
6 import org.kuali.ole.docstore.discovery.model.SearchCondition;
7 import org.kuali.ole.docstore.discovery.model.SearchParams;
8 import org.kuali.rice.core.api.config.property.ConfigContext;
9 import org.mockito.MockitoAnnotations;
10
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18
19
20
21
22
23
24 public class DiscoveryService_UT
25 extends BaseTestCase {
26 @Before
27 public void setUp() throws Exception {
28 super.setUp();
29 MockitoAnnotations.initMocks(this);
30 }
31
32 @Test
33 public void testBuildQuery() {
34 assertTrue(true);
35 SearchParams searchParams = getSearchParams();
36 searchParams.setSearchType("moreFacets");
37 DiscoveryService discoveryService = ServiceLocator.getDiscoveryService();
38 Map<String, String> facetTermsMap = new HashMap<String, String>();
39 facetTermsMap.put("Author_display", "Author");
40 facetTermsMap.put("Title_display", "Title");
41 searchParams.setFacetTermsMap(facetTermsMap);
42 searchParams.setResultPageSize("50");
43 searchParams.setResultFromIndex("0");
44 String query = discoveryService.buildQuery(searchParams);
45 assertNotNull(query);
46 LOG.info("query:" + query);
47
48 }
49
50 @Test
51 public void testSearch() throws Exception {
52 SearchParams searchParams = getSearchParams();
53
54
55 String query = "";
56
57 searchParams.setSearchType("moreFacets");
58 DiscoveryService discoveryService = DiscoveryServiceImpl.getInstance();
59 query = discoveryService.search(searchParams);
60 assertNotNull(query);
61 LOG.info("search Type:" + searchParams.getSearchType());
62 LOG.info("query:" + query);
63
64
65 searchParams = getSearchParams();
66 searchParams.setSearchType("linksearch");
67 query = discoveryService.search(searchParams);
68 LOG.info("search Type:" + searchParams.getSearchType());
69 LOG.info("query:" + query);
70
71
72 searchParams = getSearchParams();
73 searchParams.setSearchType("advancedSearch");
74 searchParams.setResultFromIndex("0");
75 searchParams.setResultPageSize("50");
76 List<SearchCondition> searchConditionList = new ArrayList<SearchCondition>();
77 SearchCondition searchCondition = new SearchCondition();
78 searchCondition.setSearchText("Carl San");
79 searchCondition.setOperator("NOT");
80 searchCondition.setDocField("all");
81 searchCondition.setSearchScope("OR");
82 searchConditionList.add(searchCondition);
83 searchParams.setSearchFieldsList(searchConditionList);
84
85 List<String> fieldList = new ArrayList<String>();
86 fieldList.add("Author");
87 fieldList.add("Subject");
88 searchParams.setFieldList(fieldList);
89 searchParams.setSortField("Author");
90 query = discoveryService.search(searchParams);
91 LOG.info("search Type:" + searchParams.getSearchType());
92 LOG.info("query:" + query);
93
94
95 }
96
97 public SearchParams getSearchParams() {
98 SearchParams searchParams = new SearchParams();
99 searchParams.setDocCategory("work");
100 searchParams.setDocType("bibliographic");
101 searchParams.setDocFormat("marc");
102 List<SearchCondition> searchConditionList = new ArrayList<SearchCondition>();
103 SearchCondition searchCondition = new SearchCondition();
104 searchCondition.setSearchText("Carl San");
105 searchCondition.setOperator("NOT");
106 searchCondition.setDocField("Author_search");
107 searchCondition.setSearchScope("OR");
108 searchConditionList.add(searchCondition);
109 searchCondition = new SearchCondition();
110 searchCondition.setSearchText("Sandburg");
111 searchCondition.setOperator("NOT");
112 searchCondition.setDocField("Author_search");
113 searchCondition.setSearchScope("OR");
114 searchConditionList.add(searchCondition);
115 searchParams.setSearchFieldsList(searchConditionList);
116
117 return searchParams;
118 }
119
120 }