From d4ae304e5ac2d92015ab0f84cb67bbc2ff6bee03 Mon Sep 17 00:00:00 2001 From: Adam Heath Date: Tue, 24 Jun 2014 01:30:56 +0000 Subject: [PATCH] Fix OFBIZ-5565: FinAccountHelper.getFinAccountFromCode() no longer returns financial account. Now that EntityCondition lookups work against encrypted fields, there is no longer a need to do the field encryption locally in the above method. So, just pass the value directly into the entity engine. There are also test cases, to prevent this breakage from occurring again. This commit depends on r1604967 and r1604968, at the minimum. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1604993 13f79535-47bb-0310-9956-ffa450edef68 --- applications/order/ofbiz-component.xml | 1 + .../order/finaccount/FinAccountHelper.java | 5 +- .../org/ofbiz/order/test/FinAccountTest.java | 58 +++++++++++++++++++ .../order/testdef/FinAccountTests.xml | 28 +++++++++ 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 applications/order/src/org/ofbiz/order/test/FinAccountTest.java create mode 100644 applications/order/testdef/FinAccountTests.xml diff --git a/applications/order/ofbiz-component.xml b/applications/order/ofbiz-component.xml index 0fc3b16862..ea14da45e3 100644 --- a/applications/order/ofbiz-component.xml +++ b/applications/order/ofbiz-component.xml @@ -52,6 +52,7 @@ under the License. + diff --git a/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java b/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java index 225ca0c99c..98aed08b4f 100644 --- a/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java +++ b/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java @@ -140,11 +140,8 @@ public class FinAccountHelper { } finAccountCode = finAccountCode.toUpperCase().replaceAll("[^0-9A-Z]", ""); - // now we need to get the encrypted version of the fin account code the user passed in to look up against FinAccount - String encryptedFinAccountCode = (String) delegator.encryptFieldValue("FinAccount", finAccountCode); - // now look for the account - List accounts = delegator.findByAnd("FinAccount", UtilMisc.toMap("finAccountCode", encryptedFinAccountCode), null, false); + List accounts = delegator.findByAnd("FinAccount", UtilMisc.toMap("finAccountCode", finAccountCode), null, false); accounts = EntityUtil.filterByDate(accounts); if (UtilValidate.isEmpty(accounts)) { diff --git a/applications/order/src/org/ofbiz/order/test/FinAccountTest.java b/applications/order/src/org/ofbiz/order/test/FinAccountTest.java new file mode 100644 index 0000000000..125a1d6f8a --- /dev/null +++ b/applications/order/src/org/ofbiz/order/test/FinAccountTest.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.ofbiz.order.test; + +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.testtools.OFBizTestCase; +import org.ofbiz.order.finaccount.FinAccountHelper; + +public class FinAccountTest extends OFBizTestCase { + public FinAccountTest(String name) { + super(name); + } + + public void testCreateFinAccountBasic() throws Exception { + String finAccountCode; + GenericValue account; + + finAccountCode = FinAccountHelper.getNewFinAccountCode(20, delegator); + System.err.printf("finAccountCode=%s\n", finAccountCode); + assertNotNull(finAccountCode); + + account = FinAccountHelper.getFinAccountFromCode(finAccountCode, delegator); + assertNull(account); + + delegator.createSetNextSeqId(delegator.makeValue("FinAccount", UtilMisc.toMap("finAccountCode", finAccountCode))); + + account = FinAccountHelper.getFinAccountFromCode(finAccountCode, delegator); + assertNotNull(account); + assertEquals(finAccountCode, account.get("finAccountCode")); + account = FinAccountHelper.getFinAccountFromCode(finAccountCode.toUpperCase(), delegator); + assertNotNull(account); + assertEquals(finAccountCode, account.get("finAccountCode")); + account = FinAccountHelper.getFinAccountFromCode(finAccountCode.toLowerCase(), delegator); + assertNotNull(account); + assertEquals(finAccountCode, account.get("finAccountCode")); + + delegator.createSetNextSeqId(delegator.makeValue("FinAccount", UtilMisc.toMap("finAccountCode", finAccountCode))); + account = FinAccountHelper.getFinAccountFromCode(finAccountCode, delegator); + assertNull(account); + } +} diff --git a/applications/order/testdef/FinAccountTests.xml b/applications/order/testdef/FinAccountTests.xml new file mode 100644 index 0000000000..1467a3ff70 --- /dev/null +++ b/applications/order/testdef/FinAccountTests.xml @@ -0,0 +1,28 @@ + + + + + + + + +