View Javadoc
1   package org.kuali.ole;
2   
3   import org.junit.Test;
4   import org.kuali.ole.converter.OLEEDIConverter;
5   import org.kuali.ole.converter.OLEINVConverter;
6   import org.kuali.ole.docstore.xstream.FileUtil;
7   import org.kuali.ole.pojo.edi.EDIOrder;
8   import org.kuali.ole.pojo.edi.EDIOrders;
9   import org.kuali.ole.pojo.edi.INVOrder;
10  import org.kuali.ole.pojo.edi.INVOrders;
11  import org.slf4j.Logger;
12  import org.slf4j.LoggerFactory;
13  
14  import java.io.File;
15  import java.net.URL;
16  import java.util.Iterator;
17  
18  import static junit.framework.Assert.assertNotNull;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: palanivel
23   * Date: 7/8/13
24   * Time: 8:13 PM
25   * To change this template use File | Settings | File Templates.
26   */
27  public class OleInvoiceRecordBuilder_UT {
28  
29      protected static final Logger LOG = LoggerFactory.getLogger(OleInvoiceRecordBuilder_UT.class);
30  
31      @Test
32      public void testBuild() throws Exception {
33          OLEINVConverter OLEEDITranslator = new OLEINVConverter();
34          assertNotNull(OLEEDITranslator);
35          URL ediResource = getClass().getResource("R032713.T102543.INV");
36          File ediFile = new File(ediResource.toURI());
37          String fileContent = new FileUtil().readFile(ediFile);
38          String javaResult = OLEEDITranslator.convertToXML(fileContent);
39  
40          System.out.println("Invoice XML-----------------" + javaResult);
41  
42  
43      }
44  
45  
46      /**
47       * This method is used to generate POJOS from XML.
48       *
49       * @throws Exception
50       */
51      @Test
52      public void testGenerateXMLToPojos() throws Exception {
53          OLEINVConverter OLEEDITranslator = new OLEINVConverter();
54          assertNotNull(OLEEDITranslator);
55          URL ediResource = getClass().getResource("R032713.T102543.INV");
56          File ediFile = new File(ediResource.toURI());
57          String fileContent = new FileUtil().readFile(ediFile);
58          String xml = OLEEDITranslator.convertToXML(fileContent);
59  
60          OLETranscationalRecordGenerator oleTranscationalRecordGenerator = new OLETranscationalRecordGenerator();
61          INVOrders invOrders = oleTranscationalRecordGenerator.fromInvoiceXml(xml);
62  
63          for (Iterator<INVOrder> iterator = invOrders.getInvOrder().iterator(); iterator.hasNext(); ) {
64              INVOrder invOrder = iterator.next();
65              LOG.info("==============Object Message Out=============");
66              LOG.info(invOrders.getSenderAndReceiver().getSendersAndReceiversConstant().getCode());
67              LOG.info(invOrders.getSenderAndReceiver().getSenderInformation().getSenderId());
68              LOG.info(invOrders.getSenderAndReceiver().getReceiverInformation().getReceiverId());
69              LOG.info(invOrders.getSenderAndReceiver().getSchedule().getPreparationDate());
70              LOG.info(invOrders.getSenderAndReceiver().getInterChangeControlReference());
71              LOG.info("======================================\n\n");
72          }
73      }
74  }