View Javadoc
1   package org.kuali.ole.docstore.discovery.solr.work.license.binary;
2   
3   import junit.framework.TestCase;
4   import org.apache.solr.common.SolrInputDocument;
5   import org.junit.After;
6   import org.junit.Assert;
7   import org.junit.Before;
8   import org.junit.Test;
9   import org.kuali.ole.docstore.discovery.BaseTestCase;
10  import org.kuali.ole.docstore.model.enums.DocFormat;
11  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
12  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
13  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
14  import org.slf4j.Logger;
15  import org.slf4j.LoggerFactory;
16  
17  import java.io.File;
18  import java.net.URL;
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.UUID;
22  
23  /**
24   * Created by IntelliJ IDEA.
25   * User: Sreekanth
26   * Date: 6/1/12
27   * Time: 10:47 AM
28   * To change this template use File | Settings | File Templates.
29   */
30  public class WorkLicenseBinaryDocBuilder_UT extends BaseTestCase {
31  
32      protected final Logger LOG = LoggerFactory.getLogger(WorkLicenseBinaryDocBuilder_UT.class);
33  
34      WorkLicenseBinaryDocBuilder workLicenseBinaryDocBuilder = new WorkLicenseBinaryDocBuilder();
35      List<SolrInputDocument> solrInputDocuments = new ArrayList<SolrInputDocument>();
36  
37      @Before
38      public void setUp() throws Exception {
39      }
40  
41      @After
42      public void tearDown() throws Exception {
43          //To change body of created methods use File | Settings | File Templates.
44      }
45  
46      @Test
47      public void testIndexBinaryDocuments() throws Exception {
48          try {
49              String resFile = "/work/license/binary/OLE-License-Binary.xml";
50              URL resource = getClass().getResource(resFile);
51              File file = new File(resource.toURI());
52              String requestContent = readFile(file);
53              RequestHandler requestHandler = new RequestHandler();
54              Request request = requestHandler.toObject(requestContent);
55              List<RequestDocument> requestDocumentList = request.getRequestDocuments();
56              for (RequestDocument requestDocument : requestDocumentList) {
57                  requestDocument.setUuid(String.valueOf(Math.round(Math.random())));
58                  workLicenseBinaryDocBuilder.buildSolrInputDocument(requestDocument, solrInputDocuments);
59                  Assert.assertNotNull(solrInputDocuments);
60                  LOG.info("uuid-->" + requestDocument.getUuid());
61                  LOG.info("type-->" + requestDocument.getAdditionalAttributes().getAttribute("type"));
62              }
63              String fileName = (String) solrInputDocuments.get(0).getField("FileName_search").getValue();
64              LOG.info("File Name-->" + fileName);
65              Assert.assertEquals("test.xslt", fileName);
66              String dateuploaded = (String) solrInputDocuments.get(0).getField("DateUploaded_search").getValue();
67              LOG.info("Date Uploaded-->" + dateuploaded);
68              Assert.assertEquals("01/06/2012", dateuploaded);
69              String owner = (String) solrInputDocuments.get(0).getField("Owner_search").getValue();
70              LOG.info("Owner-->" + owner);
71              Assert.assertEquals("HTC", owner);
72          } catch (Exception e) {
73              LOG.error(e.getMessage() , e);
74          }
75      }
76  
77      @Test
78      public void testBuildSolrInputDocumentByJxp() {
79          String resFile = "/work/license/binary/OLE-License-Binary.xml";
80          URL resource = getClass().getResource(resFile);
81          File file;
82          try {
83              file = new File(resource.toURI());
84              String requestContent = readFile(file);
85              RequestHandler requestHandler = new RequestHandler();
86              Request request = requestHandler.toObject(requestContent);
87              List<RequestDocument> requestDocumentList = request.getRequestDocuments();
88              for (RequestDocument requestDocument : requestDocumentList) {
89                  requestDocument.setUuid(String.valueOf(Math.round(Math.random())));
90                  solrInputDocuments.add(workLicenseBinaryDocBuilder.buildSolrInputDocumentByJxp(requestDocument.getAdditionalAttributes(),
91                          requestDocument.getFormat()));
92                  Assert.assertNotNull(solrInputDocuments);
93                  LOG.info("uuid-->" + requestDocument.getUuid());
94                  LOG.info("type-->" + requestDocument.getAdditionalAttributes().getAttribute("type"));
95              }
96              System.out.println(solrInputDocuments);
97              String fileName = (String) solrInputDocuments.get(0).getField("FileName_search").getValue();
98              LOG.info("File Name-->" + fileName);
99              Assert.assertEquals("test.xslt", fileName);
100             String dateuploaded = (String) solrInputDocuments.get(0).getField("DateUploaded_search").getValue();
101             LOG.info("Date Uploaded-->" + dateuploaded);
102             Assert.assertEquals("01/06/2012", dateuploaded);
103             String owner = (String) solrInputDocuments.get(0).getField("Owner_search").getValue();
104             LOG.info("Owner-->" + owner);
105             Assert.assertEquals("HTC", owner);
106 
107         } catch (Exception e) {
108             LOG.error(e.getMessage() , e);
109             TestCase.fail("");
110         }
111     }
112 
113     @Test
114     public void testBuildSolrInputDocumentByJxpForPdf() {
115         String resFile = "/work/license/binary/OLE-License-Binary.xml";
116         URL resource = getClass().getResource(resFile);
117         File file;
118         try {
119             file = new File(resource.toURI());
120             String requestContent = readFile(file);
121             RequestHandler requestHandler = new RequestHandler();
122             Request request = requestHandler.toObject(requestContent);
123             List<RequestDocument> requestDocumentList = request.getRequestDocuments();
124             for (RequestDocument requestDocument : requestDocumentList) {
125                 requestDocument.setUuid(String.valueOf(Math.round(Math.random())));
126                 requestDocument.setFormat(DocFormat.PDF.getCode());
127                 solrInputDocuments.add(workLicenseBinaryDocBuilder.buildSolrInputDocumentByJxp(requestDocument.getAdditionalAttributes(),
128                         requestDocument.getFormat()));
129                 Assert.assertNotNull(solrInputDocuments);
130                 LOG.info("uuid-->" + requestDocument.getUuid());
131                 LOG.info("type-->" + requestDocument.getAdditionalAttributes().getAttribute("type"));
132             }
133             System.out.println(solrInputDocuments);
134             String fileName = (String) solrInputDocuments.get(0).getField("FileName_search").getValue();
135             LOG.info("File Name-->" + fileName);
136             Assert.assertEquals("test.xslt", fileName);
137             String dateuploaded = (String) solrInputDocuments.get(0).getField("DateUploaded_search").getValue();
138             LOG.info("Date Uploaded-->" + dateuploaded);
139             Assert.assertEquals("01/06/2012", dateuploaded);
140             String owner = (String) solrInputDocuments.get(0).getField("Owner_search").getValue();
141             LOG.info("Owner-->" + owner);
142             Assert.assertEquals("HTC", owner);
143 
144         } catch (Exception e) {
145             LOG.error(e.getMessage() , e);
146             TestCase.fail("");
147         }
148     }
149 
150     @Test
151     public void testBuildSolrInputDocumentByJxpForDoc() {
152         String resFile = "/work/license/binary/OLE-License-Binary.xml";
153         URL resource = getClass().getResource(resFile);
154         File file;
155         try {
156             file = new File(resource.toURI());
157             String requestContent = readFile(file);
158             RequestHandler requestHandler = new RequestHandler();
159             Request request = requestHandler.toObject(requestContent);
160             List<RequestDocument> requestDocumentList = request.getRequestDocuments();
161             for (RequestDocument requestDocument : requestDocumentList) {
162                 requestDocument.setUuid(String.valueOf(Math.round(Math.random())));
163                 requestDocument.setFormat(DocFormat.DOC.getCode());
164                 solrInputDocuments.add(workLicenseBinaryDocBuilder.buildSolrInputDocumentByJxp(requestDocument.getAdditionalAttributes(),
165                         requestDocument.getFormat()));
166                 Assert.assertNotNull(solrInputDocuments);
167                 LOG.info("uuid-->" + requestDocument.getUuid());
168                 LOG.info("type-->" + requestDocument.getAdditionalAttributes().getAttribute("type"));
169             }
170             System.out.println(solrInputDocuments);
171             String fileName = (String) solrInputDocuments.get(0).getField("FileName_search").getValue();
172             LOG.info("File Name-->" + fileName);
173             Assert.assertEquals("test.xslt", fileName);
174             String dateuploaded = (String) solrInputDocuments.get(0).getField("DateUploaded_search").getValue();
175             LOG.info("Date Uploaded-->" + dateuploaded);
176             Assert.assertEquals("01/06/2012", dateuploaded);
177             String owner = (String) solrInputDocuments.get(0).getField("Owner_search").getValue();
178             LOG.info("Owner-->" + owner);
179             Assert.assertEquals("HTC", owner);
180 
181         } catch (Exception e) {
182             LOG.error(e.getMessage() , e);
183             TestCase.fail("");
184         }
185     }
186 }