IDEMPIERE-851 fitnesse improvements

This commit is contained in:
Juliana Corredor 2013-04-22 12:11:51 -05:00
parent 9e2ed40587
commit c0d9c39f0d
11 changed files with 832 additions and 90 deletions

View File

@ -0,0 +1,14 @@
-- Apr 18, 2013 6:40:49 PM COT
-- IDEMPIERE-851 fitnesse improvements
UPDATE AD_Column SET IsAllowLogging='N',Updated=TO_DATE('2013-04-18 18:40:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=5903
;
-- Apr 18, 2013 6:42:14 PM COT
-- IDEMPIERE-851 fitnesse improvements
UPDATE AD_Column SET IsAllowLogging='N',Updated=TO_DATE('2013-04-18 18:42:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=11353
;
SELECT register_migration_script('2010304181900_IDEMPIERE-851.sql') FROM dual
;

View File

@ -0,0 +1,13 @@
-- Apr 18, 2013 6:40:49 PM COT
-- IDEMPIERE-851 fitnesse improvements
UPDATE AD_Column SET IsAllowLogging='N',Updated=TO_TIMESTAMP('2013-04-18 18:40:49','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=5903
;
-- Apr 18, 2013 6:42:14 PM COT
-- IDEMPIERE-851 fitnesse improvements
UPDATE AD_Column SET IsAllowLogging='N',Updated=TO_TIMESTAMP('2013-04-18 18:42:14','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=11353
;
SELECT register_migration_script('2010304181900_IDEMPIERE-851.sql') FROM dual
;

View File

@ -66,7 +66,8 @@ public class AssertRecord extends TableFixture {
MTable table = null; MTable table = null;
POInfo poinfo = null; POInfo poinfo = null;
boolean alreadyread = false; boolean alreadyread = false;
String whereclause = new String(""); StringBuilder whereclause = new StringBuilder("");
boolean error=false;
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0); String cell_title = getText(i, 0);
String cell_value = getText(i, 1); String cell_value = getText(i, 1);
@ -89,8 +90,10 @@ public class AssertRecord extends TableFixture {
exception(getCell(i, 1), new Exception("*Where* must be defined in second row")); exception(getCell(i, 1), new Exception("*Where* must be defined in second row"));
return; return;
} }
whereclause = cell_value; whereclause.append(cell_value);
} else if (cell_title.equalsIgnoreCase("*Read*")) { } else if (cell_title.equalsIgnoreCase("*Read*") || cell_title.equalsIgnoreCase("*Read*Error*") )
{
error= "*Read*Error*".equalsIgnoreCase(cell_title);
if (! tableOK) { if (! tableOK) {
getCell(i, 1).addToBody("Table " + tableName + " does not exist"); getCell(i, 1).addToBody("Table " + tableName + " does not exist");
wrong(i, 1); wrong(i, 1);
@ -110,22 +113,46 @@ public class AssertRecord extends TableFixture {
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
gpo = table.getPO(rs, null); gpo = table.getPO(rs, null);
if(error){
wrong(i,1);
return;
}
} else { } else {
getCell(i, 1).addToBody("No record found: " + sql); getCell(i, 1).addToBody("No record found: " + sql);
wrong(i, 1); boolean value=Util.evaluateError("No record found: ",cell_value,error);
if(value){
right(i,1);
return; return;
}else{
wrong(i,1);
return;
}
} }
if (rs.next()) { if (rs.next()) {
getCell(i, 1).addToBody("More than one record found: " + sql); getCell(i, 1).addToBody("More than one record found: " + sql);
wrong(i, 1); boolean value=Util.evaluateError("More than one record found: ",cell_value,error);
if(value){
right(i,1);
return; return;
}else{
wrong(i,1);
return;
}
} }
} }
catch (SQLException e) catch (SQLException e)
{ {
boolean value=Util.evaluateError(e.getMessage(),cell_value,error);
if(value){
right(getCell(i, 1));
return;
}else{
exception(getCell(i, 1), e); exception(getCell(i, 1), e);
return; return;
} }
}
finally finally
{ {
DB.close(rs, pstmt); DB.close(rs, pstmt);
@ -133,7 +160,9 @@ public class AssertRecord extends TableFixture {
pstmt = null; pstmt = null;
} }
right(i, 1); right(i, 1);
if (gpo != null) {
getCell(i, 1).addToBody(gpo.toString()); getCell(i, 1).addToBody(gpo.toString());
}
alreadyread = true; alreadyread = true;
} else { } else {
// columns // columns
@ -142,11 +171,12 @@ public class AssertRecord extends TableFixture {
// not read yet - add value to where clause // not read yet - add value to where clause
String value_evaluated = Util.evaluate(ctx, windowNo, cell_value, getCell(i, 1)); String value_evaluated = Util.evaluate(ctx, windowNo, cell_value, getCell(i, 1));
if (whereclause.length() > 0) if (whereclause.length() > 0)
whereclause = whereclause + " AND "; whereclause.append(" AND ");
whereclause = whereclause + cell_title + "=" + value_evaluated; whereclause.append(cell_title).append("=").append(value_evaluated);
} else { } else {
// already read, compare the value of db with the context variable or formula // already read, compare the value of db with the context variable or formula
String title_evaluated = ""; String title_evaluated = "";
if (gpo != null) {
Object result = gpo.get_Value(cell_title); Object result = gpo.get_Value(cell_title);
if (result != null) { if (result != null) {
getCell(i, 0).addToBody("<hr/>" + result.toString()); getCell(i, 0).addToBody("<hr/>" + result.toString());
@ -155,7 +185,7 @@ public class AssertRecord extends TableFixture {
String value_evaluated = cell_value; String value_evaluated = cell_value;
if (cell_value.startsWith("@")) { if (cell_value.startsWith("@")) {
value_evaluated = Util.evaluate(ctx, windowNo, cell_value, getCell(i, 1)); value_evaluated = Util.evaluate(ctx, windowNo,cell_value, getCell(i, 1));
} }
if (title_evaluated.equals(value_evaluated)) { if (title_evaluated.equals(value_evaluated)) {
@ -166,6 +196,7 @@ public class AssertRecord extends TableFixture {
} }
} }
} }
}//end while
} }
// set the variables at the end // set the variables at the end
// read - set context variables // read - set context variables

View File

@ -64,8 +64,10 @@ public class CreateRecord extends TableFixture {
String columnName = null; String columnName = null;
boolean tableOK = false; boolean tableOK = false;
boolean columnsOK = true; boolean columnsOK = true;
boolean error="*Save*Error*".equalsIgnoreCase(getText(rows-1, 0));
MTable table = null; MTable table = null;
POInfo poinfo = null; POInfo poinfo = null;
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0); String cell_title = getText(i, 0);
String cell_value = getText(i, 1); String cell_value = getText(i, 1);
@ -79,21 +81,30 @@ public class CreateRecord extends TableFixture {
// TODO : verify if the record already exists // TODO : verify if the record already exists
table = MTable.get(ctx, tableName); table = MTable.get(ctx, tableName);
if (table == null || table.get_ID() <= 0) { if (table == null || table.get_ID() <= 0) {
wrong(i, 1); boolean value=Util.evaluateError("Table " + tableName + " does not exist", cell_value, error);
if(value)
right(i,1);
else
wrong(i,1);
tableOK = false; tableOK = false;
} else { } else {
tableOK = true; tableOK = true;
gpo = table.getPO(0, null); gpo = table.getPO(0, null);
} }
poinfo = POInfo.getPOInfo(ctx, table!=null ? table.getAD_Table_ID() : 0); poinfo = POInfo.getPOInfo(ctx, table!=null ? table.getAD_Table_ID() : 0);
} else if (cell_title.equalsIgnoreCase("*Save*")) { } else if (cell_title.equalsIgnoreCase("*Save*") || cell_title.equalsIgnoreCase("*Save*Error*")) {
if (i != rows-1) { if (i != rows-1) {
exception(getCell(i, 1), new Exception("*Save* must be called in last row")); exception(getCell(i, 1), new Exception("*Save* must be called in last row"));
return; return;
} }
if (! tableOK) { if (! tableOK) {
getCell(i, 1).addToBody("Table " + tableName + " does not exist"); getCell(i, 1).addToBody("Table " + tableName + " does not exist");
wrong(i, 1); boolean value=Util.evaluateError("Table " + tableName + " does not exist", cell_value, error);
if(value)
right(i,1);
else
wrong(i,1);
} else { } else {
if (columnsOK) { if (columnsOK) {
if (!gpo.save()) { if (!gpo.save()) {
@ -107,9 +118,17 @@ public class CreateRecord extends TableFixture {
msg.append("Error: " + vnp.getName()); msg.append("Error: " + vnp.getName());
} }
getCell(i, 1).addToBody(msg.toString()); getCell(i, 1).addToBody(msg.toString());
wrong(i, 1); boolean value=Util.evaluateError(msg.toString(),cell_value,error);
if(value)
right(i,1);
else
wrong(i,1);
} else { } else {
if(error){
wrong(i,1);
}else{
right(i, 1); right(i, 1);
}
getCell(i, 1).addToBody(gpo.toString()); getCell(i, 1).addToBody(gpo.toString());
for (int idx = 0; idx < poinfo.getColumnCount(); idx++) { for (int idx = 0; idx < poinfo.getColumnCount(); idx++) {
String colname = poinfo.getColumnName(idx); String colname = poinfo.getColumnName(idx);
@ -126,7 +145,7 @@ public class CreateRecord extends TableFixture {
columnName = cell_title; columnName = cell_title;
int idxcol = gpo.get_ColumnIndex(columnName); int idxcol = gpo.get_ColumnIndex(columnName);
if (idxcol < 0) { if (idxcol < 0) {
wrong(i, 0); wrong(i,1);
// column does not exist in dictionary - anyways try custom column in case it exists in table // column does not exist in dictionary - anyways try custom column in case it exists in table
gpo.set_CustomColumnReturningBoolean(columnName, cell_value); gpo.set_CustomColumnReturningBoolean(columnName, cell_value);
} else { } else {
@ -175,10 +194,18 @@ public class CreateRecord extends TableFixture {
try { try {
if (!gpo.set_ValueOfColumnReturningBoolean(columnName, value)) { if (!gpo.set_ValueOfColumnReturningBoolean(columnName, value)) {
columnsOK = false; columnsOK = false;
boolean value1=Util.evaluateError("Cannot set value of column",cell_value,error);
if(value1)
right(getCell(i, 1));
else
exception(getCell(i, 1), new Exception("Cannot set value of column")); exception(getCell(i, 1), new Exception("Cannot set value of column"));
} }
} catch (Exception e) { } catch (Exception e) {
columnsOK = false; columnsOK = false;
boolean value1=Util.evaluateError("Cannot set value of column",cell_value,error);
if(value1)
right(getCell(i, 1));
else
exception(getCell(i, 1), e); exception(getCell(i, 1), e);
} }
} }

View File

@ -0,0 +1,182 @@
/**********************************************************************
* This file is part of Adempiere ERP Bazaar *
* http://www.adempiere.org *
* *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
***********************************************************************/
package org.idempiere.fitnesse.fixture;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.util.DB;
import org.idempiere.fitnesse.fixture.Instance;
import org.idempiere.fitnesse.fixture.Static_iDempiereInstance;
import org.idempiere.fitnesse.fixture.Util;
import fitnesse.fixtures.TableFixture;
/**
* @author juliana
*
*/
public class DeleteRecord extends TableFixture {
/* (non-Javadoc)
* @see fitnesse.fixtures.TableFixture#doStaticTable(int)
*/
private volatile static Instance adempiereInstance = null;
@Override
protected void doStaticTable(int rows) {
adempiereInstance = Static_iDempiereInstance.getInstance();
if (adempiereInstance.getAdempiereService() == null
|| !adempiereInstance.getAdempiereService().isLoggedIn()) {
wrong(rows - 1, 1);
getCell(rows - 1, 1).addToBody("not logged in");
return;
}
Properties ctx = adempiereInstance.getAdempiereService().getCtx();
int windowNo = adempiereInstance.getAdempiereService().getWindowNo();
PO gpo = null;
String tableName = new String("");
boolean tableOK = false;
MTable table = null;
boolean alreadyread = false;
StringBuilder whereclause = new StringBuilder("");
boolean error = false;
String msgerror=null;
for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0);
String cell_value = getText(i, 1);
if (cell_title.equalsIgnoreCase("*Table*")) {
if (i > 0) {
exception(getCell(i, 1), new Exception("*Table* must be defined in first row"));
return;
}
tableName = cell_value;
table = MTable.get(ctx, tableName);
if (table == null || table.get_ID() <= 0) {
wrong(i, 1);
tableOK = false;
} else {
tableOK = true;
}
} else if (cell_title.equalsIgnoreCase("*Where*")) {
if (i != 1) {
exception(getCell(i, 1), new Exception("*Where* must be defined in second row"));
return;
}
whereclause.append(cell_value);
} else if (cell_title.equalsIgnoreCase("*Delete*") || cell_title.equalsIgnoreCase("*Delete*Error*")) {
error = "*Delete*Error*".equalsIgnoreCase(cell_title);
msgerror=cell_value;
if (!tableOK) {
getCell(i, 1).addToBody("Table " + tableName + " does not exist");
wrong(i, 1);
return;
}
if (whereclause.length() == 0) {
getCell(i, 1).addToBody("No where clause");
wrong(i, 1);
return;
}
String sql = "SELECT * FROM " + tableName + " WHERE "+ whereclause;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
if (rs.next()) {
gpo = table.getPO(rs, null);
} else {
getCell(i, 1).addToBody("No record found: " + sql);
boolean value = Util.evaluateError("No record found: ",cell_value, error);
if (value) {
right(i, 1);
return;
} else {
wrong(i, 1);
return;
}
}
if (rs.next()) {
getCell(i, 1).addToBody("More than one record found: " + sql);
boolean value = Util.evaluateError("More than one record found: ", cell_value,error);
if (value) {
right(i, 1);
return;
} else {
wrong(i, 1);
return;
}
}
if (gpo != null) {
gpo.deleteEx(true);
}
} catch (Exception e) {
boolean value = Util.evaluateError(e.getMessage(),msgerror, error);
if (value) {
right(getCell(i, 1));
return;
} else {
exception(getCell(i, 1), e);
return;
}
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
right(i, 1);
alreadyread = true;
} else {
// columns
if (tableOK) {
String value_evaluated = Util.evaluate(ctx, windowNo,cell_value, getCell(i, 1));
if (!alreadyread) {
// not read yet - add value to where clause
if (whereclause.length() > 0)
whereclause.append(" AND ");
whereclause.append(cell_title).append("=").append(value_evaluated);
}
}
}
}//end while
}
}

View File

@ -54,6 +54,8 @@ public class Login extends TableFixture {
if (adempiereInstance == null) { if (adempiereInstance == null) {
adempiereInstance = Static_iDempiereInstance.getInstance(); adempiereInstance = Static_iDempiereInstance.getInstance();
} }
boolean error="*Login*Error*".equalsIgnoreCase(getText(rows-1, 0));
String msgerror=getText(rows-1, 1);
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0); String cell_title = getText(i, 0);
String cell_value = getText(i, 1); String cell_value = getText(i, 1);
@ -92,7 +94,7 @@ public class Login extends TableFixture {
exception(getCell(i, 1), e); exception(getCell(i, 1), e);
continue; continue;
} }
} else if (cell_title.equalsIgnoreCase("*Login*")) { } else if (cell_title.equalsIgnoreCase("*Login*") || cell_title.equalsIgnoreCase("*Login*Error*")) {
if (i != rows-1) { if (i != rows-1) {
exception(getCell(i, 1), new Exception("*Login* must be called in last row")); exception(getCell(i, 1), new Exception("*Login* must be called in last row"));
return; return;
@ -104,18 +106,36 @@ public class Login extends TableFixture {
|| m_password == null || m_password.length() == 0 || m_password == null || m_password.length() == 0
|| m_role_id < 0 || m_role_id < 0
|| m_client_id < 0) { || m_client_id < 0) {
boolean value=Util.evaluateError("Incomplete data to login, needed User|Password|AD_Role_ID|AD_Client_ID", msgerror, error);
if(value)
right(i,1);
else
exception(getCell(rows-1, 1), new Exception("Incomplete data to login, needed User|Password|AD_Role_ID|AD_Client_ID")); exception(getCell(rows-1, 1), new Exception("Incomplete data to login, needed User|Password|AD_Role_ID|AD_Client_ID"));
} }
else { else {
String msg = modelLogin(); String msg = modelLogin();
if (msg == null || msg.length() == 0) { if (msg == null || msg.length() == 0) {
MSession.get (Env.getCtx(), true); // Start Session MSession.get (Env.getCtx(), true);// Start Session
if(error){
wrong(rows-1, 0);
wrong(rows-1, 1);
}else{
right(rows-1, 0); right(rows-1, 0);
right(rows-1, 1); right(rows-1, 1);
}
} else { } else {
boolean value=Util.evaluateError(msg, msgerror, error);
if(value){
right(rows-1, 0);
}
else{
wrong(rows-1, 0); wrong(rows-1, 0);
exception(getCell(rows-1, 1), new Exception(msg)); exception(getCell(rows-1, 1), new Exception(msg));
} }
}
} }
} else { } else {

View File

@ -67,6 +67,7 @@ public class ReadRecord extends TableFixture {
POInfo poinfo = null; POInfo poinfo = null;
boolean alreadyread = false; boolean alreadyread = false;
String whereclause = new String(""); String whereclause = new String("");
boolean error=false;
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0); String cell_title = getText(i, 0);
String cell_value = getText(i, 1); String cell_value = getText(i, 1);
@ -90,12 +91,13 @@ public class ReadRecord extends TableFixture {
return; return;
} }
whereclause = cell_value; whereclause = cell_value;
} else if (cell_title.equalsIgnoreCase("*Read*")) { } else if (cell_title.equalsIgnoreCase("*Read*") || cell_title.equalsIgnoreCase("*Read*Error*")) {
if (! tableOK) { if (! tableOK) {
getCell(i, 1).addToBody("Table " + tableName + " does not exist"); getCell(i, 1).addToBody("Table " + tableName + " does not exist");
wrong(i, 1); wrong(i, 1);
return; return;
} }
error="*Read*Error*".equalsIgnoreCase(cell_title);
if (whereclause.length() == 0) { if (whereclause.length() == 0) {
getCell(i, 1).addToBody("No where clause"); getCell(i, 1).addToBody("No where clause");
wrong(i, 1); wrong(i, 1);
@ -110,22 +112,43 @@ public class ReadRecord extends TableFixture {
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) { if (rs.next()) {
gpo = table.getPO(rs, null); gpo = table.getPO(rs, null);
if(error){
wrong(i,1);
}
} else { } else {
getCell(i, 1).addToBody("No record found: " + sql); getCell(i, 1).addToBody("No record found: " + sql);
wrong(i, 1); boolean value=Util.evaluateError("No record found: ",cell_value,error);
if(value){
right(i,1);
return; return;
}else{
wrong(i,1);
return;
}
} }
if (rs.next()) { if (rs.next()) {
getCell(i, 1).addToBody("More than one record found: " + sql); getCell(i, 1).addToBody("More than one record found: " + sql);
wrong(i, 1); boolean value=Util.evaluateError("More than one record found: ",cell_value,error);
if(value){
right(i,1);
return; return;
}else{
wrong(i,1);
return;
}
} }
} }
catch (SQLException e) catch (SQLException e)
{ {
boolean value=Util.evaluateError(e.getMessage(),cell_value,error);
if(value){
right(getCell(i, 1));
return;
}else{
exception(getCell(i, 1), e); exception(getCell(i, 1), e);
return; return;
} }
}
finally finally
{ {
DB.close(rs, pstmt); DB.close(rs, pstmt);
@ -133,7 +156,9 @@ public class ReadRecord extends TableFixture {
pstmt = null; pstmt = null;
} }
right(i, 1); right(i, 1);
if (gpo != null) {
getCell(i, 1).addToBody(gpo.toString()); getCell(i, 1).addToBody(gpo.toString());
}
// read - set context variables // read - set context variables
for (int idx = 0; idx < poinfo.getColumnCount(); idx++) { for (int idx = 0; idx < poinfo.getColumnCount(); idx++) {
String colname = poinfo.getColumnName(idx); String colname = poinfo.getColumnName(idx);
@ -153,6 +178,7 @@ public class ReadRecord extends TableFixture {
whereclause = whereclause + cell_title + "=" + value_evaluated; whereclause = whereclause + cell_title + "=" + value_evaluated;
} else { } else {
// already read, show the value of context variable // already read, show the value of context variable
if (gpo != null) {
Object result = gpo.get_Value(cell_title); Object result = gpo.get_Value(cell_title);
if (result != null) if (result != null)
getCell(i, 1).addToBody(result.toString()); getCell(i, 1).addToBody(result.toString());
@ -160,6 +186,7 @@ public class ReadRecord extends TableFixture {
} }
} }
} }
}
} // doStaticTable } // doStaticTable
} // AdempiereReadRecord } // AdempiereReadRecord

View File

@ -83,6 +83,8 @@ public class RunProcess extends TableFixture {
HashMap<String,Object> fmap = new HashMap<String,Object>(); HashMap<String,Object> fmap = new HashMap<String,Object>();
int recordID = 0; int recordID = 0;
String docAction = null; String docAction = null;
boolean error="*Run*Error*".equalsIgnoreCase(getText(rows-1, 0));
String msgerror1=getText(rows-1, 1);
for (int i = 0; i < rows; i++) { for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0); String cell_title = getText(i, 0);
String cell_value = getText(i, 1); String cell_value = getText(i, 1);
@ -93,10 +95,15 @@ public class RunProcess extends TableFixture {
} }
String processValue = cell_value; String processValue = cell_value;
int processID = MProcess.getProcess_ID(processValue, null); int processID = MProcess.getProcess_ID(processValue, null);
if (processID <= 0) { if (processID <= 0 ) {
boolean value=Util.evaluateError(msgerror1,"Process with Value=" + processValue + " doesn't exist", error);
if(value){
right(getCell(i, 1));
}else{
exception(getCell(i, 1), new Exception("Process with Value=" + processValue + " doesn't exist")); exception(getCell(i, 1), new Exception("Process with Value=" + processValue + " doesn't exist"));
return; return;
} }
}
process = new MProcess(ctx, processID, null); process = new MProcess(ctx, processID, null);
} else if (cell_title.equalsIgnoreCase("*ProcessID*")) { } else if (cell_title.equalsIgnoreCase("*ProcessID*")) {
if (i > 0) { if (i > 0) {
@ -106,10 +113,15 @@ public class RunProcess extends TableFixture {
int processID = getInt(i, 1); int processID = getInt(i, 1);
process = new MProcess(ctx, processID, null); process = new MProcess(ctx, processID, null);
if (process == null || process.get_ID() <= 0) { if (process == null || process.get_ID() <= 0) {
boolean value=Util.evaluateError(msgerror1,"Process with ID=" + processID + " doesn't exist", error);
if(value){
right(getCell(i, 1));
}else{
exception(getCell(i, 1), new Exception("Process with ID=" + processID + " doesn't exist")); exception(getCell(i, 1), new Exception("Process with ID=" + processID + " doesn't exist"));
return; return;
} }
} else if (cell_title.equalsIgnoreCase("*Run*")) { }
} else if (cell_title.equalsIgnoreCase("*Run*") || cell_title.equalsIgnoreCase("*Run*Error*") ) {
if (i != rows-1) { if (i != rows-1) {
exception(getCell(i, 1), new Exception("*Run* must be called in last row")); exception(getCell(i, 1), new Exception("*Run* must be called in last row"));
return; return;
@ -118,8 +130,14 @@ public class RunProcess extends TableFixture {
pInstance = new MPInstance (process, 0); pInstance = new MPInstance (process, 0);
MPInstancePara[] iParams = pInstance.getParameters(); MPInstancePara[] iParams = pInstance.getParameters();
String errorMsg = setParams(process, iParams, fmap); String errorMsg = setParams(process, iParams, fmap);
if (errorMsg != null) if (errorMsg != null){
boolean value=Util.evaluateError(msgerror1,errorMsg, error);
if(value){
}else{
exception(getCell(i, 1), new Exception(errorMsg)); exception(getCell(i, 1), new Exception(errorMsg));
}
}
if (recordID > 0) if (recordID > 0)
pInstance.setRecord_ID( recordID); pInstance.setRecord_ID( recordID);
pInstance.saveEx(); pInstance.saveEx();
@ -141,6 +159,7 @@ public class RunProcess extends TableFixture {
po.set_ValueOfColumn("DocAction", docAction); po.set_ValueOfColumn("DocAction", docAction);
po.saveEx(); po.saveEx();
} }
} }
} }
} }
@ -157,6 +176,7 @@ public class RunProcess extends TableFixture {
// Start // Start
if (process.isWorkflow()) if (process.isWorkflow())
{ {
boolean value=Util.evaluateError(msgerror1,pi.getSummary(), error);
try try
{ {
int AD_Workflow_ID = process.getAD_Workflow_ID(); int AD_Workflow_ID = process.getAD_Workflow_ID();
@ -166,13 +186,44 @@ public class RunProcess extends TableFixture {
{ {
getCell(i, 1).addToBody(Msg.parseTranslation(ctx, pi.getSummary())); getCell(i, 1).addToBody(Msg.parseTranslation(ctx, pi.getSummary()));
addLogInfo(pInstance, i); addLogInfo(pInstance, i);
if (wf.getWorkflowType().equals(MWorkflow.WORKFLOWTYPE_DocumentProcess)) {
MTable table = MTable.get(ctx, wf.getAD_Table_ID());
if (table != null) {
PO po = table.getPO(recordID, null);
if(!docAction.equals(po.get_Value("DocStatus"))){
if(value){
right(getCell(i, 1)); right(getCell(i, 1));
}else{
wrong(getCell(i, 1));
}
}
else {
if (value) {
right(getCell(i, 1));
} else {
wrong(getCell(i, 1));
}
}
}
}
else{
if(value){
right(getCell(i, 1));
}else{
wrong(getCell(i, 1));
}
}
} }
} }
catch(Exception ex) catch(Exception ex)
{ {
if(value){
right(getCell(i, 1));
}else{
exception(getCell(i, 1), ex); exception(getCell(i, 1), ex);
} }
}
//started = wfProcess != null; //started = wfProcess != null;
} }
@ -192,16 +243,26 @@ public class RunProcess extends TableFixture {
} }
if (!processOK || pi.isError()) if (!processOK || pi.isError())
{ {
boolean value=Util.evaluateError(msgerror1,pi.getSummary(), error);
if(value){
right(getCell(i, 1));
processOK = true;
}else{
exception(getCell(i, 1), new Exception(pi.getSummary())); exception(getCell(i, 1), new Exception(pi.getSummary()));
processOK = false; processOK = false;
} }
}
else else
{ {
if(error){
wrong(getCell(i, 1));
}else{
getCell(i, 1).addToBody(Msg.parseTranslation(ctx, pi.getSummary())); getCell(i, 1).addToBody(Msg.parseTranslation(ctx, pi.getSummary()));
addLogInfo(pInstance, i); addLogInfo(pInstance, i);
right(getCell(i, 1)); right(getCell(i, 1));
} }
} }
}
// Report // Report
if (/*processOK &&*/ (process.isReport() || jasperreport))//&& !m_jasperreport) if (/*processOK &&*/ (process.isReport() || jasperreport))//&& !m_jasperreport)

View File

@ -0,0 +1,200 @@
/**********************************************************************
* This file is part of Adempiere ERP Bazaar *
* http://www.adempiere.org *
* *
* *
* Copyright (C) Contributors *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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., 51 Franklin Street, Fifth Floor, Boston, *
* MA 02110-1301, USA. *
* *
***********************************************************************/
package org.idempiere.fitnesse.fixture;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import org.compiere.model.MTable;
import org.compiere.model.PO;
import org.compiere.util.DB;
import fitnesse.fixtures.TableFixture;
/**
*
* iDempiere Update Record fixture for use with fitnesse framework testing
* @author juliana
*
*/
public class UpdateRecord extends TableFixture {
/* (non-Javadoc)
* @see fitnesse.fixtures.TableFixture#doStaticTable(int)
*/
private volatile static Instance adempiereInstance = null;
@Override
protected void doStaticTable(int rows) {
if (adempiereInstance == null) {
adempiereInstance = Static_iDempiereInstance.getInstance();
}
if (adempiereInstance.getAdempiereService() == null
|| !adempiereInstance.getAdempiereService().isLoggedIn()) {
wrong(rows - 1, 1);
getCell(rows - 1, 1).addToBody("not logged in");
return;
}
Properties ctx = adempiereInstance.getAdempiereService().getCtx();
int windowNo = adempiereInstance.getAdempiereService().getWindowNo();
PO gpo = null;
String tableName = new String("");
boolean tableOK = false;
MTable table = null;
boolean alreadyread = false;
StringBuilder whereclause = new StringBuilder("");
boolean error = false;
String msgerror=null;
for (int i = 0; i < rows; i++) {
String cell_title = getText(i, 0);
String cell_value = getText(i, 1);
if (cell_title.equalsIgnoreCase("*Table*")) {
if (i > 0) {
exception(getCell(i, 1), new Exception("*Table* must be defined in first row"));
return;
}
tableName = cell_value;
table = MTable.get(ctx, tableName);
if (table == null || table.get_ID() <= 0) {
wrong(i, 1);
tableOK = false;
} else {
tableOK = true;
}
} else if (cell_title.equalsIgnoreCase("*Where*")) {
if (i != 1) {
exception(getCell(i, 1), new Exception("*Where* must be defined in second row"));
return;
}
whereclause.append(cell_value);
} else if (cell_title.equalsIgnoreCase("*Update*") || cell_title.equalsIgnoreCase("*Update*Error*")) {
error = "*Update*Error*".equalsIgnoreCase(cell_title);
msgerror=cell_value;
if (!tableOK) {
getCell(i, 1).addToBody("Table " + tableName + " does not exist");
wrong(i, 1);
return;
}
if (whereclause.length() == 0) {
getCell(i, 1).addToBody("No where clause");
wrong(i, 1);
return;
}
String sql = "SELECT * FROM " + tableName + " WHERE "+ whereclause;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
if (rs.next()) {
gpo = table.getPO(rs, null);
} else {
getCell(i, 1).addToBody("No record found: " + sql);
boolean value = Util.evaluateError("No record found: ",cell_value, error);
if (value) {
right(i, 1);
return;
} else {
wrong(i, 1);
return;
}
}
if (rs.next()) {
getCell(i, 1).addToBody("More than one record found: " + sql);
boolean value = Util.evaluateError("More than one record found: ", cell_value,error);
if (value) {
right(i, 1);
return;
} else {
wrong(i, 1);
return;
}
}
} catch (SQLException e) {
boolean value = Util.evaluateError(e.getMessage(),cell_value, error);
if (value) {
right(getCell(i, 1));
return;
} else {
exception(getCell(i, 1), e);
return;
}
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
right(i, 1);
if (gpo != null) {
getCell(i, 1).addToBody(gpo.toString());
}
alreadyread = true;
} else {
// columns
if (tableOK) {
String value_evaluated = Util.evaluate(ctx, windowNo,cell_value, getCell(i, 1));
if (!alreadyread) {
// not read yet - add value to where clause
if (whereclause.length() > 0)
whereclause.append(" AND ");
whereclause.append(cell_title).append("=").append(value_evaluated);
} else {
if(gpo != null){
if(gpo.set_ValueOfColumnReturningBoolean(cell_title, cell_value)){
if(error){
wrong(getCell(i, 1));
}else{
right(getCell(i, 1));
}
}
try {
gpo.saveEx();
} catch (Exception e) {
boolean value = Util.evaluateError(e.getMessage(),msgerror, error);
if (value)
right(getCell(i, 1));
else
exception(getCell(i, 1),e);
}
}
}
}
}
}//end while
}
}

View File

@ -250,4 +250,30 @@ public class Util {
return evaluate(ctx, windowNo, expr, null); return evaluate(ctx, windowNo, expr, null);
} }
public static boolean evaluateError(String error, String cell,boolean isError) {
boolean evaluate = false;
if(error == null)
error="";
if (cell == null)
cell="";
if (isError) {
if (cell.length() > 0) {
if (error.contains(cell)) {
evaluate = true;
} else {
evaluate = false;
}
} else {
evaluate = true;
}
} else {
evaluate = false;
}
return evaluate;
}
} // AdempiereUtil } // AdempiereUtil

View File

@ -205,8 +205,7 @@ public class FitRecorder implements ModelValidator {
|| colName.equals("AD_Client_ID") || colName.equals("AD_Client_ID")
|| colName.equals(table.getTableName() + "_ID") || colName.equals(table.getTableName() + "_ID")
|| colName.equals(PO.getUUIDColumnName(table.getTableName())) || colName.equals(PO.getUUIDColumnName(table.getTableName()))
|| column.getAD_Reference_ID() == DisplayType.Button || column.getAD_Reference_ID() == DisplayType.Button)
)
continue; continue;
if (po.isActive() && colName.equals("IsActive")) if (po.isActive() && colName.equals("IsActive"))
continue; continue;
@ -229,9 +228,10 @@ public class FitRecorder implements ModelValidator {
} }
if (po instanceof MPInstance) { if(type == TYPE_AFTER_CHANGE)
if (type == TYPE_AFTER_CHANGE) { {
if (po instanceof MPInstance)
{
MProcess pro = MProcess.get(Env.getCtx(), po.get_ValueAsInt("AD_Process_ID")); MProcess pro = MProcess.get(Env.getCtx(), po.get_ValueAsInt("AD_Process_ID"));
MPInstance pint = (MPInstance)po; MPInstance pint = (MPInstance)po;
writeFile("\n"); writeFile("\n");
@ -294,18 +294,160 @@ public class FitRecorder implements ModelValidator {
writeFile("|*Run*|"); writeFile("|*Run*|");
writeFile("\n"); writeFile("\n");
} }else if(po instanceof MSession)
} {
if (po instanceof MSession) {
if (type == TYPE_AFTER_CHANGE) {
MSession session = (MSession) po; MSession session = (MSession) po;
if (session.isProcessed()) { if (session.isProcessed()) {
closefile(); closefile();
} }
} else {
if (dontLogTables.contains(po.get_TableName().toUpperCase()))
return null;
// Ignore records created within a process
if (po.get_TrxName().startsWith("SvrProcess_"))
return null;
// Ignore records created within a workflow process
if (po.get_TrxName().startsWith("WFP_"))
return null;
MTable table = MTable.get(Env.getCtx(), po.get_Table_ID());
MColumn[] columns = table.getColumns(true);
StringBuilder where = new StringBuilder();
StringBuilder set = new StringBuilder();
boolean key=false;
for (int i = 0; i < columns.length; i++)
{
MColumn column = columns[i];
String colName = column.getColumnName();
String value=null;
if (DisplayType.isLookup(column.getAD_Reference_ID()) && DisplayType.List != column.getAD_Reference_ID()) {
value = resolveValue(po, table, column);
}else{
value=po.get_ValueAsString(colName);
}
if (column.isAllowLogging())
{
if (column.isKey())
{
if (!key) {
where.append("| *Where* | ");
where.append(colName + " = " + value+ " | ");
key=true;
} else {
where.append(" | " + colName + " | ");
where.append(value + " | ");
} }
} }
if (po.is_ValueChanged(colName)) {
if (colName.equals("Created")
|| colName.equals("CreatedBy")
|| colName.equals("Updated")
|| colName.equals("UpdatedBy")
|| colName.equals("AD_Client_ID")
|| colName.equals(table.getTableName()+ "_ID")
|| colName.equals(PO.getUUIDColumnName(table.getTableName()))
|| column.getAD_Reference_ID() == DisplayType.Button)
continue;
if (po.isActive() && colName.equals("IsActive"))
continue;
if (value != null && value.length() > 0) {
set.append("\n");
set.append("| " + colName + " | ");
set.append(value + "|");
}
}
}
}// end while columns
if (where.length() > 0 && set.length() > 0) {
writeFile("\n");
writeFile("\n");
writeFile("UPDATE RECORD");
writeFile("\n");
writeFile("!");
writeFile("| Update Record |");
writeFile("\n");
writeFile("| *Table* | ");
writeFile(po.get_TableName() + " |");
writeFile("\n");
writeFile(where.toString());
writeFile("\n");
writeFile("| *Update* |");
writeFile(set.toString());
}
}
}
if(type == TYPE_AFTER_DELETE)
{
if (dontLogTables.contains(po.get_TableName().toUpperCase()))
return null;
// Ignore records created within a process
if (po.get_TrxName().startsWith("SvrProcess_"))
return null;
// Ignore records created within a workflow process
if (po.get_TrxName().startsWith("WFP_"))
return null;
writeFile("\n");
writeFile("\n");
writeFile("DELETE RECORD");
writeFile("\n");
writeFile("!");
writeFile("| Delete Record |");
writeFile("\n");
writeFile("| *Table* | ");
writeFile(po.get_TableName() + " |");
writeFile("\n");
MTable table = MTable.get(Env.getCtx(), po.get_Table_ID());
MColumn[] columns = table.getColumns(true);
boolean key=false;
for (int i = 0; i < columns.length; i++)
{
MColumn column = columns[i];
String colName = column.getColumnName();
String value=null;
if (DisplayType.isLookup(column.getAD_Reference_ID()) && DisplayType.List != column.getAD_Reference_ID()) {
value = resolveValue(po, table, column);
}else{
value=po.get_ValueAsString(colName);
}
if (column.isAllowLogging())
{
if (column.isKey())
{
if (!key) {
writeFile("| *Where* | ");
writeFile(colName + " = " + value+ " | ");
key=true;
} else {
writeFile(" | " + colName + " | ");
writeFile(value + " | ");
}
}
}
}//while columns
writeFile("\n");
writeFile("| *Delete* |");
}
} catch (Exception e) { } catch (Exception e) {
if (log.isLoggable(Level.INFO)) log.info(e.getLocalizedMessage());
return e.getLocalizedMessage(); return e.getLocalizedMessage();
} }
return null; return null;
@ -498,8 +640,7 @@ public class FitRecorder implements ModelValidator {
writeFile("|Login|"); writeFile("|Login|");
writeFile("\n"); writeFile("\n");
writeFile("|User|"); writeFile("|User|");
if (MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN, if (MSysConfig.getBooleanValue(MSysConfig.USE_EMAIL_FOR_LOGIN,false))
false))
writeFile(user.getEMail() + "|"); writeFile(user.getEMail() + "|");
else if (user.getLDAPUser() != null) else if (user.getLDAPUser() != null)
writeFile(user.getLDAPUser() + "|"); writeFile(user.getLDAPUser() + "|");