details: /erp/devel/pi/rev/a7c862c13fc5 changeset: 6542:a7c862c13fc5 user: Stefan Hühner <stefan.huehner <at> openbravo.com> date: Mon Mar 01 19:13:54 2010 +0100 summary: Fixed 12515: Add some junit-tests for the ErrorTextParser classes The testcase use some xsql-methods to raise a number of db-exceptions then uses the ErrorTextParser to translate those inho user-readable error messages and compares those to some expted values (which have to be in sync with the ad_message strings used for the translation)
diffstat: src-test/org/openbravo/test/system/ErrorTextParserTest.java | 132 ++++++++++++ src/org/openbravo/test/system/ErrorTextParserTest_data.xsql | 92 ++++++++ 2 files changed, 224 insertions(+), 0 deletions(-) diffs (233 lines): diff -r 163ea059a644 -r a7c862c13fc5 src-test/org/openbravo/test/system/ErrorTextParserTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-test/org/openbravo/test/system/ErrorTextParserTest.java Mon Mar 01 19:13:54 2010 +0100 @@ -0,0 +1,132 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.0 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SL + * All portions are Copyright (C) 2010 Openbravo SL + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.test.system; + +import java.sql.Connection; + +import javax.servlet.ServletException; + +import org.apache.log4j.Logger; +import org.openbravo.base.provider.OBConfigFileProvider; +import org.openbravo.base.secureApp.VariablesSecureApp; +import org.openbravo.database.ConnectionProvider; +import org.openbravo.database.ConnectionProviderImpl; +import org.openbravo.erpCommon.utility.OBError; +import org.openbravo.erpCommon.utility.Utility; +import org.openbravo.test.base.BaseTest; + +/** + * Test the ErrorTextParser class logic. + * + * @author huehner + */ + +public class ErrorTextParserTest extends BaseTest { + + private static final Logger log = Logger.getLogger(ErrorTextParserTest.class); + + public void testDuplicatePrimaryKey() throws Exception { + doErrorTextParserTest(1); + } + + // test disabled as postgresql notnull error message text cannot be parsed right now + // public void testNotNull() throws Exception { + // doErrorTextParserTest(2); + // } + + public void testBoolean() throws Exception { + doErrorTextParserTest(3); + } + + public void testUniqueSingleField() throws Exception { + doErrorTextParserTest(4); + } + + public void testUniqueMultipleFields() throws Exception { + doErrorTextParserTest(5); + } + + public void testFKInsert() throws Exception { + doErrorTextParserTest(6); + } + + public void testFKDelete() throws Exception { + doErrorTextParserTest(7); + } + + public void testNonBooleanCheck() throws Exception { + doErrorTextParserTest(8); + } + + private void doErrorTextParserTest(int testCase) throws Exception { + String propFile = OBConfigFileProvider.getInstance().getFileLocation(); + ConnectionProvider conn = new ConnectionProviderImpl(propFile + "/Openbravo.properties"); + VariablesSecureApp vars = new VariablesSecureApp("", "", ""); + Connection con = conn.getTransactionConnection(); + String errorMessage = ""; + String expectedErrorMessage = ""; + try { + switch (testCase) { + case 1: + expectedErrorMessage = "Internal Error: Duplicate primary key/uuid. Your record has not been saved into the table User/Contact"; + ErrorTextParserTestData.insertUserPK(con, conn, "0", "N", "name"); + break; + case 2: + expectedErrorMessage = "The column Active is mandatory and cannot be left empty."; + ErrorTextParserTestData.insertUser(con, conn, null, "name"); + break; + case 3: + expectedErrorMessage = "Only values 'Y'or 'N' may be entered into the field Active."; + ErrorTextParserTestData.insertUser(con, conn, "B", "name"); + break; + case 4: + expectedErrorMessage = "There is already a Client with the same Name. Name must be unique. You must change the values entered."; + ErrorTextParserTestData.insertClientWithName(con, conn, "System", "System"); + break; + case 5: + expectedErrorMessage = "There is already a Month Translation with the same (Month, Language). (Month, Language) must be unique. You must change the values entered."; + ErrorTextParserTestData.insertMonthTrl(con, conn); + break; + case 6: + expectedErrorMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items"; + ErrorTextParserTestData.insertUserWithClient(con, conn, "42", "Y", "Openbravo"); + break; + case 7: + expectedErrorMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items"; + ErrorTextParserTestData.deleteClient(con, conn, "0"); + break; + case 8: + expectedErrorMessage = "There is a constraint defined that was not satisfied. Please check the data entered"; + ErrorTextParserTestData.insertProcess(con, conn, "value", "name", "test"); + break; + } + + } catch (ServletException se) { + errorMessage = se.getMessage(); + } finally { + conn.releaseRollbackConnection(con); + } + + OBError trlError = Utility.translateError(conn, vars, "en_US", errorMessage); + + assertEquals(expectedErrorMessage, trlError.getMessage()); + } + +} \ No newline at end of file diff -r 163ea059a644 -r a7c862c13fc5 src/org/openbravo/test/system/ErrorTextParserTest_data.xsql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openbravo/test/system/ErrorTextParserTest_data.xsql Mon Mar 01 19:13:54 2010 +0100 @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.0 (the "License"), being the Mozilla Public License + * Version 1.1 with a permitted attribution clause; you may not use this + * file except in compliance with the License. You may obtain a copy of + * the License at http://www.openbravo.com/legal/license.html + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * The Original Code is Openbravo ERP. + * The Initial Developer of the Original Code is Openbravo SL + * All portions are Copyright (C) 2010 Openbravo SL + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ +--> + +<SqlClass name="ErrorTextParserTestData" package="org.openbravo.test.system"> + <SqlClassComment>This file is only used from the src-test/org/openbravo/test/system/ErrorTextParserText testcase</SqlClassComment> + + <SqlMethod name="dummy" type="preparedStatement" return="single"> + <Sql> + SELECT dummy from dual + </Sql> + </SqlMethod> + + <SqlMethod name="insertUserPK" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + INSERT INTO AD_USER (AD_USER_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME) + VALUES (?, '0', '0', ?, now(), '0', now(), '0', ?) + </Sql> + <Parameter name="adUserId"/> + <Parameter name="isActive"/> + <Parameter name="name"/> + </SqlMethod> + + <SqlMethod name="insertClientWithName" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + INSERT INTO AD_CLIENT (AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, VALUE, NAME) + VALUES (get_uuid(), '0', 'Y', now(), '0', now(), '0', ?, ?) + </Sql> + <Parameter name="name"/> + <Parameter name="username"/> + </SqlMethod> + + <SqlMethod name="insertUser" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + INSERT INTO AD_USER (AD_USER_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME) + VALUES (get_uuid(), '0', '0', ?, now(), '0', now(), '0', ?) + </Sql> + <Parameter name="isActive"/> + <Parameter name="name"/> + </SqlMethod> + + <SqlMethod name="insertUserWithClient" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + INSERT INTO AD_USER (AD_USER_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME) + VALUES (get_uuid(), ?, '0', ?, now(), '0', now(), '0', ?) + </Sql> + <Parameter name="adclient"/> + <Parameter name="isActive"/> + <Parameter name="name"/> + </SqlMethod> + + <SqlMethod name="deleteClient" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + DELETE FROM AD_CLIENT WHERE AD_CLIENT_ID = ? + </Sql> + <Parameter name="adclient"/> + </SqlMethod> + + <SqlMethod name="insertProcess" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + INSERT INTO AD_PROCESS (AD_PROCESS_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, VALUE, NAME, accesslevel, uipattern) + VALUES (get_uuid(), '0', '0', 'Y', now(), '0', now(), '0', ?,?,'a',?) + </Sql> + <Parameter name="value"/> + <Parameter name="name"/> + <Parameter name="uipatern"/> + </SqlMethod> + + <SqlMethod name="insertMonthTrl" type="preparedStatement" connection="true" return="rowCount"> + <Sql> + INSERT INTO AD_MONTH_TRL (AD_MONTH_TRL_ID,AD_MONTH_ID, AD_LANGUAGE, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY, NAME) + VALUES (get_uuid(), '100', 'en_US', '0', '0', 'Y', now(), '0', now(), '0', 'a') + </Sql> + </SqlMethod> + +</SqlClass> ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
