View Javadoc
1   package org.kuali.ole;
2   
3   import org.junit.Test;
4   import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
5   import org.kuali.ole.docstore.xstream.FileUtil;
6   import org.kuali.ole.pojo.OleBibRecord;
7   import org.kuali.ole.pojo.OleOrderRecord;
8   import org.kuali.ole.pojo.OleTxRecord;
9   import org.kuali.ole.pojo.edi.EDIOrder;
10  import org.kuali.ole.pojo.edi.MessageHeader;
11  import org.slf4j.Logger;
12  import org.slf4j.LoggerFactory;
13  import sun.rmi.runtime.Log;
14  
15  import java.io.File;
16  import java.net.URL;
17  import java.util.*;
18  
19  import static junit.framework.Assert.assertNotNull;
20  import static junit.framework.Assert.assertTrue;
21  
22  /**
23   * Created by IntelliJ IDEA.
24   * User: pvsubrah
25   * Date: 4/9/12
26   * Time: 7:20 AM
27   * To change this template use File | Settings | File Templates.
28   */
29  public class OleOrderRecordHandler_UT {
30      public static final Logger LOG = LoggerFactory.getLogger(OleOrderRecordHandler_UT.class);
31  
32      @Test
33      public void testExtractOleOrderRecordsFromXML() throws Exception {
34          OleOrderRecordHandler orderRecordHandlerNew =
35                  new OleOrderRecordHandler();
36  
37          URL resource = getClass().getResource("OleOrderRecord.xml");
38          String xmlContent = new FileUtil().readFile(new File(resource.toURI()));
39  
40          OleOrderRecords oleOrderRecords = orderRecordHandlerNew.fromXML(xmlContent);
41          assertNotNull(oleOrderRecords);
42          assertTrue(!oleOrderRecords.getRecords().isEmpty());
43          for (int i = 0; i < oleOrderRecords.getRecords().size(); i++) {
44              LOG.info(oleOrderRecords.getRecords().get(i).toString());
45          }
46  
47      }
48  
49      @Test
50      public void testGenerateXML() throws Exception {
51          OleOrderRecordHandler oleOrderRecordHandler = new OleOrderRecordHandler();
52  
53  
54          OleOrderRecord oleOrderRecord = new OleOrderRecord();
55          OleBibRecord oleBibRecord = new OleBibRecord();
56          oleBibRecord.setLinkedInstanceId("123213");
57          HashMap bibAssociatedFieldsValueMap = new HashMap();
58          bibAssociatedFieldsValueMap.put("author", "mock_author");
59          bibAssociatedFieldsValueMap.put("title", "mock_title");
60          oleBibRecord.setBibAssociatedFieldsValueMap(bibAssociatedFieldsValueMap);
61          oleBibRecord.setBibUUID("45643543");
62          oleOrderRecord.setOleBibRecord(oleBibRecord);
63  
64          //
65          if (oleOrderRecord.getOleBibRecord() != null) {
66              LOG.info(oleOrderRecord.getOleBibRecord().toString());
67          }
68          OleTxRecord oleTxRecord = new OleTxRecord();
69          oleTxRecord.setCostSource(null);
70          if (oleTxRecord.getCostSource() != null) {
71              LOG.info(oleTxRecord.getCostSource());
72          }
73          oleTxRecord.setFreeTextNote(null);
74          if (oleTxRecord.getFreeTextNote() != null) {
75              LOG.info(oleTxRecord.getFreeTextNote());
76          }
77          oleTxRecord.setYear(null);
78          if (oleTxRecord.getYear() != null) {
79              LOG.info(oleTxRecord.getYear());
80          }
81          oleTxRecord.setAmount(null);
82          if (oleTxRecord.getAmount() != null) {
83              LOG.info(oleTxRecord.getAmount());
84          }
85          oleTxRecord.setChartCode(null);
86          if (oleTxRecord.getChartCode() != null) {
87              LOG.info(oleTxRecord.getChartCode());
88          }
89          oleTxRecord.setOrgCode(null);
90          if (oleTxRecord.getOrgCode() != null) {
91              LOG.info(oleTxRecord.getOrgCode());
92          }
93          oleTxRecord.setItemChartCode(null);
94          if (oleTxRecord.getItemChartCode() != null) {
95              LOG.info(oleTxRecord.getItemChartCode());
96          }
97          oleTxRecord.setContractManager(null);
98          if (oleTxRecord.getContractManager() != null) {
99              LOG.info(oleTxRecord.getContractManager());
100         }
101         oleTxRecord.setAssignToUser(null);
102         if (oleTxRecord.getAssignToUser() != null) {
103             LOG.info(oleTxRecord.getAssignToUser());
104         }
105         oleTxRecord.setUseTaxIndicator(true);
106         if (oleTxRecord.isUseTaxIndicator()) {
107             LOG.info("Tax Indicator used");
108         }
109         oleTxRecord.setOrderType(null);
110         if (oleTxRecord.getOrderType() != null) {
111             LOG.info(oleTxRecord.getOrderType());
112         }
113         oleTxRecord.setFundingSource(null);
114         if (oleTxRecord.getFundingSource() != null) {
115             LOG.info(oleTxRecord.getFundingSource());
116         }
117         oleTxRecord.setPreviousPurchaseOrder(null);
118         if (oleTxRecord.getPreviousPurchaseOrder() != null) {
119             LOG.info(oleTxRecord.getPreviousPurchaseOrder());
120         }
121         oleTxRecord.setRequisitionSource(null);
122         if (oleTxRecord.getRequisitionSource() != null) {
123             LOG.info(oleTxRecord.getRequisitionSource());
124         }
125         oleTxRecord.setAdditionalInfo(null);
126         if (oleTxRecord.getAdditionalInfo() != null) {
127             LOG.info(oleTxRecord.getAdditionalInfo());
128         }
129         oleTxRecord.setDeliveryCampusCode(null);
130         if (oleTxRecord.getDeliveryCampusCode() != null) {
131             LOG.info(oleTxRecord.getDeliveryCampusCode());
132         }
133         oleTxRecord.setBuildingCode(null);
134         if (oleTxRecord.getBuildingCode() != null) {
135             LOG.info(oleTxRecord.getBuildingCode());
136         }
137         oleTxRecord.setDeliveryTo(null);
138         if (oleTxRecord.getDeliveryTo() != null) {
139             LOG.info(oleTxRecord.getDeliveryTo());
140         }
141         oleTxRecord.setDeliveryAddress1(null);
142         if (oleTxRecord.getDeliveryAddress1() != null) {
143             LOG.info(oleTxRecord.getDeliveryAddress1());
144         }
145         oleTxRecord.setDeliveryAddress2(null);
146         if (oleTxRecord.getDeliveryAddress2() != null) {
147             LOG.info(oleTxRecord.getDeliveryAddress2());
148         }
149         oleTxRecord.setDeliveryBuildingRoomNumber(null);
150         if (oleTxRecord.getDeliveryBuildingRoomNumber() != null) {
151             LOG.info(oleTxRecord.getDeliveryBuildingRoomNumber());
152         }
153         oleTxRecord.setDeliveryBuildingLine1Address(null);
154         if (oleTxRecord.getDeliveryBuildingLine1Address() != null) {
155             LOG.info(oleTxRecord.getDeliveryBuildingLine1Address());
156         }
157         oleTxRecord.setDeliveryCityName(null);
158         if (oleTxRecord.getDeliveryCityName() != null) {
159             LOG.info(oleTxRecord.getDeliveryCityName());
160         }
161         oleTxRecord.setDeliveryStateCode(null);
162         if (oleTxRecord.getDeliveryStateCode() != null) {
163             LOG.info(oleTxRecord.getDeliveryStateCode());
164         }
165         oleTxRecord.setDeliveryPostalCode(null);
166         if (oleTxRecord.getDeliveryPostalCode() != null) {
167             LOG.info(oleTxRecord.getDeliveryPostalCode());
168         }
169         oleTxRecord.setDeliveryCountryCode(null);
170         if (oleTxRecord.getDeliveryCountryCode() != null) {
171             LOG.info(oleTxRecord.getDeliveryCountryCode());
172         }
173         oleTxRecord.setDeliveryDateRequired(null);
174         if (oleTxRecord.getDeliveryDateRequired() != null) {
175             LOG.info(oleTxRecord.getDeliveryDateRequired().toString());
176         }
177         oleTxRecord.setDeliveryDateRequiredReason(null);
178         if (oleTxRecord.getDeliveryDateRequiredReason() != null) {
179             LOG.info(oleTxRecord.getDeliveryDateRequiredReason());
180         }
181         oleTxRecord.setDeliveryInstruction(null);
182         if (oleTxRecord.getDeliveryInstruction() != null) {
183             LOG.info(oleTxRecord.getDeliveryInstruction());
184         }
185         oleTxRecord.setReceivingAddress(null);
186         if (oleTxRecord.getReceivingAddress() != null) {
187             LOG.info(oleTxRecord.getReceivingAddress());
188         }
189         oleTxRecord.setReceivingAddressToVendorIndicator(null);
190         if (oleTxRecord.getReceivingAddressToVendorIndicator() != null) {
191             LOG.info(oleTxRecord.getReceivingAddressToVendorIndicator());
192         }
193         oleTxRecord.setVendor(null);
194         if (oleTxRecord.getVendor() != null) {
195             LOG.info(oleTxRecord.getVendor());
196         }
197         oleTxRecord.setVendorNumber(null);
198         if (oleTxRecord.getVendorNumber() != null) {
199             LOG.info(oleTxRecord.getVendorNumber());
200         }
201         oleTxRecord.setVendorAddress1(null);
202         if (oleTxRecord.getVendorAddress1() != null) {
203             LOG.info(oleTxRecord.getVendorAddress1());
204         }
205         oleTxRecord.setVendorAddress2(null);
206         if (oleTxRecord.getVendorAddress2() != null) {
207             LOG.info(oleTxRecord.getVendorAddress2());
208         }
209 
210         oleTxRecord.setAttention(null);
211         if (oleTxRecord.getAttention() != null) {
212             LOG.info(oleTxRecord.getAttention());
213         }
214         oleTxRecord.setVendorCity(null);
215         if (oleTxRecord.getVendorCity() != null) {
216             LOG.info(oleTxRecord.getVendorCity());
217         }
218         oleTxRecord.setVendorState(null);
219         if (oleTxRecord.getVendorState() != null) {
220             LOG.info(oleTxRecord.getVendorState());
221         }
222         oleTxRecord.setProvince(null);
223         if (oleTxRecord.getProvince() != null) {
224             LOG.info(oleTxRecord.getProvince());
225         }
226         oleTxRecord.setVendorPostalCode(null);
227         if (oleTxRecord.getVendorPostalCode() != null) {
228             LOG.info(oleTxRecord.getVendorPostalCode());
229         }
230         oleTxRecord.setVendorCountry(null);
231         if (oleTxRecord.getVendorCountry() != null) {
232             LOG.info(oleTxRecord.getVendorCountry());
233         }
234         oleTxRecord.setVendorChoice(null);
235         if (oleTxRecord.getVendorChoice() != null) {
236             LOG.info(oleTxRecord.getVendorChoice());
237         }
238         oleTxRecord.setVendorInfoCustomer(null);
239         if (oleTxRecord.getVendorInfoCustomer() != null) {
240             LOG.info(oleTxRecord.getVendorInfoCustomer());
241         }
242         oleTxRecord.setVendorNotes(null);
243         if (oleTxRecord.getVendorNotes() != null) {
244             LOG.info(oleTxRecord.getVendorNotes());
245         }
246         oleTxRecord.setAlternativeNonPrimaryVendorPayment(null);
247         if (oleTxRecord.getAlternativeNonPrimaryVendorPayment() != null) {
248             LOG.info(oleTxRecord.getAlternativeNonPrimaryVendorPayment());
249         }
250         oleTxRecord.setContract(null);
251         if (oleTxRecord.getContract() != null) {
252             LOG.info(oleTxRecord.getContract());
253         }
254         oleTxRecord.setVendorPhoneNumber(null);
255         if (oleTxRecord.getVendorPhoneNumber() != null) {
256             LOG.info(oleTxRecord.getVendorPhoneNumber());
257         }
258         oleTxRecord.setVendorFaxNumber(null);
259         if (oleTxRecord.getVendorFaxNumber() != null) {
260             LOG.info(oleTxRecord.getVendorFaxNumber());
261         }
262         oleTxRecord.setVendorPaymentTerms(null);
263         if (oleTxRecord.getVendorPaymentTerms() != null) {
264             LOG.info(oleTxRecord.getVendorPaymentTerms());
265         }
266         oleTxRecord.setVendorShippingTitle(null);
267         if (oleTxRecord.getVendorShippingTitle() != null) {
268             LOG.info(oleTxRecord.getVendorShippingTitle());
269         }
270         oleTxRecord.setVendorShippingPaymentTerms(null);
271         if (oleTxRecord.getVendorShippingPaymentTerms() != null) {
272             LOG.info(oleTxRecord.getVendorShippingPaymentTerms());
273         }
274         oleTxRecord.setVendorContacts(null);
275         if (oleTxRecord.getVendorContacts() != null) {
276             LOG.info(oleTxRecord.getVendorContacts());
277         }
278         oleTxRecord.setVendorSupplierDiversity(null);
279         if (oleTxRecord.getVendorSupplierDiversity() != null) {
280             LOG.info(oleTxRecord.getVendorSupplierDiversity());
281         }
282         oleTxRecord.setNote(null);
283         if (oleTxRecord.getNote() != null) {
284             LOG.info(oleTxRecord.getNote());
285         }
286         oleTxRecord.setItemType(null);
287         if (oleTxRecord.getItemType() != null) {
288             LOG.info(oleTxRecord.getItemType());
289         }
290         oleTxRecord.setQuantity(null);
291         if (oleTxRecord.getQuantity() != null) {
292             LOG.info(oleTxRecord.getQuantity());
293         }
294         oleTxRecord.setItemDescription(null);
295         if (oleTxRecord.getItemDescription() != null) {
296             LOG.info(oleTxRecord.getItemDescription());
297         }
298         oleTxRecord.setListPrice(null);
299         if (oleTxRecord.getListPrice() != null) {
300             LOG.info(oleTxRecord.getListPrice());
301         }
302         oleTxRecord.setDiscount(null);
303         if (oleTxRecord.getDiscount() != null) {
304             LOG.info(oleTxRecord.getDiscount());
305         }
306         oleTxRecord.setDiscountType(null);
307         if (oleTxRecord.getDiscountType() != null) {
308             LOG.info(oleTxRecord.getDiscountType());
309         }
310         oleTxRecord.setCurrencyType(null);
311         if (oleTxRecord.getCurrencyType() != null) {
312             LOG.info(oleTxRecord.getCurrencyType());
313         }
314         oleTxRecord.setVendorItemIdentifier(null);
315         if (oleTxRecord.getVendorItemIdentifier() != null) {
316             LOG.info(oleTxRecord.getVendorItemIdentifier());
317         }
318         oleTxRecord.setAccountNumber(null);
319         if (oleTxRecord.getAccountNumber() != null) {
320             LOG.info(oleTxRecord.getAccountNumber());
321         }
322         oleTxRecord.setObjectCode(null);
323         if (oleTxRecord.getObjectCode() != null) {
324             LOG.info(oleTxRecord.getObjectCode());
325         }
326         oleTxRecord.setOrgRefId(null);
327         if (oleTxRecord.getOrgRefId() != null) {
328             LOG.info(oleTxRecord.getOrgRefId());
329         }
330         oleTxRecord.setPercent(null);
331         if (oleTxRecord.getPercent() != null) {
332             LOG.info(oleTxRecord.getPercent());
333         }
334         oleTxRecord.setFormat(null);
335         if (oleTxRecord.getFormat() != null) {
336             LOG.info(oleTxRecord.getFormat());
337         }
338         oleTxRecord.setInternalPurchasingLimit(null);
339         if (oleTxRecord.getInternalPurchasingLimit() != null) {
340             LOG.info(oleTxRecord.getInternalPurchasingLimit());
341         }
342         oleTxRecord.setBillingName(null);
343         if (oleTxRecord.getBillingName() != null) {
344             LOG.info(oleTxRecord.getBillingName());
345         }
346         oleTxRecord.setBillingLine1Address(null);
347         if (oleTxRecord.getBillingLine1Address() != null) {
348             LOG.info(oleTxRecord.getBillingLine1Address());
349         }
350         oleTxRecord.setBillingCityName(null);
351         if (oleTxRecord.getBillingCityName() != null) {
352             LOG.info(oleTxRecord.getBillingCityName());
353         }
354         oleTxRecord.setBillingStateCode(null);
355         if (oleTxRecord.getBillingStateCode() != null) {
356             LOG.info(oleTxRecord.getBillingStateCode());
357         }
358         oleTxRecord.setBillingPostalCode(null);
359         if (oleTxRecord.getBillingPostalCode() != null) {
360             LOG.info(oleTxRecord.getBillingPostalCode());
361         }
362         oleTxRecord.setBillingPhoneNumber(null);
363         if (oleTxRecord.getBillingPhoneNumber() != null) {
364             LOG.info(oleTxRecord.getBillingPhoneNumber());
365         }
366         oleTxRecord.setBillingCountryCode(null);
367         if (oleTxRecord.getBillingCountryCode() != null) {
368             LOG.info(oleTxRecord.getBillingCountryCode());
369         }
370         oleTxRecord.setMethodOfPOTransmission(null);
371         if (oleTxRecord.getMethodOfPOTransmission() != null) {
372             LOG.info(oleTxRecord.getMethodOfPOTransmission());
373         }
374         oleTxRecord.setReceivingRequired(true);
375         if (oleTxRecord.isReceivingRequired()) {
376             LOG.info("Receiving Required");
377         }
378         oleTxRecord.setPayReqPositiveApprovalReq(true);
379         if (oleTxRecord.isPayReqPositiveApprovalReq()) {
380             LOG.info("Payment Request Positive Approval Requires");
381         }
382         oleTxRecord.setPurchaseOrderConfirmationIndicator(true);
383         if (oleTxRecord.isPurchaseOrderConfirmationIndicator()) {
384             LOG.info("Purchase Order Confirmation");
385         }
386         oleTxRecord.setRouteToRequestor(true);
387         if (oleTxRecord.isRouteToRequestor()) {
388             LOG.info("Route to Requestor");
389         }
390         oleTxRecord.setPublicView(true);
391         if (oleTxRecord.isPublicView()) {
392             LOG.info("Public View");
393         }
394         oleTxRecord.setAccountNumber("1234567");
395         oleTxRecord.setDeliveryDateRequired(new Date());
396         oleOrderRecord.setOleTxRecord(oleTxRecord);
397         if (oleOrderRecord.getOleTxRecord() != null) {
398             LOG.info(oleOrderRecord.getOleTxRecord().toString());
399         }
400         BibMarcRecord bibMarcRecord = new BibMarcRecord();
401         bibMarcRecord.setLeader("Lincoln");
402         oleOrderRecord.setOriginalRecord(bibMarcRecord);
403         if (oleOrderRecord.getOriginalRecord() != null) {
404             LOG.info(oleOrderRecord.getOriginalRecord().toString());
405         }
406         EDIOrder eDIOrder = new EDIOrder();
407         MessageHeader messageHeader = new MessageHeader();
408         messageHeader.setInterchangeControlReference("reference");
409         eDIOrder.setMessageHeader(messageHeader);
410         oleOrderRecord.setOriginalEdi(eDIOrder);
411         if (oleOrderRecord.getOriginalEdi() != null) {
412             LOG.info(oleOrderRecord.getOriginalEdi().toString());
413         }
414         List messages = new ArrayList();
415         messages.add("isbnCheckFailed");
416         oleOrderRecord.addMessageToMap("message", messages);
417         if (oleOrderRecord.getMessageMap() != null) {
418             for (Map.Entry<String, Object> entry : oleOrderRecord.getMessageMap().entrySet()) {
419                 LOG.info(entry.getKey());
420                 LOG.info(entry.getValue().toString());
421             }
422         }
423         oleOrderRecord.setAgendaName("mockAgenda");
424         if (oleOrderRecord.getAgendaName() != null) {
425             LOG.info(oleOrderRecord.getAgendaName());
426         }
427         oleOrderRecord.setOriginalEDIFileName("ediFileName.edi");
428         if (oleOrderRecord.getOriginalEDIFileName() != null) {
429             LOG.info(oleOrderRecord.getOriginalEDIFileName());
430         }
431         oleOrderRecord.setOleOriginalBibRecordFileName("bib.mrc");
432         if (oleOrderRecord.getOleOriginalBibRecordFileName() != null) {
433             LOG.info(oleOrderRecord.getOriginalEDIFileName());
434         }
435         OleOrderRecord oleOrderRecord1 = new OleOrderRecord();
436         oleOrderRecord1.setAgendaName("Agenda");
437         oleOrderRecord1.setOriginalEDIFileName("edifile");
438         oleOrderRecord1.setOleOriginalBibRecordFileName("bibfile");
439         oleOrderRecord1.addMessageToMap("messages", messages);
440         OleBibRecord oleBibRecord1 = new OleBibRecord();
441         oleBibRecord1.setBibUUID("123456789");
442         oleBibRecord.setLinkedInstanceId("123213");
443         HashMap bibAssociatedFieldsValueMap1 = new HashMap();
444         bibAssociatedFieldsValueMap1.put("author1", "mock_author1");
445         bibAssociatedFieldsValueMap1.put("title1", "mock_title1");
446         oleBibRecord1.setBibAssociatedFieldsValueMap(bibAssociatedFieldsValueMap1);
447         OleTxRecord oleTxRecord1 = new OleTxRecord();
448         oleTxRecord1.setAccountNumber("56789");
449         oleOrderRecord1.setOleBibRecord(oleBibRecord1);
450         oleOrderRecord1.setOleTxRecord(oleTxRecord1);
451         oleOrderRecord.setDescription("Description");
452         oleOrderRecord1.setDescription("Descrip");
453         if (oleOrderRecord.getDescription() != null) {
454             LOG.info(oleOrderRecord.getDescription());
455         }
456 
457         BibMarcRecord bibMarcRecord1 = new BibMarcRecord();
458         bibMarcRecord1.setLeader("kennedy");
459        oleOrderRecord1.setOriginalRecord(bibMarcRecord1);
460         EDIOrder eDIOrder1 = new EDIOrder();
461         MessageHeader messageHeader1 = new MessageHeader();
462         messageHeader1.setInterchangeControlReference("reference");
463         eDIOrder1.setMessageHeader(messageHeader1);
464         oleOrderRecord1.setOriginalEdi(eDIOrder1);
465         LOG.info(String.valueOf(oleOrderRecord1.hashCode()));
466         OleOrderRecords record = new OleOrderRecords();
467         List<OleOrderRecord> records = new ArrayList<OleOrderRecord>();
468 
469         records.add(oleOrderRecord);
470         records.add(oleOrderRecord1);
471         record.setRecords(records);
472 
473         String xml = oleOrderRecordHandler.toXML(record);
474         LOG.info(xml);
475 
476         //for testing hashcode and equals in OleOrderRecord
477 
478         OleOrderRecord oleOrderRecord2 = new OleOrderRecord();
479         oleOrderRecord2.setAgendaName("Agenda");
480         oleOrderRecord2.setOriginalEDIFileName("edifile");
481         oleOrderRecord2.setOleOriginalBibRecordFileName("bibfile");
482         oleOrderRecord2.addMessageToMap("messages", messages);
483         oleOrderRecord2.setOleBibRecord(oleBibRecord1);
484         oleOrderRecord2.setOleTxRecord(oleTxRecord1);
485         oleOrderRecord2.setDescription("Descrip");
486         oleOrderRecord2.setOriginalRecord(bibMarcRecord1);
487         oleOrderRecord2.setOriginalEdi(eDIOrder1);
488         if (oleOrderRecord1.equals(oleOrderRecord2)) {
489             LOG.info("Objects are equal");
490         }
491 
492     }
493 }