001package org.kuali.ole.docstore.discovery.service;
002
003import org.junit.Before;
004import org.junit.Test;
005import org.kuali.ole.docstore.discovery.BaseTestCase;
006import org.kuali.ole.docstore.discovery.model.SearchCondition;
007import org.kuali.ole.docstore.discovery.model.SearchParams;
008import org.kuali.rice.core.api.config.property.ConfigContext;
009import org.mockito.MockitoAnnotations;
010
011import java.util.ArrayList;
012import java.util.HashMap;
013import java.util.List;
014import java.util.Map;
015
016import static org.junit.Assert.assertNotNull;
017import static org.junit.Assert.assertTrue;
018
019/**
020 * Unit tests for DiscoveryService class.
021 * User: tirumalesh.b
022 * Date: 22/11/11 Time: 5:23 PM
023 */
024public class DiscoveryService_UT
025        extends BaseTestCase {
026    @Before
027    public void setUp() throws Exception {
028        super.setUp();
029        MockitoAnnotations.initMocks(this);
030    }
031
032    @Test
033    public void testBuildQuery() {
034        assertTrue(true);
035        SearchParams searchParams = getSearchParams();
036        searchParams.setSearchType("moreFacets");
037        DiscoveryService discoveryService = ServiceLocator.getDiscoveryService();
038        Map<String, String> facetTermsMap = new HashMap<String, String>();
039        facetTermsMap.put("Author_display", "Author");
040        facetTermsMap.put("Title_display", "Title");
041        searchParams.setFacetTermsMap(facetTermsMap);
042        searchParams.setResultPageSize("50");
043        searchParams.setResultFromIndex("0");
044        String query = discoveryService.buildQuery(searchParams);
045        assertNotNull(query);
046        LOG.info("query:" + query);
047
048    }
049
050    @Test
051    public void testSearch() throws Exception {
052        SearchParams searchParams = getSearchParams();
053        //System.setProperty("docSearchURL", "http://dev.docstore.ole.kuali.org/");
054       // System.out.println("url:" + ConfigContext.getCurrentContextConfig().getProperty("docSearchURL"));
055        String query = "";
056
057        searchParams.setSearchType("moreFacets");
058        DiscoveryService discoveryService = DiscoveryServiceImpl.getInstance();
059        query = discoveryService.search(searchParams);
060        assertNotNull(query);
061        LOG.info("search Type:" + searchParams.getSearchType());
062        LOG.info("query:" + query);
063
064
065        searchParams = getSearchParams();
066        searchParams.setSearchType("linksearch");
067        query = discoveryService.search(searchParams);
068        LOG.info("search Type:" + searchParams.getSearchType());
069        LOG.info("query:" + query);
070
071
072        searchParams = getSearchParams();
073        searchParams.setSearchType("advancedSearch");
074        searchParams.setResultFromIndex("0");
075        searchParams.setResultPageSize("50");
076        List<SearchCondition> searchConditionList = new ArrayList<SearchCondition>();
077        SearchCondition searchCondition = new SearchCondition();
078        searchCondition.setSearchText("Carl San");
079        searchCondition.setOperator("NOT");
080        searchCondition.setDocField("all");
081        searchCondition.setSearchScope("OR");
082        searchConditionList.add(searchCondition);
083        searchParams.setSearchFieldsList(searchConditionList);
084
085        List<String> fieldList = new ArrayList<String>();
086        fieldList.add("Author");
087        fieldList.add("Subject");
088        searchParams.setFieldList(fieldList);
089        searchParams.setSortField("Author");
090        query = discoveryService.search(searchParams);
091        LOG.info("search Type:" + searchParams.getSearchType());
092        LOG.info("query:" + query);
093
094
095    }
096
097    public SearchParams getSearchParams() {
098        SearchParams searchParams = new SearchParams();
099        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        //        searchParams.setSearchType("moreFacets");
117        return searchParams;
118    }
119
120}