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

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

commit a3068004a1423e5f3665396e2a756f5c8dda64f1
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          |  4 +-
 .../accounting/InvoicePerShipmentTests.groovy      | 47 ++++++++++------------
 .../org/apache/ofbiz/base/util/UtilProperties.java | 26 +++++++++++-
 3 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/applications/accounting/data/AccountingSystemPropertyData.xml 
b/applications/accounting/data/AccountingSystemPropertyData.xml
index 09464b9912..a24958112d 100644
--- a/applications/accounting/data/AccountingSystemPropertyData.xml
+++ b/applications/accounting/data/AccountingSystemPropertyData.xml
@@ -48,6 +48,6 @@ under the License.
     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..1fa57bd2ff 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,6 +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
@@ -142,49 +143,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