You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2022/04/06 09:06:39 UTC

[ofbiz-framework] branch trunk updated (2aeb282cdc -> e5b0d63b65)

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

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


    from 2aeb282cdc Improved: Prevent Freemarker interpolation in fields (OFBIZ-12594)
     new a3068004a1 Fixed: testInvoicePerShipmentSetFalse work with runtime configuration data (OFBIZ-12453)
     new e5b0d63b65 Fixed: Prevent Freemarker interpolation in fields (OFBIZ-12594)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../data/AccountingSystemPropertyData.xml          |  4 +-
 .../accounting/InvoicePerShipmentTests.groovy      | 47 ++++++++++------------
 .../org/apache/ofbiz/base/util/UtilProperties.java | 26 +++++++++++-
 .../apache/ofbiz/webapp/control/ControlFilter.java |  1 +
 4 files changed, 49 insertions(+), 29 deletions(-)


[ofbiz-framework] 01/02: Fixed: testInvoicePerShipmentSetFalse work with runtime configuration data (OFBIZ-12453)

Posted by jl...@apache.org.
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 <ja...@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;
         }


[ofbiz-framework] 02/02: Fixed: Prevent Freemarker interpolation in fields (OFBIZ-12594)

Posted by jl...@apache.org.
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 e5b0d63b65f3640fe542884ab8f525edcbf7c7d7
Author: Jacques Le Roux <ja...@les7arts.com>
AuthorDate: Wed Apr 6 10:59:56 2022 +0200

    Fixed: Prevent Freemarker interpolation in fields (OFBIZ-12594)
    
    I did not catch an issue put in by this feature because BuildBot is not running
    for few days (see INFRA-23076) and i don't always run tests locally (relying on
    BuildBot and GH actions don't run tests).
    
    This is the error Solr tests throw else:
    <<Unfortunately, the stream was empty / not available. This may be caused by
    another servlet filter calling ServletRequest.getParameter*() before
    SolrDispatchFilter>>
---
 .../src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java     | 1 +
 1 file changed, 1 insertion(+)

diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
index 8c76628225..31c6fc78e1 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/ControlFilter.java
@@ -150,6 +150,7 @@ public class ControlFilter extends HttpFilter {
             String uri = uriWithContext.substring(context.length());
 
             if (!GenericValue.getStackTraceAsString().contains("ControlFilterTests")
+                    && !System.getProperty("java.class.path").contains("--test component=solr") // Allows Solr tests
                     && SecurityUtil.containsFreemarkerInterpolation(req, resp, uri)) {
                 return;
             }