MProductTest

* doesn't compile because it used DBUtils from JasperReports project.
* fixed identation
* removed unused imports
* commented not used variables
This commit is contained in:
teo_sarca 2007-07-05 09:34:14 +00:00
parent ad941619ff
commit 3859f40636
1 changed files with 85 additions and 83 deletions

View File

@ -2,31 +2,33 @@
package test.functional; package test.functional;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.compiere.model.*; import org.adempiere.test.utils.DBUtils;
import org.compiere.model.MProduct;
import org.compiere.model.X_I_Product;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Ini; import org.compiere.util.Ini;
import org.compiere.utils.DBUtils;
import org.compiere.util.*;
import java.sql.*;
public class MProductTest extends TestCase { public class MProductTest extends TestCase {
// Test: General // Test: General
private Properties testProperties = null; private Properties testProperties = null;
private Properties m_Ctx = null; private Properties m_Ctx = null;
String trxName = "test"; String trxName = "test";
private String fileName_DefaultValue = "J:/Trifon-CD-0.3/workspace/adempiere-trunk/adempiere/Adempiere/Adempiere.properties"; private String fileName_DefaultValue = "J:/Trifon-CD-0.3/workspace/adempiere-trunk/adempiere/Adempiere/Adempiere.properties";
private String fileName_Key = "AdempiereProperties"; private String fileName_Key = "AdempiereProperties";
private String fileName_Value = ""; private String fileName_Value = "";
private String isClient_DefaultValue = "Y"; private String isClient_DefaultValue = "Y";
private String isClient_Key = "isClient"; private String isClient_Key = "isClient";
private boolean isClient_Value = true; private boolean isClient_Value = true;
@ -40,117 +42,117 @@ public class MProductTest extends TestCase {
private int AD_Client_ID_Value = 11; private int AD_Client_ID_Value = 11;
// Test: Specific variables // Test: Specific variables
private MProduct location = null; // private MProduct location = null;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
testProperties = new Properties(); testProperties = new Properties();
testProperties.load(new FileInputStream("test.properties")); testProperties.load(new FileInputStream("test.properties"));
fileName_Value = testProperties.getProperty(fileName_Key, fileName_DefaultValue); fileName_Value = testProperties.getProperty(fileName_Key, fileName_DefaultValue);
isClient_Value = "Y".equals( testProperties.getProperty(isClient_Key, isClient_DefaultValue) ); isClient_Value = "Y".equals( testProperties.getProperty(isClient_Key, isClient_DefaultValue) );
AD_User_ID_Value = Integer.parseInt(testProperties.getProperty(AD_User_ID_Key, AD_User_ID_DefaultValue) ); AD_User_ID_Value = Integer.parseInt(testProperties.getProperty(AD_User_ID_Key, AD_User_ID_DefaultValue) );
AD_Client_ID_Value = Integer.parseInt(testProperties.getProperty(AD_Client_ID_Key, AD_Client_ID_DefaultValue) ); AD_Client_ID_Value = Integer.parseInt(testProperties.getProperty(AD_Client_ID_Key, AD_Client_ID_DefaultValue) );
m_Ctx = new Properties(); m_Ctx = new Properties();
m_Ctx.setProperty("#AD_User_ID", new Integer(AD_User_ID_Value).toString()); m_Ctx.setProperty("#AD_User_ID", new Integer(AD_User_ID_Value).toString());
m_Ctx.setProperty("#AD_Client_ID", new Integer(AD_Client_ID_Value).toString()); m_Ctx.setProperty("#AD_Client_ID", new Integer(AD_Client_ID_Value).toString());
System.out.println("m_Ctx: " + m_Ctx); System.out.println("m_Ctx: " + m_Ctx);
if (fileName_Value.length() < 1) { if (fileName_Value.length() < 1) {
assertEquals("Please specify path to Adempiere.properties file!", true, false); assertEquals("Please specify path to Adempiere.properties file!", true, false);
} }
System.setProperty("PropertyFile", fileName_Value); System.setProperty("PropertyFile", fileName_Value);
Ini.setClient (isClient_Value); Ini.setClient (isClient_Value);
org.compiere.Adempiere.startup(isClient_Value); org.compiere.Adempiere.startup(isClient_Value);
// Force connection if there are enough parameters. Else we work with Adempiere.properties // Force connection if there are enough parameters. Else we work with Adempiere.properties
// if (args.length >= 6) { // if (args.length >= 6) {
// CConnection cc = CConnection.get(Database.DB_ORACLE, args[1], Integer.valueOf(args[2]).intValue(), args[3], args[4], args[5]); // CConnection cc = CConnection.get(Database.DB_ORACLE, args[1], Integer.valueOf(args[2]).intValue(), args[3], args[4], args[5]);
// System.out.println("DB UserID:"+cc.getDbUid()); // System.out.println("DB UserID:"+cc.getDbUid());
// DB.setDBTarget(cc); // DB.setDBTarget(cc);
// } // }
CLogMgt.setLevel(Level.FINEST); CLogMgt.setLevel(Level.FINEST);
/* Available levels: /* Available levels:
Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO, Level.OFF, Level.SEVERE, Level.WARNING, Level.INFO,
Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL Level.CONFIG, Level.FINE, Level.FINER, Level.FINEST, Level.ALL
*/ */
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
testProperties = null; testProperties = null;
m_Ctx = null; m_Ctx = null;
} }
public int getProduct_Category_ID(String productCategory) { public int getProduct_Category_ID(String productCategory) {
System.out.println("In getProduct_Category_ID"); System.out.println("In getProduct_Category_ID");
String sql = "select m_product_category_id from m_product_category where name = ?"; String sql = "select m_product_category_id from m_product_category where name = ?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
int M_ProductCategory_ID = -1; int M_ProductCategory_ID = -1;
try { try {
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName); pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName);
pstmt.setString(1, productCategory.trim()); pstmt.setString(1, productCategory.trim());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
M_ProductCategory_ID = rs.getInt(1); M_ProductCategory_ID = rs.getInt(1);
} }
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("Execption; sql = "+sql+"; e.getMessage() = " +e.getMessage()); System.out.println("Execption; sql = "+sql+"; e.getMessage() = " +e.getMessage());
} finally { } finally {
DBUtils.close( rs); DBUtils.close( rs);
DBUtils.close( pstmt); DBUtils.close( pstmt);
} }
System.out.println("productCategory: " + productCategory); System.out.println("productCategory: " + productCategory);
System.out.println("M_ProductCategory_ID: " + M_ProductCategory_ID); System.out.println("M_ProductCategory_ID: " + M_ProductCategory_ID);
return M_ProductCategory_ID; return M_ProductCategory_ID;
} }
public int getUOM_ID(String UOM) { public int getUOM_ID(String UOM) {
System.out.println("In getUOM_ID"); System.out.println("In getUOM_ID");
String sql = "select c_uom_id from c_uom where name = ?"; String sql = "select c_uom_id from c_uom where name = ?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null; ResultSet rs = null;
int C_Uom_ID = -1; int C_Uom_ID = -1;
try { try {
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName); pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName);
pstmt.setString(1, UOM.trim()); pstmt.setString(1, UOM.trim());
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
C_Uom_ID = rs.getInt(1); C_Uom_ID = rs.getInt(1);
} }
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("Execption; sql = "+sql+"; e.getMessage() = " +e.getMessage()); System.out.println("Execption; sql = "+sql+"; e.getMessage() = " +e.getMessage());
} finally { } finally {
DBUtils.close( rs); DBUtils.close( rs);
DBUtils.close( pstmt); DBUtils.close( pstmt);
} }
System.out.println("Uom: " + UOM); System.out.println("Uom: " + UOM);
System.out.println("C_Uom_ID: " + C_Uom_ID); System.out.println("C_Uom_ID: " + C_Uom_ID);
return C_Uom_ID; return C_Uom_ID;
} }
@ -158,19 +160,19 @@ public class MProductTest extends TestCase {
MProduct m_product = new MProduct(m_Ctx, 0, trxName); MProduct m_product = new MProduct(m_Ctx, 0, trxName);
m_product.setAD_Org_ID(0); m_product.setAD_Org_ID(0);
m_product.setProductType (X_I_Product.PRODUCTTYPE_Item); // I m_product.setProductType (X_I_Product.PRODUCTTYPE_Item); // I
m_product.setIsBOM (false); // N m_product.setIsBOM (false); // N
m_product.setIsInvoicePrintDetails (false); m_product.setIsInvoicePrintDetails (false);
m_product.setIsPickListPrintDetails (false); m_product.setIsPickListPrintDetails (false);
m_product.setIsPurchased (true); // Y m_product.setIsPurchased (true); // Y
m_product.setIsSold (true); // Y m_product.setIsSold (true); // Y
m_product.setIsStocked (true); // Y m_product.setIsStocked (true); // Y
m_product.setIsSummary (false); m_product.setIsSummary (false);
m_product.setIsVerified (false); // N m_product.setIsVerified (false); // N
m_product.setIsWebStoreFeatured (false); m_product.setIsWebStoreFeatured (false);
m_product.setIsSelfService(true); m_product.setIsSelfService(true);
m_product.setIsExcludeAutoDelivery(false); m_product.setIsExcludeAutoDelivery(false);
m_product.setProcessing (false); // N m_product.setProcessing (false); // N
m_product.setName("Test Product"); // N m_product.setName("Test Product"); // N
m_product.setC_UOM_ID(getUOM_ID("Each")); m_product.setC_UOM_ID(getUOM_ID("Each"));
//m_product.setM_Product_ID(getProduct_Category_ID("Documentation")); //m_product.setM_Product_ID(getProduct_Category_ID("Documentation"));
m_product.setM_Product_ID(111); m_product.setM_Product_ID(111);
@ -185,7 +187,7 @@ public class MProductTest extends TestCase {
DB.commit(true, trxName); DB.commit(true, trxName);
} catch (Exception e) { } catch (Exception e) {
assertEquals("Location not updated!", true, false); assertEquals("Location not updated!", true, false);
} */ } */
} }
assertTrue("MProductTest", true); assertTrue("MProductTest", true);
} }