001package org.kuali.ole;
002
003import org.kuali.ole.pojo.edi.*;
004
005import java.util.Arrays;
006
007/**
008 * Created by IntelliJ IDEA.
009 * User: palanivel
010 * Date: 3/7/12
011 * Time: 8:05 PM
012 * To change this template use File | Settings | File Templates.
013 */
014public class EDIOrderFixture {
015
016    public SenderAndReceiver createSenderAndReceiver(Class clazz) {
017        SenderAndReceiver senderAndReceiver = null;
018        try {
019            senderAndReceiver = (SenderAndReceiver) clazz.newInstance();
020        } catch (InstantiationException e) {
021            throw new RuntimeException("SenderAndReceiver creation failed. class = " + clazz);
022        } catch (IllegalAccessException e) {
023            throw new RuntimeException("SenderAndReceiver creation failed. class = " + clazz);
024        }
025        senderAndReceiver.setSendersAndReceiversConstant(SendersAndReceiverFixture.SendersAndReceiversConstant.
026                createSenderAndReceiverConstant(SendersAndReceiversConstant.class));
027        senderAndReceiver.setSenderInformation(SendersAndReceiverFixture.SenderInformation.
028                createSenderInformation(SenderInformation.class));
029        senderAndReceiver.setReceiverInformation(SendersAndReceiverFixture.ReceiverInformation.
030                createReceiverInformation(ReceiverInformation.class));
031        senderAndReceiver.setSchedule(SendersAndReceiverFixture.Schedule.
032                createSchedule(Schedule.class));
033        senderAndReceiver.setInterChangeControlReference(SendersAndReceiverFixture.InterchangeControlReference.
034                createInterchangeControlReference());
035
036        return senderAndReceiver;
037    }
038
039    public MessageHeader createMessageHeader(Class clazz) {
040        MessageHeader messageHeader = null;
041        try {
042            messageHeader = (MessageHeader) clazz.newInstance();
043        } catch (InstantiationException e) {
044            throw new RuntimeException("MessageHeader creation failed. class = " + clazz);
045        } catch (IllegalAccessException e) {
046            throw new RuntimeException("MessageHeader creation failed. class = " + clazz);
047        }
048        messageHeader.setMesssageTypeInformation(MessageHeaderFixture.MesssageTypeInformation.
049                createMesssageTypeInformation(MesssageTypeInformation.class));
050        messageHeader.setInterchangeControlReference(MessageHeaderFixture.InterChangeControlRef.
051                createInterchangeControlReference());
052
053        return messageHeader;
054    }
055
056    public Message createMessage(Class clazz) {
057        Message message = null;
058        try {
059            message = (Message) clazz.newInstance();
060        } catch (InstantiationException e) {
061            throw new RuntimeException("Message creation failed. class = " + clazz);
062        } catch (IllegalAccessException e) {
063            throw new RuntimeException("Message creation failed. class = " + clazz);
064        }
065        message.setMessageBeginning(MessageFixture.MessageBeginning.
066                createMessageBeginningPojo(MessageBeginning.class));
067        message.setMessageCreationInformation(MessageFixture.MessageCreationInformation.
068                createMessageCreationInformationPojo(MessageCreationInformation.class));
069        message.setBuyerPartyQualifier(MessageFixture.BuyerPartyQualifier.
070                createBuyerPartyQualifierPojo(BuyerPartyQualifier.class));
071        message.setMessageReference(MessageFixture.MessageReference.
072                createMessageReferencePojo(MessageReference.class));
073        message.setSupplierPartyQualifier(MessageFixture.SupplierPartyQualifier.
074                createSupplierPartyQualifierPojo(SupplierPartyQualifier.class));
075        message.setCurrencyDetails(MessageFixture.CurrencyDetails.
076                createCurrencyDetailsPojo(CurrencyDetails.class));
077
078        return message;
079    }
080
081    public LineItemOrder createLineItemOrder(Class clazz) {
082        LineItemOrder lineItemOrder = null;
083        try {
084            lineItemOrder = (LineItemOrder) clazz.newInstance();
085        } catch (InstantiationException e) {
086            throw new RuntimeException("LineItemOrder creation failed. class = " + clazz);
087        } catch (IllegalAccessException e) {
088            throw new RuntimeException("LineItemOrder creation failed. class = " + clazz);
089        }
090        lineItemOrder.addLineItem(LineItemOrderFixture.LINEITEM.createLineItemPojo(LineItem.class));
091        lineItemOrder.addProductFunction(LineItemOrderFixture.PRODUCTFUNCTION.createProductFunctionPojo(ProductFunction.class));
092        lineItemOrder.addItemDescription(LineItemOrderFixture.ITEMDESCRIPTION.createItemDescriptionPojo(ItemDescription.class));
093        lineItemOrder.addQuantityInformation(LineItemOrderFixture.QUANTITYINFORMATION.createQuantityInformationPojo(QuantityInformation.class));
094        lineItemOrder.addPriceInformation(LineItemOrderFixture.PRICEINFORMATION.createPriceInformationPojo(PriceInformation.class));
095        lineItemOrder.addBuyerReferenceInformation(LineItemOrderFixture.REFERENCEINFORMATION.createBuyerReferenceInformationPojo(BuyerReferenceInformation.class));
096        lineItemOrder.addSupplierReferenceInformation(LineItemOrderFixture.SUPPLIERSREFERENCEINFORMATION.createSupplierReferenceInformationPojo(SupplierReferenceInformation.class));
097        lineItemOrder.addFundNumberReference(LineItemOrderFixture.FUNDNUMBERREFERENCE.createFundNumberReferencePojo(FundNumberReference.class));
098        lineItemOrder.addTransportStageQualifier(LineItemOrderFixture.TRANSPORTSTAGEQUALIFIER.createTransportStageQualifierPojo(TransportStageQualifier.class));
099        return lineItemOrder;
100    }
101
102    public Summary createSummaryOrder(Class clazz) {
103        Summary summary = null;
104        try {
105            summary = (Summary) clazz.newInstance();
106        } catch (InstantiationException e) {
107            throw new RuntimeException("Summary creation failed. class = " + clazz);
108        } catch (IllegalAccessException e) {
109            throw new RuntimeException("Summary creation failed. class = " + clazz);
110        }
111        summary.setSummarySection(SummaryFixture.SUMMARYSECTION.createSummarySectionPojo(SummarySection.class));
112        summary.addControlInfomation(SummaryFixture.CONTROLINFORMATION.createControlInfomationPojo(ControlInfomation.class));
113        summary.setUntSummary(SummaryFixture.UNT.createUNTSummaryPojo(UNTSummary.class));
114        return summary;
115    }
116}
117
118