This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 4a5b0f829b0e834e70631a64e5b0c53cbe3d836e
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Tue Apr 5 17:44:28 2022 +0200

    Fixed: testInvoicePerShipmentSetFalse work with runtime configuration data 
(OFBIZ-12453)
    
    UtilProperties::setPropertyValueInMemory was only based on files. Thinking 
by
    analogy, as Pierre pushed SystemProperties with OFBIZ-6189, I thought that 
by
    adding an UtilProperties::setPropertyValueInMemory based on
    EntityUtilProperties::getProperties it would resolve the issue. But it did 
not.
    
    Looking closer at the code, I wondered why 
UtilProperties::setPropertyValueInMemory
    was used at all.
    
    This fixes the issue by simply removing setPropertyValueInMemory and 
setting "Y"
    or "N" when calling testInvoicePerShipment.
    
    It though keeps the new UtilProperties::setPropertyValueInMemory variant
---
 .../data/AccountingSystemPropertyData.xml          | 16 ++++----
 .../accounting/InvoicePerShipmentTests.groovy      | 48 ++++++++++------------
 .../org/apache/ofbiz/base/util/UtilProperties.java | 26 +++++++++++-
 3 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/applications/accounting/data/AccountingSystemPropertyData.xml 
b/applications/accounting/data/AccountingSystemPropertyData.xml
index 09464b9912..a08269121e 100644
--- a/applications/accounting/data/AccountingSystemPropertyData.xml
+++ b/applications/accounting/data/AccountingSystemPropertyData.xml
@@ -18,7 +18,7 @@ specific language governing permissions and limitations
 under the License.
 -->
 <entity-engine-xml>
-<!-- 
+<!--
 # what should the default of the payment to invoice processing be?
 # paymentProcessing by invoice or paymentprocessing by invoiceitem?
 # there is still a box on the menu to change this option by the user.
@@ -27,27 +27,27 @@ under the License.
 #value YY: do not show the option box to the user and do only invoice 
processing
 #value NN: do not show the option box to the user and do only invoiceitem 
processing
 -->
-    <SystemProperty systemResourceId="accounting" 
systemPropertyId="invoiceProcessing" 
+    <SystemProperty systemResourceId="accounting" 
systemPropertyId="invoiceProcessing"
     systemPropertyValue="YY"
     description="Options are: Y, N, YY, NN"
     />
 
-    <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.fixedasset.autocreate" 
+    <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.fixedasset.autocreate"
     systemPropertyValue="Y"
     description="Create a fixed asset when an 'asset usage' type product is 
created. Options: Y, N"/>
 
-    <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.payment.application.autocreate" 
+    <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.payment.application.autocreate"
     systemPropertyValue="Y"
     description="Create a payment application when a payment is received/sent 
or invoice is approved (take the oldest not closed one). Options: Y, N"/>
 
-   <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.payment.purchaseorder.autocreate" 
+   <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.payment.purchaseorder.autocreate"
     systemPropertyValue="Y"
     description="Create a 'not-paid' payment record if the purchase order is 
approved. Options: Y, N"/>
 
-    <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.payment.salesorder.autocreate" 
+    <SystemProperty systemResourceId="accounting" 
systemPropertyId="accounting.payment.salesorder.autocreate"
     systemPropertyValue="Y"
     description="Create a 'not-paid' payment record if the sales order is 
completed and no payment exist yet. Options:: Y, N"/>
 
-    <!-- <SystemProperty systemResourceId="accounting" 
systemPropertyId="create.invoice.per.shipment" systemPropertyValue="Y"
-    description="create invoice per shipment. Options: = Y (Invoice per 
shipment), N (Invoice per order)"/> -->
+    <SystemProperty systemResourceId="accounting" 
systemPropertyId="create.invoice.per.shipment" systemPropertyValue="Y"
+    description="create invoice per shipment. Options: = Y (Invoice per 
shipment), N (Invoice per order)"/>
 </entity-engine-xml>
diff --git 
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
 
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
index fe81f7db1e..55146ff581 100644
--- 
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
+++ 
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/InvoicePerShipmentTests.groovy
@@ -19,7 +19,7 @@
 package org.apache.ofbiz.accounting
 
 import javax.servlet.http.HttpSession
-import org.apache.ofbiz.base.util.UtilProperties
+
 import org.apache.ofbiz.base.util.UtilValidate
 import org.apache.ofbiz.entity.GenericValue
 import org.apache.ofbiz.order.shoppingcart.CheckOutEvents
@@ -142,49 +142,43 @@ public class InvoicePerShipmentTests extends 
OFBizTestCase {
     }
     void testInvoicePerShipmentSetFalse() {
         /* Test Invoice Per Shipment
-            Step 1) Set create.invoice.per.shipment=N in accounting.properties 
file.
-            Step 2) Create order and approve order.
-            Step 3) Pack Shipment For Ship Group.
-            Step 4) Check invoice should not created.
-        */
-        UtilProperties.setPropertyValueInMemory("accounting", 
"create.invoice.per.shipment", "N")
-        logInfo("===== >>> Set Accounting.properties / 
create.invoice.per.shipment = N")
-
-        List invoices = testInvoicePerShipment("GZ-1000", null)
+         Step 1) Set create.invoice.per.shipment=N in accounting.properties 
file.
+         Step 2) Create order and approve order.
+         Step 3) Pack Shipment For Ship Group.
+         Step 4) Check invoice should not created.
+         */
+        List invoices = testInvoicePerShipment("GZ-1000", "N")
         assert UtilValidate.isEmpty(invoices)
     }
 
     void testInvoicePerShipmentSetTrue() {
         /* Test Invoice Per Shipment
-             Step 1) Set create.invoice.per.shipment=Y in 
accounting.properties file.
-             Step 2) Create order and approve order.
-             Step 3) Pack Shipment For Ship Group.
-             Step 4) Check invoice should be created.
+         Step 1) Set create.invoice.per.shipment=Y in accounting.properties 
file.
+         Step 2) Create order and approve order.
+         Step 3) Pack Shipment For Ship Group.
+         Step 4) Check invoice should be created.
          */
-        UtilProperties.setPropertyValueInMemory("accounting", 
"create.invoice.per.shipment", "Y")
-        logInfo("===== >>> Set Accounting.properties / 
create.invoice.per.shipment = Y")
-
-        List invoices = testInvoicePerShipment("GZ-1000", null)
+        List invoices = testInvoicePerShipment("GZ-1000", "Y")
         assert UtilValidate.isNotEmpty(invoices)
     }
 
     void testInvoicePerShipmentSetOrderFalse() {
         /* Test Invoice Per Shipment
-            Step 1) Create order and set invoicePerShipment=N.
-            Step 2) Pack Shipment For Ship Group.
-            Step 3) Check invoice should not be created.
-        */
+         Step 1) Create order and set invoicePerShipment=N.
+         Step 2) Pack Shipment For Ship Group.
+         Step 3) Check invoice should not be created.
+         */
         List invoices = testInvoicePerShipment("GZ-2644", "N")
         assert UtilValidate.isEmpty(invoices)
     }
 
     void testInvoicePerShipmentSetOrderTrue() {
         /* Test Invoice Per Shipment
-            Step 1) Create order and set invoicePerShipment=Y
-            Step 2) Pack Shipment For Ship Group.
-            Step 3) Check invoice should be created.
-        */
+         Step 1) Create order and set invoicePerShipment=Y
+         Step 2) Pack Shipment For Ship Group.
+         Step 3) Check invoice should be created.
+         */
         List invoices = testInvoicePerShipment("GZ-2644", "Y")
         assert UtilValidate.isNotEmpty(invoices)
     }
-}
\ No newline at end of file
+}
diff --git 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
index 8b1f313ae7..5ac0897f26 100644
--- 
a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
+++ 
b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilProperties.java
@@ -46,6 +46,8 @@ import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.cache.UtilCache;
 import org.apache.ofbiz.base.util.collections.ResourceBundleMapWrapper;
 import org.apache.ofbiz.base.util.string.FlexibleStringExpander;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.util.EntityUtilProperties;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -501,7 +503,29 @@ public final class UtilProperties implements Serializable {
             return;
         }
 
-        Properties properties = getProperties(resource);
+        Properties properties = UtilProperties.getProperties(resource);
+        if (properties == null) {
+            return;
+        }
+        properties.setProperty(name, value);
+    }
+
+    /**
+     * Sets the specified value of the specified property name to the 
specified resource/properties in memory, does not persist it
+     * @param delegator Default delegator, mostly used in tests
+     * @param resource The name of the resource
+     * @param name     The name of the property in the resource
+     * @param value    The value of the property to set in memory
+     */
+    public static void setPropertyValueInMemory(Delegator delegator, String 
resource, String name, String value) {
+        if (UtilValidate.isEmpty(resource)) {
+            return;
+        }
+        if (UtilValidate.isEmpty(name)) {
+            return;
+        }
+
+        Properties properties = EntityUtilProperties.getProperties(delegator, 
resource);
         if (properties == null) {
             return;
         }

Reply via email to