Author: vsalaun Date: 2011-08-08 15:57:43 +0200 (Mon, 08 Aug 2011) New Revision: 3253 Url: http://chorem.org/repositories/revision/lima/3253 Log: #424 update all accounts tests 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/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.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 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 10:06:23 UTC (rev 3252) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2011-08-08 13:57:43 UTC (rev 3253) @@ -80,9 +80,7 @@ @Override - public boolean createAccountWithTransaction(Account masterAccount, Account account, TopiaContext topiaContext) throws LimaException { - - boolean result = true; + public void createAccountWithTransaction(Account masterAccount, Account account, TopiaContext topiaContext) throws LimaException { try { // check if account number already exist @@ -112,10 +110,8 @@ commitTransaction(topiaContext); } catch (TopiaException ex) { - result = false; doCatch(topiaContext, ex, log); } - return result; } @@ -129,10 +125,8 @@ * @throws LimaException */ @Override - public boolean createAccount(Account masterAccount, Account account) throws LimaException { + public void createAccount(Account masterAccount, Account account) throws LimaException { - boolean result = true; - //check rules before create the account accountingRules.createAccountRules(masterAccount, account); @@ -140,17 +134,15 @@ try { transaction = beginTransaction(); - result = createAccountWithTransaction(masterAccount, account, transaction); + createAccountWithTransaction(masterAccount, account, transaction); } catch (TopiaException ex) { - result = false; doCatch(transaction, ex, log); } finally { doFinally(transaction, log); } - return result; } @@ -443,6 +435,7 @@ public void updateAccount(Account account) throws LimaException { TopiaContext transaction = null; + try { transaction = beginTransaction(); 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 10:06:23 UTC (rev 3252) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/EntryBookServiceImpl.java 2011-08-08 13:57:43 UTC (rev 3253) @@ -132,10 +132,9 @@ * @return * @throws LimaException */ - public boolean createEntryBook(EntryBook entryBook) throws LimaException { + public void createEntryBook(EntryBook entryBook) throws LimaException { TopiaContext transaction = null; - boolean result = true; try { transaction = beginTransaction(); @@ -143,13 +142,11 @@ createEntryBookWithTransaction(entryBook, transaction); } catch (TopiaException ex) { - result = false; doCatch(transaction, ex, log); } finally { doFinally(transaction, log); } - return result; } /** @@ -209,9 +206,8 @@ * @throws LimaException * */ - public boolean updateEntryBook(EntryBook entryBook) throws LimaException { + public void updateEntryBook(EntryBook entryBook) throws LimaException { TopiaContext transaction = null; - boolean result = true; try { transaction = beginTransaction(); @@ -225,13 +221,11 @@ commitTransaction(transaction); } catch (TopiaException ex) { - result = false; doCatch(transaction, ex, log); } finally { doFinally(transaction, log); } - return result; } /** @@ -243,10 +237,9 @@ * @param prefix préfixe du EntryBook à supprimer * @throws LimaException */ - public boolean removeEntryBook(EntryBook entryBook) throws LimaException { + public void removeEntryBook(EntryBook entryBook) throws LimaException { TopiaContext topiaTransaction = null; - boolean result = true; try { topiaTransaction = beginTransaction(); @@ -262,13 +255,11 @@ 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/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java 2011-08-08 10:06:23 UTC (rev 3252) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/EntryBookService.java 2011-08-08 13:57:43 UTC (rev 3253) @@ -45,6 +45,8 @@ List<EntryBook> getAllEntryBooks() throws LimaException; + List<EntryBook> getAllEntryByProperty(String propertyName, String value) throws LimaException; + void createEntryBook(EntryBook entryBook) throws LimaException; void updateEntryBook(EntryBook entryBook) throws LimaException; 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 10:06:23 UTC (rev 3252) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2011-08-08 13:57:43 UTC (rev 3253) @@ -91,38 +91,34 @@ */ @Test public void createAccountDAOTest() throws LimaException { - Boolean result; - // Création des comptes DTO + // Création des comptes Account account = new AccountImpl(); account.setAccountNumber("5"); account.setLabel("COMPTES FINANCIERS"); - result = instance.createAccount(null, account); - + instance.createAccount(null, account); Account accountChild1 = new AccountImpl(); accountChild1.setAccountNumber("50"); accountChild1.setLabel("Valeurs mobilières de placement"); //accountChild1.setMasterAccount(account); - result = instance.createAccount(account, accountChild1); + instance.createAccount(account, accountChild1); Account accountChild2 = new AccountImpl(); accountChild2.setAccountNumber("51"); accountChild2.setLabel("Banques établissements financiers et assimilés"); //accountChild2.setMasterAccount(account); - result = instance.createAccount(account, accountChild2); + instance.createAccount(account, accountChild2); Account accountChildChild1 = new AccountImpl(); accountChildChild1.setAccountNumber("511"); accountChildChild1.setLabel("Valeurs à l'encaissement"); //accountChildChild1.setMasterAccount(accountChild2); - result = instance.createAccount(accountChild2, accountChildChild1); + instance.createAccount(accountChild2, accountChildChild1); Account accountChildChild2 = new AccountImpl(); accountChildChild2.setAccountNumber("512"); accountChildChild2.setLabel("Banques"); //accountChildChild2.setMasterAccount(accountChild2); - result = instance.createAccount(accountChild2, accountChildChild2); - - Assert.assertEquals(true,result); + instance.createAccount(accountChild2, accountChildChild2); } @@ -165,32 +161,47 @@ /** - * Permet de tester si un compte est bien effacé. Si celui-ci n'existe pas - * un message d'avertissement doit apparaître. - * On supprime un compte avec seulement son numéro de compte (supposé/vérifié - * unique lors de la création). + * Permet de tester si un compte est bien effacé. + * @throws LimaException */ @Test - public void removeAccountTest() { - boolean result; + public void removeAccountTest() throws LimaException { + Account masterAccount = instance.getAccountByNumber("4"); // Création de comptes - /*instance.createAccount("40", "Fournisseurs", "4","actif"); - instance.createAccount("41", "Usagers", "4","actif"); - instance.createAccount("44", "Etat", "4","actif"); + 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. - result = instance.removeAccount("41"); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + instance.removeAccount(account2); + // On recherche les fils du compte 4 - List<Account> listAccount = instance.searchListChildAccount("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. - result = instance.removeAccount("422"); - Assert.assertEquals(ServiceHelper.ACCOUNT_NOT_EXIST,result);*/ + Account account4 = new AccountImpl(); + account4.setAccountNumber("422"); + account4.setLabel("Unsaved account"); + instance.removeAccount(account4); } @@ -203,36 +214,46 @@ * 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() { - /*String result; + public void updateTest() throws LimaException { // On recherche le compte 5 - COMPTES FINANCIERS - AccountDTO accountDTO = instance.searchAccountDTO("5"); + Account account = instance.getAccountByNumber("5"); + // {ETAPE 1} Modification du nom pour le compte 5 - accountDTO.setLabel("COMPTES FINANCIERS modifié"); + account.setLabel("COMPTES FINANCIERS modifié"); + // {ETAPE 2} Ajout du compte 53 - AccountDTO accountChildDTO = new AccountDTO("","53","Caisse","5",null,"actif"); - accountDTO.addAccountChild(accountChildDTO); + 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) - AccountDTO accountremoveDTO = instance.searchAccountDTO("51"); - accountDTO.removeAccountChild(accountremoveDTO); + Account accountRemove = instance.getAccountByNumber("51"); + + account.removeSubAccounts(accountRemove); + // Met à jour le compte 5 DTO dans la bdd ainsi que toutes les {ETAPE *} - result = instance.updateDTO(accountDTO); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + instance.updateAccount(account); // Vérification ETAPE // ETAPE 1 - Account account = instance.searchAccount("5"); + account = instance.getAccountByNumber("5"); Assert.assertEquals("COMPTES FINANCIERS modifié",account.getLabel()); // ETAPE 2 - account = instance.searchAccount("53"); + account = instance.getAccountByNumber("53"); Assert.assertEquals("Caisse",account.getLabel()); // ETAPE 3 - account = instance.searchAccount("5"); // les comptes fils de 5 - List<Account> listAccount = instance.searchListChildAccount(account); - // Il doit avoir 50 et 53 - Assert.assertEquals(2,listAccount.size());*/ + 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()); } } \ 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 2011-08-08 10:06:23 UTC (rev 3252) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2011-08-08 13:57:43 UTC (rev 3253) @@ -82,8 +82,7 @@ EntryBook entryBook = new EntryBookImpl(); entryBook.setLabel("Journal des ventes"); entryBook.setCode("jdv"); - boolean result = instance.createEntryBook(entryBook); - Assert.assertTrue(result); + instance.createEntryBook(entryBook); } /**