From 8aaa009751647898445d37ef9f7e4f1484c1658d Mon Sep 17 00:00:00 2001 From: "Redhuan D. Oon" Date: Thu, 25 Feb 2010 08:12:39 +0000 Subject: [PATCH] FR: [ 2214883 ] Remove SQL code and Replace for Query -- I am begining to use JUnit test and commit them as i go along also. Please advice where need be, or -- If OK, i shall remove more SQLs from ADempiere :) Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2214883 --- base/src/org/compiere/model/MPayment.java | 29 +++---------- extend/src/test/functional/MPaymentTest.java | 45 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 extend/src/test/functional/MPaymentTest.java diff --git a/base/src/org/compiere/model/MPayment.java b/base/src/org/compiere/model/MPayment.java index 0270513037..1a2ec37a7e 100644 --- a/base/src/org/compiere/model/MPayment.java +++ b/base/src/org/compiere/model/MPayment.java @@ -26,6 +26,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Properties; import java.util.logging.Level; +import java.util.List; +import java.util.Properties; import org.adempiere.exceptions.AdempiereException; import org.compiere.process.DocAction; @@ -91,28 +93,11 @@ public final class MPayment extends X_C_Payment */ public static MPayment[] getOfBPartner (Properties ctx, int C_BPartner_ID, String trxName) { - ArrayList list = new ArrayList(); - String sql = "SELECT * FROM C_Payment WHERE C_BPartner_ID=?"; - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql, trxName); - pstmt.setInt(1, C_BPartner_ID); - rs = pstmt.executeQuery(); - while (rs.next()) - list.add(new MPayment(ctx,rs, trxName)); - } - catch (Exception e) - { - s_log.log(Level.SEVERE, sql, e); - } - finally - { - DB.close(rs, pstmt); - rs = null; - pstmt = null; - } + //FR: [ 2214883 ] Remove SQL code and Replace for Query - red1 + String whereClause = "C_BPartner_ID=?"; + List list = new Query(ctx, MPayment.Table_Name, whereClause, null) + .setParameters(new Object[]{C_BPartner_ID}) + .list(); // MPayment[] retValue = new MPayment[list.size()]; diff --git a/extend/src/test/functional/MPaymentTest.java b/extend/src/test/functional/MPaymentTest.java new file mode 100644 index 0000000000..21ddbf3d43 --- /dev/null +++ b/extend/src/test/functional/MPaymentTest.java @@ -0,0 +1,45 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + *****************************************************************************/ +package test.functional; + +import org.compiere.model.MInvoice; +import org.compiere.model.MPayment; +import org.compiere.util.Env; + +import test.AdempiereTestCase; + +/** + * @author Teo Sarca, www.arhipac.ro // copied by red1 from MInvoiceTest + */ +public class MPaymentTest extends AdempiereTestCase +{ + public static final int BPARTNER_Standard = 112; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + assertEquals("Client is not GardenWorld", 11, Env.getAD_Client_ID(getCtx())); + } + + public void testQuery() throws Exception + { + MPayment.getOfBPartner(getCtx(), BPARTNER_Standard, getTrxName()); + + MPayment[] payments = MPayment.getOfBPartner(getCtx(), BPARTNER_Standard, getTrxName()); + assertTrue("Partner "+BPARTNER_Standard+" should have payments", payments.length > 0); + //testquery + } + +}