View Javadoc

1   package org.kuali.ole.docstore.process;
2   
3   import org.apache.commons.io.FileUtils;
4   import org.junit.Test;
5   import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
6   import org.kuali.ole.docstore.model.xstream.ingest.IngestDocumentHandler;
7   import org.kuali.ole.documenthandler.WorkBibMarcContentHandler;
8   
9   import java.io.File;
10  import java.net.URL;
11  import java.text.DateFormat;
12  import java.text.SimpleDateFormat;
13  import java.util.ArrayList;
14  import java.util.Calendar;
15  
16  /**
17   * Created by IntelliJ IDEA.
18   * User: nd6967
19   * Date: 9/12/12
20   * Time: 4:47 PM
21   * To change this template use File | Settings | File Templates.
22   */
23  public class WorkBibMarcContentHandler_UT {
24      IngestDocumentHandler ingestDocumentHandler = new IngestDocumentHandler();
25  
26      @Test
27      public void testdoPreIngestContentManipulations() throws Exception {
28          URL resource = getClass().getResource("/org/kuali/ole/repository/Sample-Input.xml");
29          File file = new File(resource.toURI());
30          String fileContent = FileUtils.readFileToString(file);
31          ArrayList<RequestDocument> ingestDocs = new ArrayList<RequestDocument>();
32          int uuid = 1;
33          for (int i = 0; i < 1000; i++) {
34              ingestDocs.add(ingestDocumentHandler.toObject(fileContent));
35          }
36          WorkBibMarcContentHandler wbch = new WorkBibMarcContentHandler();
37          RequestDocument reqDoc = ingestDocs.get(0);
38          System.out.println("First Request Document content before modifying " + reqDoc.getContent().getContent());
39          long start = System.currentTimeMillis();
40          get("start");
41          for (RequestDocument rq : ingestDocs) {
42              wbch.doPreIngestContentManipulations(rq, Integer.toString(uuid));
43  //            if (uuid <= 3) {
44  //                System.out.println(" Request Document content after modifying " + rq.getContent().getContent());
45  //            }
46              uuid++;
47          }
48          get("end");
49          System.out.println("total " + (System.currentTimeMillis() - start));
50  
51  
52      }
53  
54      @Test
55      public void testdoPreIngestContentManipulationsForTesting() throws Exception {
56          URL resource = getClass().getResource("/org/kuali/ole/repository/Sample-Input.xml");
57          File file = new File(resource.toURI());
58          String fileContent = FileUtils.readFileToString(file);
59          ArrayList<RequestDocument> ingestDocs = new ArrayList<RequestDocument>();
60          int uuid = 1;
61          for (int i = 0; i < 1000; i++) {
62              ingestDocs.add(ingestDocumentHandler.toObject(fileContent));
63          }
64          WorkBibMarcContentHandler wbch = new WorkBibMarcContentHandler();
65          RequestDocument reqDoc = ingestDocs.get(0);
66          System.out.println("First Request Document content before modifying " + reqDoc.getContent().getContent());
67          long start = System.currentTimeMillis();
68          get("start");
69          for (RequestDocument rq : ingestDocs) {
70              System.out.println("uuid " + uuid);
71              wbch.doPreIngestContentManipulationsForTesting(rq, Integer.toString(uuid));
72  //            if (uuid <= 3) {
73  //                System.out.println(" Request Document content after modifying " + rq.getContent().getContent());
74  //            }
75              uuid++;
76          }
77          get("end");
78  
79          System.out.println("total " + (System.currentTimeMillis() - start));
80      }
81  
82      public void get(String str) {
83          DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS");
84          long now = System.currentTimeMillis();
85          Calendar calendar = Calendar.getInstance();
86          calendar.setTimeInMillis(now);
87          System.out.println("Timeeeeee " + " " + str + " " + now + " = " + formatter.format(calendar.getTime()));
88      }
89  
90      public void display(RequestDocument rq) {
91          System.out.println("getCategory " + rq.getCategory());
92          System.out.println("getDocumentName " + rq.getDocumentName());
93          System.out.println("getContent " + rq.getContent().getContent());
94          System.out.println("getFormat " + rq.getFormat());
95          System.out.println("getType " + rq.getType());
96  
97      }
98  
99  }