1 package org.kuali.ole;
2
3 import org.junit.Test;
4 import org.kuali.ole.pojo.OleBibRecord;
5 import org.kuali.ole.pojo.OleOrderRecord;
6 import org.kuali.ole.pojo.OleTxRecord;
7 import org.kuali.ole.pojo.bib.BibliographicRecord;
8 import org.kuali.ole.pojo.edi.EDIOrder;
9 import org.kuali.ole.pojo.edi.MessageHeader;
10
11 import java.io.File;
12 import java.net.URL;
13 import java.util.ArrayList;
14 import java.util.Date;
15 import java.util.HashMap;
16 import java.util.List;
17
18 import static junit.framework.Assert.assertNotNull;
19 import static junit.framework.Assert.assertTrue;
20
21
22
23
24
25
26
27
28 public class OleOrderRecordHandler_UT {
29 @Test
30 public void testExtractOleOrderRecordsFromXML() throws Exception {
31 OleOrderRecordHandler orderRecordHandlerNew =
32 new OleOrderRecordHandler();
33
34 URL resource = getClass().getResource("OleOrderRecord.xml");
35 String xmlContent = new FileUtil().readFile(new File(resource.toURI()));
36
37 OleOrderRecords oleOrderRecords = orderRecordHandlerNew.fromXML(xmlContent);
38 assertNotNull(oleOrderRecords);
39 assertTrue(!oleOrderRecords.getRecords().isEmpty());
40 for (int i=0;i<oleOrderRecords.getRecords().size();i++){
41 System.out.println(oleOrderRecords.getRecords().get(i));
42 }
43 }
44
45 @Test
46 public void testGenerateXML() throws Exception {
47 OleOrderRecordHandler oleOrderRecordHandler = new OleOrderRecordHandler();
48
49
50 OleOrderRecord oleOrderRecord = new OleOrderRecord();
51 OleBibRecord oleBibRecord = new OleBibRecord();
52 oleBibRecord.setLinkedInstanceId("123213");
53 HashMap bibAssociatedFieldsValueMap = new HashMap();
54 bibAssociatedFieldsValueMap.put("author", "mock_author");
55 bibAssociatedFieldsValueMap.put("title", "mock_title");
56 oleBibRecord.setBibAssociatedFieldsValueMap(bibAssociatedFieldsValueMap);
57 oleBibRecord.setBibUUID("45643543");
58 oleOrderRecord.setOleBibRecord(oleBibRecord);
59 OleTxRecord oleTxRecord = new OleTxRecord();
60 oleTxRecord.setAccountNumber("1234567");
61 oleTxRecord.setDeliveryDateRequired(new Date());
62 oleOrderRecord.setOleTxRecord(oleTxRecord);
63 BibliographicRecord bibliographicRecord = new BibliographicRecord();
64 bibliographicRecord.setLeader("Lincoln");
65 oleOrderRecord.setOriginalRecord(bibliographicRecord);
66 EDIOrder eDIOrder = new EDIOrder();
67 MessageHeader messageHeader = new MessageHeader();
68 messageHeader.setInterchangeControlReference("reference");
69 eDIOrder.setMessageHeader(messageHeader);
70 oleOrderRecord.setOriginalEdi(eDIOrder);
71 List messages = new ArrayList();
72 messages.add("isbnCheckFailed");
73 oleOrderRecord.addMessageToMap("message", messages);
74 oleOrderRecord.setAgendaName("mockAgenda");
75 oleOrderRecord.setOriginalEDIFileName("ediFileName.edi");
76 oleOrderRecord.setOleOriginalBibRecordFileName("bib.mrc");
77
78 OleOrderRecord oleOrderRecord1 = new OleOrderRecord();
79 OleBibRecord oleBibRecord1 = new OleBibRecord();
80 oleBibRecord1.setBibUUID("123456789");
81 oleBibRecord.setLinkedInstanceId("123213");
82 HashMap bibAssociatedFieldsValueMap1 = new HashMap();
83 bibAssociatedFieldsValueMap1.put("author1", "mock_author1");
84 bibAssociatedFieldsValueMap1.put("title1", "mock_title1");
85 oleBibRecord1.setBibAssociatedFieldsValueMap(bibAssociatedFieldsValueMap1);
86 OleTxRecord oleTxRecord1 = new OleTxRecord();
87 oleTxRecord1.setAccountNumber("56789");
88 oleOrderRecord1.setOleBibRecord(oleBibRecord1);
89 oleOrderRecord1.setOleTxRecord(oleTxRecord1);
90
91 BibliographicRecord bibliographicRecord1 = new BibliographicRecord();
92 bibliographicRecord1.setLeader("kennedy");
93 oleOrderRecord1.setOriginalRecord(bibliographicRecord1);
94 EDIOrder eDIOrder1 = new EDIOrder();
95 MessageHeader messageHeader1 = new MessageHeader();
96 messageHeader1.setInterchangeControlReference("reference");
97 eDIOrder1.setMessageHeader(messageHeader1);
98 oleOrderRecord1.setOriginalEdi(eDIOrder1);
99
100 OleOrderRecords record = new OleOrderRecords();
101 List<OleOrderRecord> records = new ArrayList<OleOrderRecord>();
102
103 records.add(oleOrderRecord);
104 records.add(oleOrderRecord1);
105 record.setRecords(records);
106
107 String xml = oleOrderRecordHandler.toXML(record);
108 System.out.println(xml);
109
110 }
111 }