View Javadoc
1   package org.kuali.ole.docstore.service;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.apache.solr.client.solrj.response.QueryResponse;
5   import org.junit.After;
6   import org.junit.Before;
7   import org.junit.Ignore;
8   import org.junit.Test;
9   import org.kuali.ole.BaseTestCase;
10  import org.kuali.ole.docstore.discovery.service.SolrServerManager;
11  import org.kuali.ole.docstore.discovery.util.HttpPostUtil;
12  import org.kuali.ole.docstore.indexer.solr.IndexerService;
13  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
14  import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
15  import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
16  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
17  import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
18  import org.slf4j.Logger;
19  import org.slf4j.LoggerFactory;
20  
21  import java.io.File;
22  import java.net.URL;
23  import java.util.ArrayList;
24  import java.util.Date;
25  import java.util.List;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.fail;
29  
30  /**
31   * Created by IntelliJ IDEA.
32   * User: Sreekanth
33   * Date: 3/8/12
34   * Time: 5:12 PM
35   * To change this template use File | Settings | File Templates.
36   */
37  @Ignore
38  @Deprecated
39  public class DocumentIngester_AT
40          extends BaseTestCase {
41  
42      private IndexerService indexerService = null;
43      public static final String FAILURE = "failure";
44      private static final Logger LOG = LoggerFactory
45              .getLogger(DocumentIngester_AT.class);
46      private IngestNIndexHandlerService ingestNIndexHandlerService = BeanLocator
47              .getIngestNIndexHandlerService();
48  
49      @Before
50      public void setUp() throws Exception {
51          indexerService = ServiceLocator.getIndexerService();
52  
53      }
54  
55      @After
56      public void tearDown() throws Exception {
57      }
58  
59      @Test
60      public void testBibBatchIngest() throws Exception {
61  
62          try {
63              cleanUpData();
64              URL resource = getClass().getResource("/org/kuali/ole/repository/request.xml");
65              File file = new File(resource.toURI());
66              String fileContent = FileUtils.readFileToString(file);
67              RequestHandler requestHandler = new RequestHandler();
68              Request request = requestHandler.toObject(fileContent);
69              Response response = ingestNIndexHandlerService.ingestNIndexRequestDocuments(request);
70              ResponseHandler responseHandler = new ResponseHandler();
71              String result = responseHandler.toXML(response);
72              LOG.info("response=" + result);
73              ResponseDocument responseDocument = new ResponseDocument();
74              List<ResponseDocument> responseDocumentList = new ArrayList<ResponseDocument>();
75              responseDocumentList = response.getDocuments();
76              responseDocument = responseDocumentList.get(0);
77              String bibUuid = responseDocument.getUuid();
78              LOG.info("uuid of Bib record-->" + bibUuid);
79              assertEquals(bibUuid, responseDocumentList.get(0).getUuid());
80              String instanceUuid = responseDocumentList.get(0).getLinkedDocuments().get(0).getUuid();
81              LOG.info("instance Uuid-->" + instanceUuid);
82              QueryResponse queryResponse = indexerService
83                      .searchBibRecord("work", "bibliographic", "marc", "instanceIdentifier", instanceUuid, "");
84              String id = (String) queryResponse.getResults().get(0).getFieldValue("id");
85              LOG.info("id-->" + id);
86              assertEquals(bibUuid, id);
87              LOG.info("queryResponse->" + queryResponse);
88              QueryResponse queryResponse1 = indexerService
89                      .searchBibRecord("work", "instance", "oleml", "id", instanceUuid, "");
90              LOG.info("queryResponse1-->" + queryResponse1);
91  
92          } catch (Exception e) {
93              LOG.info(e.getMessage() , e);
94              //fail("Failed due to: " + e);
95          }
96          //cleanUpData();
97  
98      }
99  
100     private void cleanUpData() throws Exception {
101         StringBuffer buffer = new StringBuffer();
102         buffer.append(SolrServerManager.getInstance().getSolrCoreURL());
103         buffer.append("/update/");
104         String params = "stream.body=<delete><query>*:*</query></delete>&commit=true";
105         LOG.info("delete URL-->" + buffer.toString() + params);
106         HttpPostUtil.postData(buffer.toString(), params);
107     }
108 
109     protected String buildFailureMsg() {
110         return FAILURE + "-ErrorID:" + getErrorID();
111     }
112 
113     protected String getErrorID() {
114         return String.valueOf(new Date().getTime());
115     }
116 
117 
118 }