r3172 - in trunk/lima-business/src: main/java/org/chorem/lima/business main/resources test/java/org/chorem/lima/business test/resources
Author: echatellier Date: 2011-06-10 16:05:35 +0200 (Fri, 10 Jun 2011) New Revision: 3172 Url: http://chorem.org/repositories/revision/lima/3172 Log: Fix tests Added: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java Removed: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java trunk/lima-business/src/test/resources/lima_test.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java trunk/lima-business/src/main/resources/lima.properties trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/LimaConfig.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -52,9 +52,9 @@ private static final Log log = LogFactory.getLog(LimaConfig.class); - private static LimaConfig instance; + protected static LimaConfig instance; - private static final String CONFIGFILE = "lima.properties"; + protected static final String CONFIGFILE = "lima.properties"; protected AccountingRules accountingRules; @@ -83,14 +83,13 @@ * * @return */ - public AccountingRules getAccountingRules(){ + public AccountingRules getAccountingRules() { - if (accountingRules == null){ + if (accountingRules == null) { Class accountingRulesClass = getOptionAsClass(Option.RULES_NATIONALTY.key); - if (accountingRulesClass == null){ + if (accountingRulesClass == null) { accountingRules = new DefaultAccountingRules(); - } - else { + } else { try { accountingRules = (AccountingRules) accountingRulesClass.newInstance(); } catch (InstantiationException e) { @@ -120,19 +119,22 @@ Integer port = Integer.valueOf(httpPort); return port; } - - - protected void loadConfiguration(String configFileName){ - instance.setConfigFileName(configFileName); - try { - instance.parse(new String[0]); - } catch (ArgumentsParserException ex) { - if (log.isErrorEnabled()) { - log.error("Can't read configuration", ex); - } + /** + * Load configuration with custom file name. + * + * @param configFileName file name to read + */ + protected void loadConfiguration(String configFileName) { + instance.setConfigFileName(configFileName); + try { + instance.parse(); + } catch (ArgumentsParserException ex) { + if (log.isErrorEnabled()) { + log.error("Can't read configuration", ex); } - instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); + } + instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); } /** @@ -140,7 +142,7 @@ * * Contains all lima configuration key, with defaut value and * information for jaxx configuration frame ({@link #type}, - * {@link #_transient}, {@link #_final}...) + * {@link #transientBoolean}, {@link #finalBoolean}...) */ public static enum Option implements OptionDef { Modified: trunk/lima-business/src/main/resources/lima.properties =================================================================== --- trunk/lima-business/src/main/resources/lima.properties 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/main/resources/lima.properties 2011-06-10 14:05:35 UTC (rev 3172) @@ -5,7 +5,7 @@ # $Id$ # $HeadURL$ # %% -# Copyright (C) 2008 - 2010 CodeLutin +# Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric # %% # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -34,15 +34,13 @@ # directory for http server lima.report.dir=${lima.dir}/reports - # Proprietes par defaut pour une base de donnees de type H2 hibernate.hbm2ddl.auto=update #hibernate.show_sql=true - hibernate.dialect=org.hibernate.dialect.H2Dialect hibernate.connection.username=sa hibernate.connection.password= hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:~/.lima/limadb -#FIXME hibernate.connection.url=jdbc:h2:file:${lima.dir}/limadb \ No newline at end of file +#FIXME should be : hibernate.connection.url=jdbc:h2:file:${lima.dir}/limadb \ No newline at end of file Added: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -0,0 +1,51 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.business; + +import java.util.Locale; + +import org.junit.BeforeClass; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.init.ClassPathI18nInitializer; + +/** + * Common initialization code for all lima tests. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public abstract class AbstractLimaTest { + + @BeforeClass + public static void setUpClass() throws Exception { + I18n.init(new ClassPathI18nInitializer(), Locale.UK); + LimaTestConfig.getInstance(); + } + +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,9 +25,10 @@ package org.chorem.lima.business; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.chorem.lima.business.ejb.AccountServiceImpl; +import org.chorem.lima.business.ejbinterface.AccountService; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountImpl; import org.junit.Test; /** @@ -40,44 +41,42 @@ * * @author Rémi Chapelet */ -public class AccountServiceImplTest { +public class AccountServiceImplTest extends AbstractLimaTest { - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } + protected AccountService instance = new AccountServiceImpl(); /** - * On nettoie la base de données - * @throws java.lang.Exception + * Création d'un compte dans le plan comptable + * @throws LimaException */ - @AfterClass - public static void tearDownClass() throws Exception { - //instance.removeAccount("4"); - //instance.removeAccount("5"); + @Test + public void createAccountTest() throws LimaException { + Account myAccount = new AccountImpl(); + myAccount.setAccountNumber("2"); + instance.createAccount(null, myAccount); } - - @Before - public void setUp() { - //instance = new AccountServiceImpl(); + + /** + * Création d'un compte dans le plan comptable + * @throws LimaException + */ + @Test(expected=LimaException.class) + public void testCreateAccountWrongNumber() throws LimaException { + Account myAccount = new AccountImpl(); + myAccount.setAccountNumber("42"); + instance.createAccount(null, myAccount); } - - public AccountServiceImplTest() { - } - /** * Création d'un compte dans le plan comptable + * @throws LimaException */ - @Test - public void createAccountTest () - { - /*// On ajoute le compte 4 - Comptes de tiers - String result = instance.createAccount("4", "Comptes de tiers", "0","actif"); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); - // On ajoute de nouveau le compte 4 - Comptes de tiers - result = instance.createAccount("4", "Le nom n'a pas d'importance", "0","actif"); - Assert.assertEquals(ServiceHelper.ACCOUNT_DOUBLE,result);*/ + @Test(expected=LimaException.class) + public void testCreateAccountDuplicated() throws LimaException { + Account myAccount = new AccountImpl(); + myAccount.setAccountNumber("1"); + instance.createAccount(null, myAccount); + instance.createAccount(null, myAccount); } /** @@ -86,8 +85,7 @@ * enfants. */ @Test - public void createAccountDTOTest () - { + public void createAccountDTOTest() { /*String result; // Création des comptes DTO AccountDTO accountDTO = new AccountDTO("","5","COMPTES FINANCIERS","0",null,"actif"); @@ -113,8 +111,7 @@ * compte. */ @Test - public void searchAccountTest () - { + public void searchAccountTest() { /*// On recherche le compte 4 - Comptes de tiers Account result = instance.searchAccount("4"); Assert.assertEquals("Comptes de tiers",result.getLabel());*/ @@ -126,8 +123,7 @@ * compte. Il renvoie un objet DTO compte */ @Test - public void searchAccountDTOTest () - { + public void searchAccountDTOTest() { /*// On recherche le compte 4 - Comptes de tiers AccountDTO result = instance.searchAccountDTO("4"); Assert.assertEquals("Comptes de tiers",result.getLabel());*/ @@ -138,8 +134,7 @@ * Permet de tester le nombre d'enfants renvoyés appartenant à un père. */ @Test - public void searchListAccountTest () - { + public void searchListAccountTest() { /*// On recherche le compte 5 - COMPTES FINANCIERS Account account = instance.searchAccount("5"); List<Account> listAccount = instance.searchListChildAccount(account); @@ -152,8 +147,7 @@ * Permet de tester le nombre d'enfants renvoyés appartenant à un père. */ @Test - public void searchListAccountDTOTest () - { + public void searchListAccountDTOTest() { /*// On recherche le compte 5 - COMPTES FINANCIERS AccountDTO accountDTO = instance.searchAccountDTO("5"); // Il possède les comptes 50 et 51 @@ -165,8 +159,7 @@ * Permet de tester la méthode recherchant tous les comptes au format DTO. */ @Test - public void getAllAccountTest () - { + public void getAllAccountTest() { /*List<AccountDTO> listAccountDTO = instance.getAllAccount(); // doit être égal à 2 (compte 4 et 5) Assert.assertEquals(2,listAccountDTO.size());*/ @@ -180,8 +173,7 @@ * unique lors de la création). */ @Test - public void removeAccountTest () - { + public void removeAccountTest() { /*String result; // Création de comptes instance.createAccount("40", "Fournisseurs", "4","actif"); @@ -215,8 +207,7 @@ * sur le compte 5, et supprimons le compte 51 (et ses enfants). */ @Test - public void updateTest () - { + public void updateTest() { /*String result; // On recherche le compte 5 - COMPTES FINANCIERS AccountDTO accountDTO = instance.searchAccountDTO("5"); Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -41,18 +41,13 @@ * * @author Rémi Chapelet */ -public class EntryBookServiceImplTest { +public class EntryBookServiceImplTest extends AbstractLimaTest { /** log. */ private static final Log log = LogFactory.getLog(EntryBookServiceImplTest.class); private static EntryBookServiceImpl instance; - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } - /** * On nettoie la base de données * @throws java.lang.Exception Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -45,18 +45,13 @@ * * @author Rémi Chapelet */ -public class FinancialPeriodServiceImplTest { +public class FinancialPeriodServiceImplTest extends AbstractLimaTest { /** log. */ private static final Log log = LogFactory.getLog(FinancialPeriodServiceImplTest.class); private static FinancialPeriodServiceImpl instance; - @BeforeClass - public static void setUpClass() throws Exception { - LimaConfigTest.getInstance(); - } - /** * On nettoie la base de données * @throws java.lang.Exception Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -43,7 +43,7 @@ * * @author Rémi Chapelet */ -public class FiscalPeriodServiceImplTest { +public class FiscalPeriodServiceImplTest extends AbstractLimaTest { /** log. */ private static final Log log = LogFactory Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -25,12 +25,13 @@ package org.chorem.lima.business; +import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ejb.AccountServiceImpl; import org.chorem.lima.business.ejb.EntryBookServiceImpl; -import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; import org.chorem.lima.business.ejb.FinancialTransactionServiceImpl; +import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -39,10 +40,10 @@ * * @author Rémi Chapelet */ -public class GeneratorTest { +public class GeneratorTest extends AbstractLimaTest { /** log. */ - private static final org.apache.commons.logging.Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); + private static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); private static FinancialTransactionServiceImpl instanceTransaction; private static FiscalPeriodServiceImpl instancePeriod; @@ -51,12 +52,6 @@ private static AccountServiceImpl instanceAccount; private static String topiaIDTransaction; - - @BeforeClass - public static void setUpClass() throws Exception { - //LimaConfigTest.getInstance(); - } - @Before public void setUp() { /* instanceTransaction = new FinancialTransactionServiceImpl(); Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -1,57 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2010 CodeLutin - * %% - * 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 3 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, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.business; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Ignore; - -/** - * TODO add comment here. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -@Ignore -public class LimaConfigTest extends LimaConfig { - - private static final Log log = LogFactory.getLog(LimaConfig.class); - - private static final String configFile = "lima_test.properties"; - - /* - public static LimaConfig getInstance() { - - if (instance == null) { - instance = new LimaConfig(); - instance.loadConfiguration(configFile); - } - return instance; - }*/ -} Copied: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java (from rev 3168, trunk/lima-business/src/test/java/org/chorem/lima/business/LimaConfigTest.java) =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java 2011-06-10 14:05:35 UTC (rev 3172) @@ -0,0 +1,79 @@ +/* + * #%L + * Lima business + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2010 CodeLutin + * %% + * 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.business; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.LimaCallaoDAOHelper; + +/** + * Application config instance used it tests. (load custom test configuration) + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaTestConfig extends LimaConfig { + + private static final Log log = LogFactory.getLog(LimaTestConfig.class); + + public static LimaConfig getInstance() { + if (instance == null) { + instance = new LimaTestConfig(); + // do not call parse() method (don't read /etc... + + Properties testProperties = new Properties(); + InputStream stream = LimaTestConfig.class.getResourceAsStream("/" + CONFIGFILE); + + try { + testProperties.load(stream); + } catch (IOException ex) { + throw new RuntimeException("Can't init test configuration", ex); + } + + // override somes + String testDir = System.getProperty("java.io.tmpdir") + File.separator + "limatestdb"; + testProperties.put("lima.dir", testDir); + testProperties.put("hibernate.connection.url", "jdbc:h2:file:" + testDir + File.separator + "data"); + testProperties.put("hibernate.hbm2ddl.auto", "update"); + + instance.setOptions(testProperties); + instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); + + if (log.isInfoEnabled()) { + log.info("Using test configuration" + instance.getFlatOptions()); + } + } + return instance; + } +} Deleted: trunk/lima-business/src/test/resources/lima_test.properties =================================================================== --- trunk/lima-business/src/test/resources/lima_test.properties 2011-06-10 13:34:35 UTC (rev 3171) +++ trunk/lima-business/src/test/resources/lima_test.properties 2011-06-10 14:05:35 UTC (rev 3172) @@ -1,41 +0,0 @@ -### -# #%L -# Lima business -# -# $Id$ -# $HeadURL$ -# %% -# Copyright (C) 2008 - 2010 CodeLutin -# %% -# 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 3 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, see -# <http://www.gnu.org/licenses/gpl-3.0.html>. -# #L% -### -# Proprietes par defaut pour une base de donnees de type H2 -hibernate.hbm2ddl.auto=update -hibernate.show_sql=false - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.connection.username=sa -hibernate.connection.password= -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:file:target/lima/limadb - -# Permet de preciser les classes a utiliser -#topia.persistence.classes=org.chorem.callao.entity.AccountImpl, \ -#org.chorem.callao.entity.ClientImpl, \ -#org.chorem.callao.entity.EntryImpl, org.chorem.callao.entity.PeriodImpl, \ -#org.chorem.callao.entity.JournalImpl, org.chorem.callao.entity.ProjectImpl, \ -#org.chorem.callao.entity.TimeSpanImpl, org.chorem.callao.entity.TransactionImpl, \ -#org.chorem.callao.entity.UsersImpl, org.chorem.callao.entity.LogImpl
participants (1)
-
echatellier@users.chorem.org