Author: vsalaun Date: 2011-08-08 12:06:23 +0200 (Mon, 08 Aug 2011) New Revision: 3252 Url: http://chorem.org/repositories/revision/lima/3252 Log: #424 update accounts tests + change return type for AccountServiceImpl and EntryBookServiceImpl Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2011-08-08 09:12:40 UTC (rev 3251) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2011-08-08 10:06:23 UTC (rev 3252) @@ -80,8 +80,10 @@ @Override - public void createAccountWithTransaction(Account masterAccount, Account account, TopiaContext topiaContext) throws LimaException { + public boolean createAccountWithTransaction(Account masterAccount, Account account, TopiaContext topiaContext) throws LimaException { + boolean result = true; + try { // check if account number already exist AccountDAO accountDAO = @@ -110,8 +112,10 @@ commitTransaction(topiaContext); } catch (TopiaException ex) { + result = false; doCatch(topiaContext, ex, log); - } + } + return result; } @@ -125,8 +129,10 @@ * @throws LimaException */ @Override - public void createAccount(Account masterAccount, Account account) throws LimaException { + public boolean createAccount(Account masterAccount, Account account) throws LimaException { + boolean result = true; + //check rules before create the account accountingRules.createAccountRules(masterAccount, account); @@ -134,15 +140,17 @@ try { transaction = beginTransaction(); - createAccountWithTransaction(masterAccount, account, transaction); + result = createAccountWithTransaction(masterAccount, account, transaction); } catch (TopiaException ex) { + result = false; doCatch(transaction, ex, log); } finally { doFinally(transaction, log); } + return result; } 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 2011-08-08 09:12:40 UTC (rev 3251) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2011-08-08 10:06:23 UTC (rev 3252) @@ -129,22 +129,27 @@ * Création d'un EntryBook. Il peut être unique sur son label (au choix). * * @param EntryBook EntryBook + * @return * @throws LimaException */ - public void createEntryBook(EntryBook entryBook) throws LimaException { + public boolean createEntryBook(EntryBook entryBook) throws LimaException { TopiaContext transaction = null; + boolean result = true; + try { transaction = beginTransaction(); - createEntryBookWithTransaction(entryBook, transaction); + createEntryBookWithTransaction(entryBook, transaction); } catch (TopiaException ex) { + result = false; doCatch(transaction, ex, log); } finally { doFinally(transaction, log); } + return result; } /** @@ -172,15 +177,42 @@ return entryBooksList; } + + @Override + public List<EntryBook> getAllEntryByProperty(String propertyName, String value) throws LimaException { + List<EntryBook> entryBookList = null; + + TopiaContext transaction = null; + + try { + transaction = beginTransaction(); + + EntryBookDAO entryBookDAO = + LimaCallaoDAOHelper.getEntryBookDAO(transaction); + entryBookList = entryBookDAO.findAllByProperty(propertyName, value); + } + catch (TopiaException ex) { + doCatch(transaction, ex, log); + } + finally { + doFinally(transaction, log); + } + + return entryBookList; + } + /** * Permet de modifier un journal. * * @param entryBook journal - * @throws LimaException + * @throws LimaException + * */ - public void updateEntryBook(EntryBook entryBook) throws LimaException { + public boolean updateEntryBook(EntryBook entryBook) throws LimaException { TopiaContext transaction = null; + boolean result = true; + try { transaction = beginTransaction(); @@ -193,11 +225,13 @@ commitTransaction(transaction); } catch (TopiaException ex) { + result = false; doCatch(transaction, ex, log); } finally { doFinally(transaction, log); } + return result; } /** @@ -209,9 +243,11 @@ * @param prefix préfixe du EntryBook à supprimer * @throws LimaException */ - public void removeEntryBook(EntryBook entryBook) throws LimaException { + public boolean removeEntryBook(EntryBook entryBook) throws LimaException { TopiaContext topiaTransaction = null; + boolean result = true; + try { topiaTransaction = beginTransaction(); @@ -226,11 +262,13 @@ commitTransaction(topiaTransaction); } catch (TopiaException ex) { + result = false; doCatch(topiaTransaction, ex, log); } finally { doFinally(topiaTransaction, log); } + return result; } protected TopiaContext beginTransaction() throws TopiaException { 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-08-08 09:12:40 UTC (rev 3251) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2011-08-08 10:06:23 UTC (rev 3252) @@ -25,10 +25,13 @@ package org.chorem.lima.business; +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.Test; /** @@ -53,6 +56,7 @@ public void createAccountTest() throws LimaException { Account myAccount = new AccountImpl(); myAccount.setAccountNumber("4"); + myAccount.setLabel("Comptes de tiers"); instance.createAccount(null, myAccount); } @@ -83,10 +87,11 @@ * 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() { - /*String result; + public void createAccountDAOTest() throws LimaException { + Boolean result; // Création des comptes DTO Account account = new AccountImpl(); account.setAccountNumber("5"); @@ -112,72 +117,50 @@ result = instance.createAccount(accountChild2, accountChildChild1); Account accountChildChild2 = new AccountImpl(); - accountChildChild2.setAccountNumber("51"); + accountChildChild2.setAccountNumber("512"); accountChildChild2.setLabel("Banques"); //accountChildChild2.setMasterAccount(accountChild2); result = instance.createAccount(accountChild2, accountChildChild2); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result);*/ + Assert.assertEquals(true,result); } /** * Recherche d'un compte dans le plan comptable à partir d'un numéro de * compte. + * @throws LimaException */ @Test - public void searchAccountTest() { - /*// On recherche le compte 4 - Comptes de tiers - Account result = instance.searchAccount("4"); - Assert.assertEquals("Comptes de tiers",result.getLabel());*/ + 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()); } /** - * Recherche d'un compte dans le plan comptable à partir d'un numéro de - * compte. Il renvoie un objet DTO compte - */ - @Test - public void searchAccountDTOTest() { - /*// On recherche le compte 4 - Comptes de tiers - AccountDTO result = instance.searchAccountDTO("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() { - /*// On recherche le compte 5 - COMPTES FINANCIERS - Account account = instance.searchAccount("5"); - List<Account> listAccount = instance.searchListChildAccount(account); + 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());*/ + Assert.assertEquals(2,listAccount.size()); } /** - * Permet de tester le nombre d'enfants renvoyés appartenant à un père. - */ - @Test - public void searchListAccountDTOTest() { - /*// On recherche le compte 5 - COMPTES FINANCIERS - AccountDTO accountDTO = instance.searchAccountDTO("5"); - // Il possède les comptes 50 et 51 - Assert.assertEquals(2,accountDTO.getAccountChildDTO().size());*/ - } - - - /** * Permet de tester la méthode recherchant tous les comptes au format DTO. + * @throws LimaException */ @Test - public void getAllAccountTest() { - /*List<AccountDTO> listAccountDTO = instance.getAllAccount(); - // doit être égal à 2 (compte 4 et 5) - Assert.assertEquals(2,listAccountDTO.size());*/ + public void getAllAccountTest() throws LimaException { + List<Account> listAccount = instance.getAllAccounts(); + Assert.assertEquals(9,listAccount.size()); } @@ -189,9 +172,9 @@ */ @Test public void removeAccountTest() { - /*String result; + boolean result; // Création de comptes - instance.createAccount("40", "Fournisseurs", "4","actif"); + /*instance.createAccount("40", "Fournisseurs", "4","actif"); instance.createAccount("41", "Usagers", "4","actif"); instance.createAccount("44", "Etat", "4","actif");