View Javadoc

1   package org.kuali.ole;
2   
3   import org.junit.Test;
4   import org.kuali.ole.bo.cql.CQLResponseBO;
5   import org.kuali.ole.bo.serachRetrieve.OleSRUBibDocument;
6   import org.kuali.ole.docstore.model.bo.WorkBibDocument;
7   import org.kuali.ole.docstore.model.bo.WorkHoldingsDocument;
8   import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
9   import org.kuali.ole.service.OleCQLQueryParserService;
10  import org.kuali.ole.service.OleSRUDataService;
11  import org.kuali.ole.serviceimpl.OleCQLQueryParserServiceImpl;
12  import org.kuali.ole.serviceimpl.OleSRUDataServiceImpl;
13  import org.slf4j.Logger;
14  import org.slf4j.LoggerFactory;
15  
16  import java.util.HashMap;
17  import java.util.List;
18  import java.util.Map;
19  
20  import static junit.framework.Assert.assertNotNull;
21  import static junit.framework.Assert.assertNull;
22  
23  /**
24   * Created with IntelliJ IDEA.
25   * User: ?
26   * Date: 7/19/12
27   * Time: 7:07 PM
28   * To change this template use File | Settings | File Templates.
29   */
30  public class OleSRUDataService_UT extends BaseTestCase {
31  
32      private static Logger LOG = LoggerFactory.getLogger(OleValidateInputRequestService_UT.class);
33      private OleSRUDataService oleSRUDataService=new OleSRUDataServiceImpl();
34      private OleCQLQueryParserService oleCQLQueryParserService=new OleCQLQueryParserServiceImpl();
35      @Test
36      public void testGetBibliographicRecordsObject() throws Exception{
37          CQLResponseBO cQLResponseBO=getCQLResponseBOObject();
38          String solrQuery=getSolrQueryFromCQLParseBO(cQLResponseBO);
39          List<OleSRUBibDocument> oleSRUBibDocumentList=oleSRUDataService.getBibRecordsIdList(getReqParameters(),solrQuery);
40          if(oleSRUBibDocumentList!=null)
41           assertNotNull(oleSRUBibDocumentList);
42          else
43           assertNull(oleSRUBibDocumentList);
44      }
45  
46      private CQLResponseBO getCQLResponseBOObject() throws Exception{
47          OleCQLQueryParserService oleCQLQueryParserService=new OleCQLQueryParserServiceImpl();
48          String parserXml=oleCQLQueryParserService.parseCQLQuery("Title=HTC");
49          CQLResponseBO cQLResponseBO=oleCQLQueryParserService.getCQLResponseObject(parserXml);
50          return cQLResponseBO;
51      }
52  
53  
54      public String getSolrQueryFromCQLParseBO(CQLResponseBO cqlResponseBO){
55          String solrQuery=null;
56          solrQuery=oleCQLQueryParserService.getSolrQueryFromCQLBO(cqlResponseBO);
57          return solrQuery;
58      }
59  
60      private WorkBibDocument generateWorkBibDocumentObject(CQLResponseBO cqlResponseBO) {
61  
62          String term=cqlResponseBO.getSearchClauseTag().getTerm();
63          String relation=cqlResponseBO.getSearchClauseTag().getRelationTag().getValue();
64          String index=cqlResponseBO.getSearchClauseTag().getIndex();
65          WorkBibDocument workBibDocument = new WorkBibDocument();
66          WorkInstanceDocument workInstanceDocument = new WorkInstanceDocument();
67          WorkHoldingsDocument workHoldingsDocument=new WorkHoldingsDocument();
68          if("title".equalsIgnoreCase(index))
69              workBibDocument.setTitle(term+"*");
70          workBibDocument.setInstanceDocument(workInstanceDocument);
71          return workBibDocument;
72      }
73      public Map getReqParameters() {
74  
75          HashMap reqParamMap=new HashMap();
76          reqParamMap.put(OleSRUConstants.OPERATION_TYPE,OleSRUConstants.SEARCH_RETRIEVE);
77          reqParamMap.put(OleSRUConstants.VERSION,"1.1");
78          reqParamMap.put(OleSRUConstants.QUERY,"title=HTC");
79          reqParamMap.put(OleSRUConstants.START_RECORD,"1");
80          reqParamMap.put(OleSRUConstants.MAXIMUM_RECORDS,"10");
81          reqParamMap.put(OleSRUConstants.RECORD_PACKING,"xml");
82  
83          return reqParamMap;
84  
85      }
86  }