r3320 - in trunk/lima-business/src: main/java/org/chorem/lima/business/ejb main/java/org/chorem/lima/business/ejbinterface test/java/org/chorem/lima/business
Author: echatellier Date: 2012-01-13 10:56:57 +0100 (Fri, 13 Jan 2012) New Revision: 3320 Url: http://chorem.org/repositories/revision/lima/3320 Log: Begin test refactoring. Added: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaMiscTest.java Removed: trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 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 Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -150,28 +150,6 @@ } @Override - public List<EntryBook> getAllEntryByProperty(String propertyName, - String value) throws LimaException { - List<EntryBook> entryBookList = null; - - TopiaContext transaction = beginTransaction(rootContext); - - try { - - EntryBookDAO entryBookDAO = - LimaCallaoDAOHelper.getEntryBookDAO(transaction); - entryBookList = entryBookDAO.findAllByProperty(propertyName, value); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - - return entryBookList; - } - - - @Override public void updateEntryBook(EntryBook entryBook) throws LimaException { TopiaContext transaction = beginTransaction(rootContext); Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 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 @@ -36,23 +36,27 @@ * * @author chatellier * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ - @Remote public interface EntryBookService { - /** + * Get all entry book. + * * @return all entrybook * @throws LimaException */ List<EntryBook> getAllEntryBooks() throws LimaException; - List<EntryBook> getAllEntryByProperty(String propertyName, String value) throws LimaException; - + /** + * Create new entry book. + * + * @param entryBook + * @throws LimaException + */ void createEntryBook(EntryBook entryBook) throws LimaException; /** Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -3,7 +3,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2011 Codelutin, Chatellier Eric + * Copyright (C) 2011 - 2012 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 @@ -23,27 +23,101 @@ package org.chorem.lima.business; -import org.junit.BeforeClass; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.text.DateFormat; +import java.util.Locale; +import java.util.Properties; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaConfig.Option; +import org.chorem.lima.business.accountingrules.DefaultAccountingRules; +import org.chorem.lima.entity.LimaCallaoDAOHelper; +import org.junit.After; +import org.junit.Before; import org.nuiton.i18n.I18n; import org.nuiton.i18n.init.ClassPathI18nInitializer; -import java.util.Locale; - /** * Common initialization code for all lima tests. * * @author chatellier * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ public abstract class AbstractLimaTest { - @BeforeClass - public static void setUpClass() throws Exception { + private static final Log log = LogFactory.getLog(AbstractLimaTest.class); + + protected static DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); + + @Before + public void setUpLocale() throws Exception { I18n.init(new ClassPathI18nInitializer(), Locale.UK); - LimaTestConfig.getInstance(); } + /** + * Return a new instance of configuration defined on a new database at + * each call. + * + * @return single test config + */ + protected LimaConfig getTestConfiguration() { + LimaConfig instance = new LimaConfig(); + + // do not call parse() method (don't read /etc...) + // load file manually (lima.properties) + Properties testProperties = new Properties(); + InputStream stream = AbstractLimaTest.class.getResourceAsStream("/" + Option.CONFIG_FILE.getDefaultValue()); + + 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 + "lima" + File.separator; + testDir += "testdb" + System.currentTimeMillis(); + testProperties.setProperty(Option.DATA_DIR.getKey(), testDir); + testProperties.setProperty("hibernate.connection.url", "jdbc:h2:file:" + testDir + File.separator + "data"); + //testProperties.setProperty("hibernate.hbm2ddl.auto", "update"); + + instance.setOptions(testProperties); + instance.setOption("topia.persistence.classes", LimaCallaoDAOHelper.getImplementationClassesAsString()); + + if (log.isDebugEnabled()) { + log.debug("Using test configuration" + instance.getFlatOptions()); + } + return instance; + } + + @Before + public void setUpTestConfig() throws Exception { + LimaConfig.instance = getTestConfiguration(); + } + + @After + public void cleanDatabase() throws IOException { + LimaConfig config = LimaConfig.getInstance(); + FileUtils.deleteDirectory(config.getDataDir()); + } + + /** + * Default rule configuration should stay in France rule. + * + * But test will run without a specific rule during normal tests + * and france rule will be re-enabled for specifics tests. + * @throws Exception + */ + @Before + public void setUpDefaultRule() throws Exception { + LimaConfig config = LimaConfig.getInstance(); + config.setAccountingRule(DefaultAccountingRules.class.getName()); + } } 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 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2008 - 2012 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,12 +25,19 @@ package org.chorem.lima.business; -// tchemit-2011-08-11 This test must be redone thinks it does not respect -// See http://chorem.org/issues/428 +import java.util.List; +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.Assert; +import org.junit.Before; +import org.junit.Test; + /** - * Tests pour la gestion des comptes dans le plan comptable - * <p/> + * Tests pour la gestion des comptes dans le plan comptable. + * * Vérification sur l'ajout, la modification et suppression d'un compte. * Il existe également des tests sur des actions à partir de DTO. La classe * AccountServiceImplTest possède une méthode upload qui, à partir d'un DTO, @@ -40,240 +47,191 @@ */ public class AccountServiceImplTest extends AbstractLimaTest { -// protected AccountService instance; -// -// @BeforeClass -// public static void beforeclass() throws LimaException { -// deleteAccounts(); -// } -// -// @Before -// public void setUp() throws LimaException { -// instance = new AccountServiceImpl(); -// -// // create a account -// Account myAccount = new AccountImpl(); -// myAccount.setAccountNumber("4"); -// myAccount.setLabel("Comptes de tiers"); -// instance.createAccount(null, myAccount); -// } -// -// @After -// public void tearDown() throws LimaException { -// deleteAccounts(); -// } -// -// private static void deleteAccounts() throws LimaException { -// AccountService instance = new AccountServiceImpl(); -// instance.removeAllAccount(); -// } -// -//// /** -//// * Création d'un compte dans le plan comptable -//// * @throws LimaException -//// */ -//// @Test -//// public void createAccountTest() throws LimaException { -//// Account myAccount = new AccountImpl(); -//// myAccount.setAccountNumber("4"); -//// myAccount.setLabel("Comptes de tiers"); -//// instance.createAccount(null, myAccount); -//// } -// -// /** -// * 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); -// } -// -// /** -// * Création d'un compte dans le plan comptable -// * @throws LimaException -// */ -// @Test(expected=LimaException.class) -// public void testCreateAccountDuplicated() throws LimaException { -// Account myAccount = new AccountImpl(); -// myAccount.setAccountNumber("1"); -// instance.createAccount(null, myAccount); -// instance.createAccount(null, myAccount); -// } -// -// /** -// * Permet de tester l'ajout des comptes sous format DTO. La grande différence -// * entre la création classique, l'applicaion va enregistrer tous les comptes -// * enfants. -// * @throws LimaException -// */ -// @Test -// public void createAccountDAOTest() throws LimaException { -// // Création des comptes -// Account account = new AccountImpl(); -// account.setAccountNumber("5"); -// account.setLabel("COMPTES FINANCIERS"); -// instance.createAccount(null, account); -// Account accountChild1 = new AccountImpl(); -// accountChild1.setAccountNumber("50"); -// accountChild1.setLabel("Valeurs mobilières de placement"); -// //accountChild1.setMasterAccount(account); -// instance.createAccount(account, accountChild1); -// -// Account accountChild2 = new AccountImpl(); -// accountChild2.setAccountNumber("51"); -// accountChild2.setLabel("Banques établissements financiers et assimilés"); -// //accountChild2.setMasterAccount(account); -// instance.createAccount(account, accountChild2); -// -// Account accountChildChild1 = new AccountImpl(); -// accountChildChild1.setAccountNumber("511"); -// accountChildChild1.setLabel("Valeurs à l'encaissement"); -// //accountChildChild1.setMasterAccount(accountChild2); -// instance.createAccount(accountChild2, accountChildChild1); -// -// Account accountChildChild2 = new AccountImpl(); -// accountChildChild2.setAccountNumber("512"); -// accountChildChild2.setLabel("Banques"); -// //accountChildChild2.setMasterAccount(accountChild2); -// instance.createAccount(accountChild2, accountChildChild2); -// } -// -// -// /** -// * Recherche d'un compte dans le plan comptable à partir d'un numéro de -// * compte. -// * @throws LimaException -// */ -// @Test -// public void searchAccountTest() throws LimaException { -// // On recherche le compte 4 - Comptes de tiers -// Account result = instance.getAccountByNumber("4"); -// Assert.assertEquals("Comptes de tiers",result.getLabel()); -// } -// -// -// /** -// * Permet de tester le nombre d'enfants renvoyés appartenant à un père. -// * @throws LimaException -// */ -// @Test -// public void searchListAccountTest() throws LimaException { -// // On recherche le compte 5 - COMPTES FINANCIERS -// Account account = instance.getAccountByNumber("5"); -// List<Account> listAccount = instance.getChildrenAccounts(account); -// // Il possède les comptes 50 et 51 -// Assert.assertEquals(2,listAccount.size()); -// } -// -// -// /** -// * Permet de tester la méthode recherchant tous les comptes au format DTO. -// * @throws LimaException -// */ -// @Test -// public void getAllAccountTest() throws LimaException { -// List<Account> listAccount = instance.getAllAccounts(); -// Assert.assertEquals(9,listAccount.size()); -// } -// -// -// /** -// * Permet de tester si un compte est bien effacé. -// * @throws LimaException -// */ -// @Test -// public void removeAccountTest() throws LimaException { -// Account masterAccount = instance.getAccountByNumber("4"); -// // Création de comptes -// Account account = new AccountImpl(); -// account.setAccountNumber("40"); -// account.setLabel("Fournisseurs"); -// instance.createAccount(masterAccount, account); -// -// Account account2 = new AccountImpl(); -// account2.setAccountNumber("41"); -// account2.setLabel("Usagers"); -// instance.createAccount(masterAccount, account2); -// -// Account account3 = new AccountImpl(); -// account3.setAccountNumber("44"); -// account3.setLabel("Etat"); -// instance.createAccount(masterAccount, account3); -// -// // On souhaite supprimer le compte 41. Ce compte existe bien. Il ne possède -// // pas de fils. La suppression se déroule bien. -// instance.removeAccount(account2); -// -// // On recherche les fils du compte 4 -// List<Account> listAccount = instance.getChildrenAccounts(masterAccount); -// // Il ne doit en possèder que 2 (au lieu de 3) -// Assert.assertEquals(2,listAccount.size()); -// } -// -// -// @Test(expected=LimaException.class) -// public void removeUnexistedAccountTest() throws LimaException { -// // On souhaite supprimer le compte 422, ce dernier n'existe pas. La -// // suppression ne peut s'effectuer. -// Account account4 = new AccountImpl(); -// account4.setAccountNumber("422"); -// account4.setLabel("Unsaved account"); -// instance.removeAccount(account4); -// } -// -// -// /** -// * Cette méthode permet de tester la mise à jour d'un compte au format DTO. -// * Il suffit d'envoyer un compte DTO avec des ajouts, modifications, et -// * suppression. Il est automatiquement mis à jour dans Callao. -// * Cette méthode est intéressante, mais demande de la ressource importante. -// * Dans ce test, nous utilitons le compte numéro 5. Ce dernier a pour enfants -// * 50 et 51, dont 51 a à son tour les comptes enfants 511 et 512. -// * Nous ajoutons un compte supplémentaire 53 à 5. Nous modifions une valeur -// * sur le compte 5, et supprimons le compte 51 (et ses enfants). -// * @throws LimaException -// */ -// @Test -// public void updateTest() throws LimaException { -// // On recherche le compte 5 - COMPTES FINANCIERS -// Account account = instance.getAccountByNumber("5"); -// -// // {ETAPE 1} Modification du nom pour le compte 5 -// account.setLabel("COMPTES FINANCIERS modifié"); -// -// // {ETAPE 2} Ajout du compte 53 -// Account accountChild = new AccountImpl(); -// accountChild.setAccountNumber("53"); -// accountChild.setLabel("Caisse"); -// accountChild.setMasterAccount(account); -// -// instance.createAccount(account, accountChild); -// -// account.addSubAccounts(accountChild); -// -// // {ETAPE 3} Supprime le compte 51 (ainsi que ses enfants 511 et 512) -// Account accountRemove = instance.getAccountByNumber("51"); -// -// account.removeSubAccounts(accountRemove); -// -// // Met à jour le compte 5 DTO dans la bdd ainsi que toutes les {ETAPE *} -// instance.updateAccount(account); -// -// // Vérification ETAPE -// -// // ETAPE 1 -// account = instance.getAccountByNumber("5"); -// Assert.assertEquals("COMPTES FINANCIERS modifié",account.getLabel()); -// // ETAPE 2 -// account = instance.getAccountByNumber("53"); -// Assert.assertEquals("Caisse",account.getLabel()); -// // ETAPE 3 -// account = instance.getAccountByNumber("5"); // les comptes fils de 5 -// List<Account> listAccount = instance.getChildrenAccounts(account); -// // Il doit avoir 50, 51 (de la méthode searchListAccountTest) et 53 -// Assert.assertEquals(3,listAccount.size()); -// } + protected AccountService accountService = new AccountServiceImpl(); + + @Before + public void setUp() throws LimaException { + // creation des comptes + Account classFinancier = new AccountImpl(); + classFinancier.setAccountNumber("5"); + classFinancier.setLabel("Comptes financiers"); + accountService.createAccount(null, classFinancier); + + Account accountVmp = new AccountImpl(); + accountVmp.setAccountNumber("50"); + accountVmp.setLabel("Valeurs mobilières de placement"); + accountService.createAccount(classFinancier, accountVmp); + + Account accountBefa = new AccountImpl(); + accountBefa.setAccountNumber("51"); + accountBefa.setLabel("Banques établissements financiers et assimilés"); + accountService.createAccount(classFinancier, accountBefa); + + Account accountVmpVae = new AccountImpl(); + accountVmpVae.setAccountNumber("511"); + accountVmpVae.setLabel("Valeurs à l'encaissement"); + accountService.createAccount(accountBefa, accountVmpVae); + + Account accountBanques = new AccountImpl(); + accountBanques.setAccountNumber("512"); + accountBanques.setLabel("Banques"); + accountService.createAccount(accountBefa, accountBanques); + } + + /** + * Création d'un compte dans le plan comptable. + * @throws LimaException + */ + @Test + public void createAccountTest() throws LimaException { + Account myAccount = new AccountImpl(); + myAccount.setAccountNumber("2"); + myAccount.setLabel("Comptes d'immobilisations"); + accountService.createAccount(null, myAccount); + } + + /** + * Création d'un compte dans le plan comptable (echec duplication). + * + * @throws LimaException + */ + @Test(expected = LimaException.class) + public void createAccountEchecTest() throws LimaException { + Account myAccount = new AccountImpl(); + myAccount.setAccountNumber("5"); + myAccount.setLabel("Comptes de capitaux"); + accountService.createAccount(null, myAccount); + } + + /** + * Création d'un compte dans le plan comptable. + * + * Le test ne doit pas echoué avec les regles par defaut, mais peut echouer + * suivant certaines autres regles. + * + * @throws LimaException + */ + @Test + public void testCreateAccountWrongNumber() throws LimaException { + Account myAccount = new AccountImpl(); + myAccount.setAccountNumber("42"); // erreur de compte (4) + myAccount.setLabel("Comptes de tiers"); + accountService.createAccount(null, myAccount); + } + + /** + * Permet de tester l'ajout des comptes sous format DTO. La grande différence + * entre la création classique, l'applicaion va enregistrer tous les comptes + * enfants. + * @throws LimaException + */ + @Test + public void createAccountWithChildTest() throws LimaException { + // Création des comptes + Account classCharges = new AccountImpl(); + classCharges.setAccountNumber("6"); + classCharges.setLabel("Comptes de charges"); + accountService.createAccount(null, classCharges); + + Account accountAchat = new AccountImpl(); + accountAchat.setAccountNumber("60"); + accountAchat.setLabel("Achats (sauf 603)"); + accountService.createAccount(classCharges, accountAchat); + + Account accountSe = new AccountImpl(); + accountSe.setAccountNumber("61"); + accountSe.setLabel("Services extérieurs"); + accountService.createAccount(classCharges, accountSe); + + Account accountVs = new AccountImpl(); + accountVs.setAccountNumber("603"); + accountVs.setLabel("Variations des stocks (approvisionnements et marchandises)"); + accountService.createAccount(accountAchat, accountVs); + } + + /** + * Permet de tester l'ajout des comptes sous format DTO. La grande différence + * entre la création classique, l'applicaion va enregistrer tous les comptes + * enfants. + * @throws LimaException + */ + @Test(expected = LimaException.class) + public void createAccountWithChildFailureTest() throws LimaException { + // Création des comptes + Account classFinancier = new AccountImpl(); + classFinancier.setAccountNumber("5"); + classFinancier.setLabel("Comptes financiers"); + accountService.createAccount(null, classFinancier); + + Account accountVmp = new AccountImpl(); + accountVmp.setAccountNumber("40"); + accountVmp.setLabel("Fournisseurs et comptes rattachés"); + accountService.createAccount(classFinancier, accountVmp); + } + + /** + * Recherche d'un compte dans le plan comptable à partir d'un numéro de + * compte. + * @throws LimaException + */ + @Test + public void searchAccountTest() throws LimaException { + // On recherche le compte 5 Comptes financiers + Account result = accountService.getAccountByNumber("5"); + Assert.assertEquals("Comptes financiers", result.getLabel()); + } + + /** + * Permet de tester le nombre d'enfants renvoyés appartenant à un père. + * @throws LimaException + */ + @Test + public void getChildrenAccountsTest() throws LimaException { + // On recherche le compte 5 - COMPTES FINANCIERS + Account account = accountService.getAccountByNumber("5"); + List<Account> listAccount = accountService.getChildrenAccounts(account); + Assert.assertEquals(2, listAccount.size()); + } + + /** + * Permet de tester la méthode recherchant tous les comptes. + * + * @throws LimaException + */ + @Test + public void getAllAccountTest() throws LimaException { + List<Account> listAccount = accountService.getAllAccounts(); + Assert.assertEquals(5, listAccount.size()); + } + + /** + * Permet de tester si un compte est bien effacé. + * + * @throws LimaException + */ + @Test + public void removeAccountTest() throws LimaException { + Account accountToRemove = accountService.getAccountByNumber("51"); + + // On souhaite supprimer le compte 51. Ce compte existe bien. Il possede + // des fils. La suppression se déroule bien. + accountService.removeAccount(accountToRemove); + + // Il ne doit rester que 2 compte (5, 50) + Assert.assertEquals(2, accountService.getAllAccounts().size()); + } + + /** + * On souhaite supprimer le compte 422, ce dernier n'existe pas. La + * suppression ne peut s'effectuer. + * + * @throws LimaException + */ + @Test(expected = LimaException.class) + public void removeUnexistedAccountTest() throws LimaException { + Account account4 = new AccountImpl(); + account4.setAccountNumber("422"); + account4.setLabel("Unsaved account"); + accountService.removeAccount(account4); + } } \ No newline at end of file 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 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 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,22 +25,16 @@ package org.chorem.lima.business; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ejb.EntryBookServiceImpl; import org.chorem.lima.business.ejbinterface.EntryBookService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; -import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; -import java.util.List; - /** - * Tests pour la gestion des journaux + * Tests pour la gestion des journaux. * <p/> * L'application peut gérer plusieurs journaux pour la gestion des transactions. * Il est tester ici l'ajout, la recherche. @@ -49,92 +43,31 @@ */ public class EntryBookServiceImplTest extends AbstractLimaTest { - /** log. */ - private static final Log log = LogFactory.getLog(EntryBookServiceImplTest.class); + protected static EntryBookService entryBookService = new EntryBookServiceImpl(); - private static EntryBookServiceImpl instance; + protected static final String JOURNAL_DES_VENTES = "Journal des ventes"; - public static final String JOURNAL_DES_VENTES = "Journal des ventes"; - - public static final String NEW_CODE = "New Code"; - - // /** -// * On nettoie la base de données -// * @throws java.lang.Exception -// */ -// @AfterClass -// public static void tearDownClass() throws Exception { -// List<EntryBook> list = instance.getAllEntryBooks(); -// // On supprime chaque journal -// for (EntryBook entryBook : list) { -// instance.removeEntryBook(entryBook); -// } -// } - - @BeforeClass - public static void beforeclass() throws LimaException { - deleteAllBookEntries(); - } - @Before public void setUp() throws LimaException { - instance = new EntryBookServiceImpl(); - // create a entry book EntryBook entryBook = new EntryBookImpl(); entryBook.setLabel(JOURNAL_DES_VENTES); entryBook.setCode("jdv"); - instance.createEntryBook(entryBook); + entryBookService.createEntryBook(entryBook); } - @After - public void tearDown() throws LimaException { - deleteAllBookEntries(); - } - - private static void deleteAllBookEntries() throws LimaException { - EntryBookService instance = new EntryBookServiceImpl(); - List<EntryBook> list = instance.getAllEntryBooks(); - // On supprime chaque journal - for (EntryBook entryBook : list) { - instance.removeEntryBook(entryBook); - } - } - -// /** -// * Permet de tester l'ajout d'un journal dans la base de données. -// * @throws LimaException -// */ -// @Test -// public void createJournalTest() throws LimaException { -// EntryBook entryBook = new EntryBookImpl(); -// entryBook.setLabel("Journal des ventes"); -// entryBook.setCode("jdv"); -// instance.createEntryBook(entryBook); -// } - /** - * Permet de tester la recherche d'un journal suivant son préfixe. - * + * Permet de tester l'ajout d'un journal dans la base de données. + * (erreur duplication). + * * @throws LimaException */ - @Test - public void searchJournalWithLabelTest() throws LimaException { - List<EntryBook> result = instance.getAllEntryByProperty(EntryBook.PROPERTY_LABEL, JOURNAL_DES_VENTES); - Assert.assertNotNull(result); - Assert.assertEquals(1, result.size()); - - EntryBook entryBook = result.get(0); - Assert.assertNotNull(entryBook); - Assert.assertEquals("Journal des ventes", entryBook.getLabel()); - - // On ne sait pas ici si ça existe ?! - result = instance.getAllEntryByProperty(EntryBook.PROPERTY_LABEL, "Journal des achats"); - Assert.assertNotNull(result); - Assert.assertTrue(result.isEmpty()); - // TODO Il faut que ca soit vide : cette entree n'existe pas (pas créée dans le test) -// Assert.assertTrue(result.isEmpty()); - + @Test(expected=LimaException.class) + public void createJournalTest() throws LimaException { + EntryBook entryBook = new EntryBookImpl(); + entryBook.setLabel(JOURNAL_DES_VENTES); + entryBook.setCode("jdv"); + entryBookService.createEntryBook(entryBook); } /** @@ -144,25 +77,17 @@ */ @Test public void modifyJournalTest() throws LimaException { - EntryBook entryBook; - List<EntryBook> entryBooksList; - entryBooksList = instance.getAllEntryByProperty(EntryBook.PROPERTY_LABEL, JOURNAL_DES_VENTES); - Assert.assertNotNull(entryBooksList); - Assert.assertEquals(1, entryBooksList.size()); - entryBook = entryBooksList.get(0); + EntryBook entryBook = entryBookService.getAllEntryBooks().get(0); Assert.assertNotNull(entryBook); Assert.assertEquals(JOURNAL_DES_VENTES, entryBook.getLabel()); - entryBook.setCode(NEW_CODE); - instance.updateEntryBook(entryBook); + entryBook.setCode("Journal des achats"); + entryBookService.updateEntryBook(entryBook); // Recherche du journal dans la bdd - entryBooksList = instance.getAllEntryByProperty(EntryBook.PROPERTY_LABEL, JOURNAL_DES_VENTES); - Assert.assertNotNull(entryBooksList); - Assert.assertEquals(1, entryBooksList.size()); - entryBook = entryBooksList.get(0); + entryBook = entryBookService.getAllEntryBooks().get(0); Assert.assertNotNull(entryBook); - Assert.assertEquals(NEW_CODE, entryBook.getCode()); + Assert.assertEquals("Journal des achats", entryBook.getLabel()); } } \ No newline at end of file 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 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 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,8 +25,8 @@ package org.chorem.lima.business; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import java.util.Date; + import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; import org.junit.AfterClass; import org.junit.Before; @@ -46,45 +46,29 @@ */ public class FinancialPeriodServiceImplTest extends AbstractLimaTest { - /** log. */ - private static final Log log = LogFactory.getLog(FinancialPeriodServiceImplTest.class); + protected static FinancialPeriodServiceImpl financialPerdiodService = + new FinancialPeriodServiceImpl(); - private static FinancialPeriodServiceImpl instance; - - /** - * On nettoie la base de données - * - * @throws Exception - */ - @AfterClass - public static void tearDownClass() throws Exception { - /*Date beginTimeSpan = new Date(111,0,1); - TimeSpan timeSpan = instance.searchTimeSpanByDate(beginTimeSpan); - instance.removeTimeSpan(timeSpan);*/ - } - @Before public void setUp() { - //instance = new FinancialPeriodServiceImpl(); - } - public FinancialPeriodServiceImplTest() { } - /** Permet de tester l'ajout d'un timspan */ + /** + * Permet de tester l'ajout d'un timespan. + */ @Test public void createTimeSpanTest() { /*// debut 1 janvier 2011 - Date beginTimeSpan = new Date(111, 0, 1); + Date beginTimeSpan = df.parse("Junary 1, 2011"); // fin 15 janvier 2011 - Date endTimeSpan = new Date(111, 0, 15); - String result; + Date endTimeSpan = df.parse("Junary 15, 2011"); // Création du timespan du 1 janvier au 31 janvier. // Malgre la date de fin du 15 janvier, elle ne prend en compte que la // date de début. La période a pour valeur nulle, et le timepsan est // non bloqué. - result = instance.createTimeSpan(beginTimeSpan, endTimeSpan, null, + result = financialPerdiodService.createTimeSpan(beginTimeSpan, endTimeSpan, null, false); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS, result);*/ } 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 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 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 @@ -58,7 +58,7 @@ private TopiaContext rootContext; public FiscalPeriodServiceImplTest() { - LimaConfig config = LimaTestConfig.getInstance(); + LimaConfig config = LimaConfig.getInstance(); try { rootContext = TopiaContextFactory.getContext(config.getOptions()); } catch (TopiaNotFoundException ex) { Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -1,221 +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.chorem.lima.business.ejb.AccountServiceImpl; -import org.chorem.lima.business.ejb.EntryBookServiceImpl; -import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; -import org.chorem.lima.business.ejb.FinancialTransactionServiceImpl; -import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountImpl; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.EntryBookImpl; -import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.entity.FiscalPeriodImpl; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -/** @author Rémi Chapelet */ -public class GeneratorTest extends AbstractLimaTest { - - /** log. */ - private static final Log log = LogFactory.getLog(FinancialTransactionServiceImpl.class); - - private static FinancialTransactionServiceImpl instanceTransaction; - - private static FiscalPeriodServiceImpl instanceFiscalPeriod; - - private static FinancialPeriodServiceImpl instanceFinancialPeriod; - - private static EntryBookServiceImpl instanceJournal; - - private static AccountServiceImpl instanceAccount; - - private static String topiaIDTransaction; - - @Before - public void setUp() { - instanceTransaction = new FinancialTransactionServiceImpl(); - instanceFiscalPeriod = new FiscalPeriodServiceImpl(); - instanceFinancialPeriod = new FinancialPeriodServiceImpl(); - instanceJournal = new EntryBookServiceImpl(); - instanceAccount = new AccountServiceImpl(); - } - - - /** - * Permet de tester l'ajout d'un timspan - * - * @throws LimaException - */ - @Test - public void generate() throws LimaException { - - // Création Journal - EntryBook entryBook1 = new EntryBookImpl(); - entryBook1.setLabel("Journal des ventes"); - entryBook1.setCode("jv"); - instanceJournal.createEntryBook(entryBook1); - EntryBook entryBook2 = new EntryBookImpl(); - entryBook2.setLabel("Journal des achats"); - entryBook2.setCode("ja"); - instanceJournal.createEntryBook(entryBook2); - EntryBook entryBook3 = new EntryBookImpl(); - entryBook3.setLabel("Journal de trésorerie"); - entryBook3.setCode("jt"); - instanceJournal.createEntryBook(entryBook3); - EntryBook entryBook4 = new EntryBookImpl(); - entryBook4.setLabel("Journal des opérations diverses"); - entryBook4.setCode("od"); - instanceJournal.createEntryBook(entryBook4); - EntryBook entryBook5 = new EntryBookImpl(); - entryBook5.setLabel("Journal de banque"); - entryBook5.setCode("jb"); - /*instanceJournal.createJournal("Journal de banque 2", "jb2","description"); - instanceJournal.createJournal("Journal de banque 3", "jb3","description"); - instanceJournal.createJournal("Journal de banque 4", "jb4","description"); - instanceJournal.createJournal("Journal de banque 5", "jb5","description"); - instanceJournal.createJournal("Journal de banque 6", "jb6","description"); - instanceJournal.createJournal("Journal de banque 7", "jb7","description"); - instanceJournal.createJournal("Journal de banque 8", "jb8","description");*/ - - // Création account - Account account1 = new AccountImpl(); - account1.setAccountNumber("1"); - account1.setLabel("COMPTES DE CAPITAUX"); - instanceAccount.createAccount(null, account1); - Account account2 = new AccountImpl(); - account2.setAccountNumber("2"); - account2.setLabel("COMPTES D'IMMOBILISATIONS"); - instanceAccount.createAccount(null, account2); - Account account3 = new AccountImpl(); - account3.setAccountNumber("3"); - account3.setLabel("COMPTES DE STOCKS ET EN-COURS"); - instanceAccount.createAccount(null, account3); - /*instanceAccount.createAccount(4, "COMPTES DE TIERS ", null); - instanceAccount.createAccount(5, "COMPTES FINANCIERS", null); - instanceAccount.createAccount(6, "COMPTES DE CHARGES", null); - instanceAccount.createAccount(7, "COMPTES DE PRODUITS", null); - instanceAccount.createAccount(8, "COMPTES SPECIAUX", null); - instanceAccount.createAccount(10, "Capital et réserves", 1); - instanceAccount.createAccount(106, "Réserves", 10); - instanceAccount.createAccount(1061, "Réserve légale",106 ); - instanceAccount.createAccount(1062, "Réserves indisponibles", 106); - instanceAccount.createAccount(1063, "Réserves statutaires ou contractuelles", 106); - instanceAccount.createAccount(1064, "Réserves réglementées", 106); - instanceAccount.createAccount(1068, "Autres réserves", 106); - instanceAccount.createAccount(11, "Report à nouveau (solde créditeur ou débiteur)", 1); - instanceAccount.createAccount(12, "Résultat de l'exercice (bénéfice ou perte)", 1); - instanceAccount.createAccount(14, "Provisions réglementées", 1); - instanceAccount.createAccount(15, "Provisions pour risques et charges", 1); - instanceAccount.createAccount(151, "Provisions pour risques", 15); - instanceAccount.createAccount(155, "Provisions pour impôts", 15); - instanceAccount.createAccount(20, "Immobilisations incorporelles", 2); - instanceAccount.createAccount(201, "Frais d'établissement", 20); - instanceAccount.createAccount(207, "Fonds commercial", 20); - instanceAccount.createAccount(21, "Immobilisations corporelles", 2);*/ - - Date beginDate; - Date endDate; - Date dateSearch; - Calendar cal1 = Calendar.getInstance(); - Calendar cal2 = Calendar.getInstance(); - Calendar cal3 = Calendar.getInstance(); - List<EntryBook> entryBooksList = new ArrayList<EntryBook>(); - - // create 5 fiscal years - for (int annee = 2009; annee < 2015; annee++) { - - cal1.set(annee, 0, 1); - beginDate = cal1.getTime(); - - cal2.set(annee, 11, 31); - endDate = cal2.getTime(); - - FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); - fiscalPeriod.setBeginDate(beginDate); - fiscalPeriod.setEndDate(endDate); - //create the current year - //instanceFiscalPeriod.createFiscalPeriod(fiscalPeriod); - - // create a transaction for each month of the current year - /*for (int mois = 0 ; mois<11 ; mois++) { - - cal3.set(annee, mois, 1); - dateSearch = cal3.getTime(); - - TimeSpan timespan = instanceFiscalPeriod.searchTimeSpanByDate(dateSearch); - - - for (int j=0 ; j<50 ; j++) { - - entryBooksList.clear(); - - entryBooksList = instanceJournal.getAllEntryByProperty(EntryBook.LABEL, "Journal des ventes"); - - FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - - topiaIDTransaction = instanceTransaction.createFinancialTransaction(financialTransaction); createTransaction(dateSearch, "Facture 6", "description transaction", timespan, journal); - - FinancialTransaction transaction = instanceTransaction.getsearchTransactionWithTopiaId(topiaIDTransaction); - - Account account = instanceAccount.getAccountByNumber("1"); - - Entry entry1 = new EntryImpl(); - entry1.setAccount(account); - entry1.setDescription("Description"); - entry1.setDetail("Details"); - entry1.setDebit(false); - entry1.setFinancialTransaction(transaction); - - instanceTransaction.createEntry(entry1); //addEntry("entree1", "300", false, "lettering", "detail", transaction, account); - - Entry entry2 = new EntryImpl(); - entry2.setAccount(account); - entry2.setDescription("Description"); - entry2.setDetail("Details"); - entry2.setDebit(true); - entry2.setFinancialTransaction(transaction); - - instanceTransaction.createEntry(entry2); //addEntry("entree2", "300", true, "lettering", "detail", transaction, account); - } - }*/ - //Period period = instancePeriod.searchPeriodWithDate(beginTimeSpan); - //instanceFiscalPeriod.blockFiscalPeriod(fiscalPeriod); //blockAllTimeSpanOfPeriod(period); - //instanceFiscalPeriod.blockPeriod(period); - } - } - - -} Added: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaMiscTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaMiscTest.java (rev 0) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaMiscTest.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -0,0 +1,53 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 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 org.chorem.lima.business.accountingrules.FranceAccountingRules; +import org.junit.Assert; +import org.junit.Test; + +/** + * Lima misc tests. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class LimaMiscTest extends AbstractLimaTest { + + /** + * Test que la regles de nationnalité par defaut est Default pour + * la majorité des tests. + */ + @Test + public void testDefaultRule() { + Assert.assertFalse(LimaConfig.getInstance().getAccountingRules() + instanceof FranceAccountingRules); + } + +} Property changes on: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaMiscTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java 2012-01-13 09:56:43 UTC (rev 3319) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/LimaTestConfig.java 2012-01-13 09:56:57 UTC (rev 3320) @@ -1,82 +0,0 @@ -/* - * #%L - * Lima business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 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 - * 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.chorem.lima.entity.LimaCallaoDAOHelper; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -/** - * Application config instance used it tests. (load custom test configuration) - * - * @author chatellier - * @version $Revision$ - * <p/> - * 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...) - // load file manually (lima.properties) - Properties testProperties = new Properties(); - InputStream stream = LimaTestConfig.class.getResourceAsStream("/" + Option.CONFIG_FILE.getDefaultValue()); - - 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"; - //TODO clear database instead of creating a new one for each test - testDir += System.currentTimeMillis(); - 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; - } -}
participants (1)
-
echatellier@users.chorem.org