package org.ofbiz.order.test; import java.util.ArrayList; import java.util.List; import java.util.Map; import javolution.util.FastMap; import junit.framework.TestCase; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.DelegatorFactory; import org.ofbiz.entity.GenericValue; import org.ofbiz.service.GenericDispatcher; import org.ofbiz.service.LocalDispatcher; public class PurchaseOrderTest extends TestCase { protected LocalDispatcher dispatcher = null; protected Delegator delegator = null; protected GenericValue userLogin = null; protected String orderId = null; protected String statusId = null; public PurchaseOrderTest(String name) { super(name); } protected void setUp() throws Exception { delegator = DelegatorFactory.getDelegator("test"); dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator); userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system")); } protected void tearDown() throws Exception { } public void testCreatePurchaseOrder() throws Exception { Map ctx = FastMap.newInstance(); ctx.put("partyId", "Company"); ctx.put("orderTypeId", "PURCHASE_ORDER"); ctx.put("currencyUom", "USD"); ctx.put("productStoreId","9001"); GenericValue orderItem = delegator.makeValue("OrderItem", UtilMisc.toMap("orderItemSeqId", "00001", "orderItemTypeId", "PRODUCT_ORDER_ITEM", "prodCatalogId", "DemoCatalog", "productId", "VUDUBX100", "quantity", new Double(2), "isPromo", "N")); orderItem.set("unitPrice", new Double(1399.5)); orderItem.set("unitListPrice", new Double(0)); orderItem.set("isModifiedPrice", "N"); orderItem.set("statusId", "ITEM_CREATED"); List orderItems = new ArrayList(); orderItems.add(orderItem); ctx.put("orderItems", orderItems); GenericValue orderContactMech = delegator.makeValue("OrderContactMech", UtilMisc.toMap("contactMechPurposeTypeId", "SHIPPING_LOCATION", "contactMechId", "10000")); List orderContactMechs = new ArrayList(); orderContactMechs.add(orderContactMech); ctx.put("orderContactMechs", orderContactMechs); GenericValue orderItemContactMech = delegator.makeValue("OrderItemContactMech", UtilMisc.toMap("contactMechPurposeTypeId", "SHIPPING_LOCATION", "contactMechId", "10000", "orderItemSeqId", "00001")); List orderItemContactMechs = new ArrayList(); orderItemContactMechs.add(orderItemContactMech); ctx.put("orderItemContactMechs", orderItemContactMechs); GenericValue orderItemShipGroup = delegator.makeValue("OrderItemShipGroup", UtilMisc.toMap("carrierPartyId", "UPS", "contactMechId", "10000", "isGift", "N", "maySplit", "N", "shipGroupSeqId", "00001", "shipmentMethodTypeId", "NEXTDAY")); orderItemShipGroup.set("carrierRoleTypeId","CARRIER"); List orderItemShipGroupInfo = new ArrayList(); orderItemShipGroupInfo.add(orderItemShipGroup); ctx.put("orderItemShipGroupInfo", orderItemShipGroupInfo); List orderTerms = new ArrayList(); ctx.put("orderTerms", orderTerms); List orderAdjustments = new ArrayList(); ctx.put("orderAdjustments", orderAdjustments); ctx.put("billToCustomerPartyId", "Company"); ctx.put("billFromVendorPartyId", "DemoSupplier"); ctx.put("shipFromVendorPartyId", "Company"); ctx.put("supplierAgentPartyId", "DemoSupplier"); ctx.put("userLogin", userLogin); Map resp = dispatcher.runSync("storeOrder", ctx); orderId = (String) resp.get("orderId"); statusId = (String) resp.get("statusId"); assertNotNull(orderId); assertNotNull(statusId); } }