001package org.kuali.ole; 002 003import org.junit.Test; 004import org.kuali.ole.converter.OLEEDIConverter; 005import org.kuali.ole.converter.OLEINVConverter; 006import org.kuali.ole.docstore.xstream.FileUtil; 007import org.kuali.ole.pojo.edi.EDIOrder; 008import org.kuali.ole.pojo.edi.EDIOrders; 009import org.kuali.ole.pojo.edi.INVOrder; 010import org.kuali.ole.pojo.edi.INVOrders; 011import org.slf4j.Logger; 012import org.slf4j.LoggerFactory; 013 014import java.io.File; 015import java.net.URL; 016import java.util.Iterator; 017 018import static junit.framework.Assert.assertNotNull; 019 020/** 021 * Created with IntelliJ IDEA. 022 * User: palanivel 023 * Date: 7/8/13 024 * Time: 8:13 PM 025 * To change this template use File | Settings | File Templates. 026 */ 027public class OleInvoiceRecordBuilder_UT { 028 029 protected static final Logger LOG = LoggerFactory.getLogger(OleInvoiceRecordBuilder_UT.class); 030 031 @Test 032 public void testBuild() throws Exception { 033 OLEINVConverter OLEEDITranslator = new OLEINVConverter(); 034 assertNotNull(OLEEDITranslator); 035 URL ediResource = getClass().getResource("R032713.T102543.INV"); 036 File ediFile = new File(ediResource.toURI()); 037 String fileContent = new FileUtil().readFile(ediFile); 038 String javaResult = OLEEDITranslator.convertToXML(fileContent); 039 040 System.out.println("Invoice XML-----------------" + javaResult); 041 042 043 } 044 045 046 /** 047 * This method is used to generate POJOS from XML. 048 * 049 * @throws Exception 050 */ 051 @Test 052 public void testGenerateXMLToPojos() throws Exception { 053 OLEINVConverter OLEEDITranslator = new OLEINVConverter(); 054 assertNotNull(OLEEDITranslator); 055 URL ediResource = getClass().getResource("R032713.T102543.INV"); 056 File ediFile = new File(ediResource.toURI()); 057 String fileContent = new FileUtil().readFile(ediFile); 058 String xml = OLEEDITranslator.convertToXML(fileContent); 059 060 OLETranscationalRecordGenerator oleTranscationalRecordGenerator = new OLETranscationalRecordGenerator(); 061 INVOrders invOrders = oleTranscationalRecordGenerator.fromInvoiceXml(xml); 062 063 for (Iterator<INVOrder> iterator = invOrders.getInvOrder().iterator(); iterator.hasNext(); ) { 064 INVOrder invOrder = iterator.next(); 065 LOG.info("==============Object Message Out============="); 066 LOG.info(invOrders.getSenderAndReceiver().getSendersAndReceiversConstant().getCode()); 067 LOG.info(invOrders.getSenderAndReceiver().getSenderInformation().getSenderId()); 068 LOG.info(invOrders.getSenderAndReceiver().getReceiverInformation().getReceiverId()); 069 LOG.info(invOrders.getSenderAndReceiver().getSchedule().getPreparationDate()); 070 LOG.info(invOrders.getSenderAndReceiver().getInterChangeControlReference()); 071 LOG.info("======================================\n\n"); 072 } 073 } 074}