This is an automated email from the ASF dual-hosted git repository.
akashjain pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new cb3b99b Improved: Convert ShipmentTests.xml to Groovy (OFBIZ-11850) cb3b99b is described below commit cb3b99b9d5a977a134f30c0155f9fc13fb488e56 Author: Akash Jain <[hidden email]> AuthorDate: Tue Jul 7 11:37:45 2020 +0530 Improved: Convert ShipmentTests.xml to Groovy (OFBIZ-11850) --- .../minilang/shipment/test/ShipmentTests.xml | 218 --------------------- .../org/apache/ofbiz/product/ShipmentTests.groovy | 203 +++++++++++++++++++ applications/product/testdef/FacilityTest.xml | 2 +- 3 files changed, 204 insertions(+), 219 deletions(-) diff --git a/applications/product/minilang/shipment/test/ShipmentTests.xml b/applications/product/minilang/shipment/test/ShipmentTests.xml deleted file mode 100644 index e0d475e..0000000 --- a/applications/product/minilang/shipment/test/ShipmentTests.xml +++ /dev/null @@ -1,218 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd"> - <simple-method method-name="testPackingServices" short-description="test packing services" login-required="false"> - - <set field="packSingleItemInMap.productId" value="GZ-2644"/> - <set field="packSingleItemInMap.orderId" value="DEMO10090"/> - <set field="packSingleItemInMap.shipGroupSeqId" value="00001"/> - <set field="packSingleItemInMap.quantity" value="2" type="BigDecimal"/> - <set field="packSingleItemInMap.packageSeq" value="1" type="Integer"/> - <set field="packSingleItemInMap.pickerPartyId" value="DemoCustomer"/> - <set field="packSingleItemInMap.handlingInstructions" value="Handle with care"/> - <entity-one entity-name="UserLogin" value-field="userLogin" auto-field-map="false"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <set field="packSingleItemInMap.userLogin" from-field="userLogin"/> - <create-object class-name="org.apache.ofbiz.shipment.packing.PackingSession" field="packingSession"> - <field field="dispatcher" type="org.apache.ofbiz.service.LocalDispatcher"/> - <field field="userLogin" type="org.apache.ofbiz.entity.GenericValue"/> - </create-object> - <set field="packSingleItemInMap.packingSession" from-field="packingSession"/> - <call-service service-name="packSingleItem" in-map-name="packSingleItemInMap"> - <results-to-map map-name="packSingleItemOutMap"/> - </call-service> - - <log level="info" message="=====packSingleItemOutMap========${packSingleItemOutMap}========="/> - - <set field="packBulkItemInMap.updateQuantity" value="Y" type="Boolean"/> - <set field="packBulkItemInMap.orderId" value="DEMO10090"/> - <set field="packBulkItemInMap.shipGroupSeqId" value="00001"/> - <set field="packBulkItemInMap.pickerPartyId" value="DemoCustomer"/> - <set field="packBulkItemInMap.handlingInstructions" value="Handle with care"/> - <set field="packBulkItemInMap.nextPackageSeq" value="1" type="Integer"/> - <set field="packBulkItemInMap.userLogin" from-field="userLogin"/> - <set field="packBulkItemInMap.packingSession" from-field="packingSession"/> - - <call-service service-name="packBulkItems" in-map-name="packBulkItemInMap"> - <results-to-map map-name="packBulkItemsResponseMap"/> - </call-service> - - <log level="info" message="=====packBulkItemsResponseMap=======${packBulkItemsResponseMap}======"/> - - <set field="completePackInMap.orderId" value="DEMO10090"/> - <set field="completePackInMap.packingSession" from-field="packingSession"/> - <set field="completePackInMap.handlingInstructions" value="Handle with care"/> - <set field="completePackInMap.pickerPartyId" value="DemoCustomer"/> - <set field="completePackInMap.additionalShippingCharge" value="10.0" type="BigDecimal"/> - <set field="completePackInMap.forceComplete" value="Y" type="Boolean"/> - <set field="completePackInMap.userLogin" from-field="userLogin"/> - - <call-service service-name="completePack" in-map-name="completePackInMap"> - <results-to-map map-name="completePackOutMap"/> - </call-service> - - <log level="info" message="=======ShipmentId=======${completePackOutMap.shipmentId}===="/> - - <entity-one entity-name="Shipment" value-field="shipment"> - <field-map field-name="shipmentId" from-field="completePackOutMap.shipmentId"/> - </entity-one> - - <assert> - <not><if-empty field="shipment"/></not> - <if-compare-field field="shipment.shipmentId" to-field="completePackOutMap.shipmentId" operator="equals"/> - </assert> - <check-errors/> - - <set field="createInvFrmShipmentInMap.shipmentId" value="${completePackOutMap.shipmentId}"/> - <set field="createInvFrmShipmentInMap.userLogin" from-field="userLogin"/> - <call-service service-name="createInvoicesFromShipment" in-map-name="createInvFrmShipmentInMap"> - <results-to-map map-name="createInvFrmShipmentOutMap"/> - </call-service> - - <log level="info" message="=============createInvFrmShipmentOutMap===========${createInvFrmShipmentOutMap}====="/> - - <set field="invoicesCreated" from-field="createInvFrmShipmentOutMap.invoicesCreated"/> - <iterate list="invoicesCreated" entry="invoiceCreated"> - <entity-one entity-name="Invoice" value-field="invoice"> - <field-map field-name="invoiceId" from-field="invoiceCreated"/> - </entity-one> - - <assert> - <not><if-empty field="invoice"/></not> - </assert> - <check-errors/> - </iterate> - - <log level="info" message="=============Test case completed===================================="/> - - </simple-method> - - <simple-method method-name="testShipmentServices" short-description="test shipment services" login-required="false"> - <set field="createShipmentInMap.shipmentTypeId" value="SALES_SHIPMENT"/> - <set field="createShipmentInMap.statusId" value="SHIPMENT_INPUT"/> - <set field="createShipmentInMap.primaryOrderId" value="DEMO10090"/> - <set field="createShipmentInMap.partyIdTo" value="DemoCustomer"/> - <set field="createShipmentInMap.originFacilityId" value="WebStoreWarehouse"/> - <entity-one entity-name="UserLogin" value-field="userLogin" auto-field-map="false"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <set field="createShipmentInMap.userLogin" from-field="userLogin"/> - - <call-service service-name="createShipment" in-map-name="createShipmentInMap"> - <results-to-map map-name="createShipmentOutMap"/> - </call-service> - - <log level="info" message="==========Shipment Id============${createShipmentOutMap.shipmentId}=========="/> - - <set field="updateShipmentInMap.shipmentId" from-field="createShipmentOutMap.shipmentId"/> - <set field="updateShipmentInMap.statusId" value="SHIPMENT_PACKED"/> - <set field="updateShipmentInMap.userLogin" from-field="userLogin"/> - <call-service service-name="updateShipment" in-map-name="updateShipmentInMap"> - <results-to-map map-name="updateShipmentOutMap"/> - </call-service> - - <set field="updateShipmentInMap.shipmentId" from-field="createShipmentOutMap.shipmentId"/> - <set field="updateShipmentInMap.statusId" value="SHIPMENT_SHIPPED"/> - <set field="updateShipmentInMap.userLogin" from-field="userLogin"/> - <call-service service-name="updateShipment" in-map-name="updateShipmentInMap"> - <results-to-map map-name="updateShipmentOutMap"/> - </call-service> - <log level="info" message="=============Update Shipment Id=============${updateShipmentOutMap.shipmentId}========================="/> - - <entity-one entity-name="Shipment" value-field="shipment"> - <field-map field-name="shipmentId" from-field="updateShipmentOutMap.shipmentId"/> - </entity-one> - - <assert> - <not><if-empty field="shipment"/></not> - <if-compare-field field="shipment.shipmentId" to-field="updateShipmentOutMap.shipmentId" operator="equals"/> - <if-compare-field field="shipment.statusId" to-field="updateShipmentInMap.statusId" operator="equals"/> - </assert> - <check-errors/> - <log level="info" message="=============Test case completed===================================="/> - </simple-method> - - <simple-method method-name="testReceiveInventoryNonSerialized" short-description="Test Receive Non-Serialized Inventory" login-required="false"> - <now-timestamp field="nowTimeStamp"/> - <entity-one entity-name="UserLogin" value-field="userLogin"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <set field="serviceCtx.userLogin" from-field="userLogin"/> - <set field="serviceCtx.facilityId" value="WebStoreWarehouse"/> - <set field="serviceCtx.productId" value="GZ-2644"/> - <set field="serviceCtx.quantityAccepted" value="5" type="BigDecimal"/> - <set field="serviceCtx.quantityRejected" value="0" type="BigDecimal"/> - <set field="serviceCtx.unitCost" value="24" type="BigDecimal"/> - <set field="serviceCtx.inventoryItemTypeId" value="NON_SERIAL_INV_ITEM"/> - <set field="serviceCtx.datetimeReceived" from-field="nowTimeStamp"/> - <call-service service-name="receiveInventoryProduct" in-map-name="serviceCtx"> - <result-to-field field="inventoryItemId" result-name="inventoryItemId"/> - </call-service> - - <entity-one entity-name="InventoryItem" value-field="inventoryItem"/> - <get-related value-field="inventoryItem" relation-name="InventoryItemDetail" list="inventoryItemDetails"/> - <entity-condition entity-name="ShipmentReceipt" list="shipmentReceipts"> - <condition-expr field-name="inventoryItemId" from-field="inventoryItemId"/> - <order-by field-name="datetimeReceived"/> - </entity-condition> - <first-from-list list="shipmentReceipts" entry="shipmentReceipt"/> - <assert> - <not><if-empty field="inventoryItem"></if-empty></not> - <not><if-empty field="inventoryItemDetails"></if-empty></not> - <not><if-empty field="shipmentReceipt"></if-empty></not> - <if-compare-field field="inventoryItem.productId" operator="equals" to-field="serviceCtx.productId"/> - <if-compare-field field="inventoryItem.facilityId" operator="equals" to-field="serviceCtx.facilityId"/> - <if-compare-field field="inventoryItem.quantityOnHandTotal" operator="equals" to-field="serviceCtx.quantityAccepted"/> - <if-compare-field field="inventoryItem.availableToPromiseTotal" operator="equals" to-field="serviceCtx.quantityAccepted"/> - <if-compare-field field="shipmentReceipt.quantityAccepted" operator="equals" to-field="serviceCtx.quantityAccepted"/> - <if-compare-field field="shipmentReceipt.productId" operator="equals" to-field="serviceCtx.productId"/> - </assert> - <check-errors/> - </simple-method> - - <simple-method method-name="testCreateShipmentRouteSegment" short-description="Test to create Shipment Route Segment" login-required="false"> - <log level="info" message="====================Create a Shipment Route Segment test case=========================================="/> - <entity-and entity-name="Shipment" list="shipments"> - <field-map field-name="primaryOrderId" value="DEMO10090"/> - <field-map field-name="shipmentId" value="9998"/> - </entity-and> - <first-from-list list="shipments" entry="shipment"/> - <set field="shipRouteSegMap.shipmentId" from-field="shipment.shipmentId"/> - <entity-one entity-name="UserLogin" value-field="shipRouteSegMap.userLogin"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <call-service service-name="createShipmentRouteSegment" in-map-name="shipRouteSegMap"> - <result-to-field result-name="shipmentRouteSegmentId" field="routeSegMap.shipmentRouteSegmentId"/> - </call-service> - <entity-one entity-name="ShipmentRouteSegment" value-field="shipmentRouteSegment"> - <field-map field-name="shipmentId" from-field="shipRouteSegMap.shipmentId"/> - <field-map field-name="shipmentRouteSegmentId" from-field="routeSegMap.shipmentRouteSegmentId"/> - </entity-one> - <assert> - <not><if-empty field="shipmentRouteSegment"/></not> - <if-compare-field field="shipmentRouteSegment.shipmentId" to-field="shipRouteSegMap.shipmentId" operator="equals"/> - <if-compare-field field="shipmentRouteSegment.shipmentRouteSegmentId" to-field="routeSegMap.shipmentRouteSegmentId" operator="equals"/> - </assert> - <check-errors/> - </simple-method> -</simple-methods> diff --git a/applications/product/src/main/groovy/org/apache/ofbiz/product/ShipmentTests.groovy b/applications/product/src/main/groovy/org/apache/ofbiz/product/ShipmentTests.groovy new file mode 100644 index 0000000..e5de18e --- /dev/null +++ b/applications/product/src/main/groovy/org/apache/ofbiz/product/ShipmentTests.groovy @@ -0,0 +1,203 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.apache.ofbiz.product + +import org.apache.ofbiz.base.util.UtilDateTime +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.service.ServiceUtil +import org.apache.ofbiz.service.testtools.OFBizTestCase +import org.apache.ofbiz.shipment.packing.PackingSession + +class ShipmentTests extends OFBizTestCase { + public ShipmentTests(String name) { + super(name) + } + + void testPackingServices() { + PackingSession packingSession = new PackingSession(dispatcher, userLogin) + Map serviceCtx = [ + productId: 'GZ-2644', + orderId: 'DEMO10090', + shipGroupSeqId: '00001', + quantity: new BigDecimal('2'), + packageSeq: 1, + pickerPartyId: 'DemoCustomer', + handlingInstructions: 'Handle with care', + packingSession: packingSession, + userLogin: userLogin + ] + + Map serviceResult = dispatcher.runSync('packSingleItem', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + serviceCtx.clear() + serviceResult.clear() + serviceCtx = [ + updateQuantity: true, + orderId: 'DEMO10090', + shipGroupSeqId: '00001', + pickerPartyId: 'DemoCustomer', + handlingInstructions: 'Handle with care', + nextPackageSeq: 1, + packingSession: packingSession, + userLogin: userLogin + ] + serviceResult = dispatcher.runSync('packBulkItems', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + serviceCtx.clear() + serviceResult.clear() + serviceCtx = [ + orderId: 'DEMO10090', + pickerPartyId: 'DemoCustomer', + handlingInstructions: 'Handle with care', + packingSession: packingSession, + additionalShippingCharge: new BigDecimal('10'), + forceComplete: true, + userLogin: userLogin + ] + serviceResult = dispatcher.runSync('completePack', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + String shipmentId = serviceResult.shipmentId + assert shipmentId + + GenericValue shipment = from('Shipment') + .where('shipmentId', shipmentId) + .queryOne() + assert shipment + + serviceCtx.clear() + serviceResult.clear() + serviceCtx = [ + shipmentId: shipmentId, + userLogin: userLogin + ] + serviceResult = dispatcher.runSync('createInvoicesFromShipment', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + List invoicesCreated = serviceResult.invoicesCreated + assert shipmentId + + for (String invoiceId : invoicesCreated) { + GenericValue invoice = from('Invoice') + .where('invoiceId', invoiceId) + .queryOne() + assert invoice + } + } + + void testShipmentServices() { + Map serviceCtx = [ + shipmentTypeId: 'SALES_SHIPMENT', + statusId: 'SHIPMENT_INPUT', + primaryOrderId: 'DEMO10090', + partyIdTo: 'DemoCustomer', + originFacilityId: 'WebStoreWarehouse', + userLogin: userLogin + ] + + Map serviceResult = dispatcher.runSync('createShipment', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + String shipmentId = serviceResult.shipmentId + assert shipmentId + + serviceCtx.clear() + serviceResult.clear() + serviceCtx = [ + shipmentId: shipmentId, + statusId: 'SHIPMENT_PACKED', + userLogin: userLogin + ] + serviceResult = dispatcher.runSync('updateShipment', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + serviceCtx.statusId = 'SHIPMENT_SHIPPED' + serviceResult = dispatcher.runSync('updateShipment', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + GenericValue shipment = from('Shipment') + .where('shipmentId', shipmentId) + .queryOne() + assert shipment + assert 'SHIPMENT_SHIPPED'.equals(shipment.statusId) + } + + void testReceiveInventoryNonSerialized() { + Map serviceCtx = [ + facilityId: 'WebStoreWarehouse', + productId: 'GZ-2644', + quantityAccepted: new BigDecimal('2'), + quantityRejected: BigDecimal.ZERO, + unitCost: new BigDecimal('24'), + inventoryItemTypeId: 'NON_SERIAL_INV_ITEM', + datetimeReceived: UtilDateTime.nowTimestamp(), + userLogin: userLogin + ] + + Map serviceResult = dispatcher.runSync('receiveInventoryProduct', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + String inventoryItemId = serviceResult.inventoryItemId + assert inventoryItemId + + GenericValue inventoryItem = from('InventoryItem') + .where('inventoryItemId', inventoryItemId) + .queryOne() + assert inventoryItem + assert inventoryItem.productId.equals(serviceCtx.productId) + assert inventoryItem.facilityId.equals(serviceCtx.facilityId) + assert inventoryItem.quantityOnHandTotal.compareTo(serviceCtx.quantityAccepted) == 0 + assert inventoryItem.availableToPromiseTotal.compareTo(serviceCtx.quantityAccepted) == 0 + + List inventoryItemDetails = from('InventoryItemDetail') + .where('inventoryItemId', inventoryItemId) + .queryList() + assert inventoryItemDetails + + GenericValue shipmentReceipt = from('ShipmentReceipt') + .where('inventoryItemId', inventoryItemId) + .orderBy('datetimeReceived').queryFirst() + assert shipmentReceipt + assert shipmentReceipt.quantityAccepted.compareTo(serviceCtx.quantityAccepted) == 0 + assert shipmentReceipt.productId.equals(serviceCtx.productId) + } + + void testCreateShipmentRouteSegment() { + GenericValue shipment = from('Shipment') + .where('shipmentId', '9998') + .queryOne() + assert shipment + + Map serviceCtx = [ + shipmentId: shipment.shipmentId, + shipmentRouteSegmentId: '0001', + userLogin: userLogin + ] + Map serviceResult = dispatcher.runSync('createShipmentRouteSegment', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + String shipmentRouteSegmentId = serviceResult.shipmentRouteSegmentId + assert shipmentRouteSegmentId + + GenericValue shipmentRouteSegment = from('ShipmentRouteSegment') + .where('shipmentId', shipment.shipmentId, 'shipmentRouteSegmentId', shipmentRouteSegmentId) + .queryOne() + assert shipmentRouteSegment + assert '9998'.equals(shipmentRouteSegment.shipmentId) + assert shipmentRouteSegment.shipmentRouteSegmentId.equals(shipmentRouteSegmentId) + } +} \ No newline at end of file diff --git a/applications/product/testdef/FacilityTest.xml b/applications/product/testdef/FacilityTest.xml index 8dcf21c..c0c58d9 100644 --- a/applications/product/testdef/FacilityTest.xml +++ b/applications/product/testdef/FacilityTest.xml @@ -32,7 +32,7 @@ under the License. </test-case> <test-case case-name="shipment-tests"> - <simple-method-test location="component://product/minilang/shipment/test/ShipmentTests.xml"/> + <junit-test-suite class-name="org.apache.ofbiz.product.ShipmentTests"/> </test-case> <test-case case-name="loadIssuanceTestData"> |
Free forum by Nabble | Edit this page |