Author: fdesbois Date: 2009-10-13 18:50:55 +0200 (Tue, 13 Oct 2009) New Revision: 2669 Added: trunk/callao-service/src/test/resources/ trunk/callao-service/src/test/resources/Callao_bdd.properties Modified: trunk/callao-service/src/test/java/org/chorem/callao/service/TransactionServiceImplTest.java Log: - Correction Ano #56 : Test was completely change to have distinct methods without dependencies between them - Add properties to change database location for Tests Modified: trunk/callao-service/src/test/java/org/chorem/callao/service/TransactionServiceImplTest.java =================================================================== --- trunk/callao-service/src/test/java/org/chorem/callao/service/TransactionServiceImplTest.java 2009-10-11 12:14:48 UTC (rev 2668) +++ trunk/callao-service/src/test/java/org/chorem/callao/service/TransactionServiceImplTest.java 2009-10-13 16:50:55 UTC (rev 2669) @@ -39,58 +39,24 @@ /** log. */ private static final org.apache.commons.logging.Log log = LogFactory.getLog(TransactionServiceImplTest.class); - private static TransactionServiceImpl instanceTransaction; - private static PeriodServiceImpl instancePeriod; - private static TimeSpanServiceImpl instanceTimespan; - private static JournalServiceImpl instanceJournal; - private static EntryServiceImpl instanceEntry; - private static AccountServiceImpl instanceAccount; - private static LogServiceImpl instanceLog; - private static String topiaIDTransaction; - private static String topiaIDTransaction2; - @BeforeClass public static void setUpClass() throws Exception { ContextCallao.getInstance().init(); } - @Before - public void setUp() { - instanceTransaction = new TransactionServiceImpl(); - instancePeriod = new PeriodServiceImpl(); - instanceTimespan = new TimeSpanServiceImpl(); - instanceJournal = new JournalServiceImpl(); - instanceEntry = new EntryServiceImpl(); - instanceAccount = new AccountServiceImpl(); - instanceLog = new LogServiceImpl(); - } - /** * On nettoie la base de données * @throws java.lang.Exception */ @AfterClass public static void tearDownClass() throws Exception { - // Supprime Account - instanceAccount.removeAccount("8"); - // Supprime Journal - List<JournalDTO> listJournal = instanceJournal.getAllJournal(); - for (JournalDTO journalDTO : listJournal) - { - instanceJournal.removeJournal(journalDTO); - } + LogServiceImpl serviceLog = new LogServiceImpl(); // Supprime Log - List<LogDTO> listLog = instanceLog.listeAllLogDTO(); + List<LogDTO> listLog = serviceLog.listeAllLogDTO(); for (LogDTO logDTO : listLog) { - instanceLog.removeLog(logDTO); - } - // Supprime Period & TimeSpan - Date d = new Date(110,0,1); - PeriodDTO periodDTO = instancePeriod.searchPeriodDTOWithDate(d); - instancePeriod.removePeriod(periodDTO); - // Supprime Transaction - //List<Transaction> listTransaction = instanceTransaction.s + serviceLog.removeLog(logDTO); + } ContextCallao.getInstance().disconnect(); } @@ -103,51 +69,60 @@ @Test public void createTransactionTest () { - String result; - // debut 1 janvier 2010 - Date beginTimeSpan = new Date(110,0,1); - // fin 31 décembre 2010 - Date endTimeSpan = new Date(110,11,31); - // Création période avec son découpage sur 12 mois - result = instancePeriod.createPeriod(beginTimeSpan, endTimeSpan, false); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); - // Recherche du timespan 1 janv au 31 janv 2010 - Date dateSearch = new Date(110,0,1); - TimeSpan timespan = instanceTimespan.searchTimeSpanByDate(dateSearch); - // Création Journal - result = instanceJournal.createJournal("Journal transaction", "jt","description"); - Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); - // Recherche du journal pour l'ajouter dans la transaction - Journal journal = instanceJournal.searchJournalWithLabel("Journal transaction"); - /** - * Création d'une transaction - */ - result = instanceTransaction.createTransaction(dateSearch, "Facture 6", "description transaction", timespan, journal); - /** - * Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) - */ - //Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + log.info("BEGIN createTransactionTest()"); + + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + + // Creation Period & TimeSpan (default period 01/01/2010 -> 31/12/2010) + TimeSpan timespan = createPeriod(servicePeriod); + + // Creation Journal + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + + // Test creationTransaction avec Journal et TimeSpan + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } + /** * Recherche des transactions. */ @Test public void searchTransactionTest () { - // Une seule transaction est dans la base de données. - Date dateSearch = new Date(110,0,1); - // Recherche d'un timeSpan - TimeSpan timespan = instanceTimespan.searchTimeSpanByDate(dateSearch); + log.info("BEGIN searchTransactionTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + /* FIN PREPARATION TEST */ + // Recherche de la transaction suivant ce timeSpan. - List<Transaction> listTransaction = instanceTransaction.searchListTransactionWithTimeSpan(timespan); + List<Transaction> listTransaction = serviceTransaction.searchListTransactionWithTimeSpan(timespan); Assert.assertEquals(1,listTransaction.size()); // On prend le premier élément de la liste de transactions Transaction transaction = listTransaction.get(0); // Si c'est la bonne transaction Assert.assertEquals("Facture 6",transaction.getVoucherRef()); - // On inscrit le topiaId pour la suite des tests - topiaIDTransaction = transaction.getTopiaId(); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } @@ -160,10 +135,28 @@ @Test public void searchWithTopiaIdTest () { + log.info("BEGIN searchWithTopiaIdTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + /* FIN PREPARATION TEST */ + // Recherche de la transaction avec son identifiant. - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); // Si c'est la bonne transaction Assert.assertEquals("Facture 6",transaction.getVoucherRef()); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -172,8 +165,20 @@ @Test public void searchTransactionDTOTest () { + log.info("BEGIN searchTransactionDTOTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + /* FIN PREPARATION TEST */ + // Recherche de la transaction à l'aide de son identifiant. - TransactionDTO transactionDTO = instanceTransaction.searchTransactionDTO(topiaIDTransaction); + TransactionDTO transactionDTO = serviceTransaction.searchTransactionDTO(transactionId); // Vérifie si la transaction DTO est correcte. Assert.assertEquals("Facture 6",transactionDTO.getVoucherRef()); // Charge le journalDTO à partir de la transactionDTO @@ -184,6 +189,12 @@ // debut 1 janvier 2010 - vérifie si c'est la même période Date beginTimeSpan = new Date(110,0,1); Assert.assertEquals(beginTimeSpan,timeSpanDTO.getBeginTimeSpan()); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -192,14 +203,32 @@ @Test public void modifyTransactionTest () { - TransactionDTO transactionDTO = instanceTransaction.searchTransactionDTO(topiaIDTransaction); + log.info("BEGIN modifyTransactionTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + TransactionDTO transactionDTO = serviceTransaction.searchTransactionDTO(transactionId); + /* FIN PREPARATION TEST */ + // On modifie la référence du fichier. transactionDTO.setVoucherRef("Nouvelle facture"); - String result = instanceTransaction.modifyTransaction(transactionDTO); + String result = serviceTransaction.modifyTransaction(transactionDTO); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // On recherche la transaction dans la base de données. - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); Assert.assertEquals("Nouvelle facture",transaction.getVoucherRef()); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -208,6 +237,19 @@ @Test public void createTransactionDTOTest () { + log.info("BEGIN createTransactionDTOTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TimeSpanServiceImpl serviceTimespan = new TimeSpanServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + /* FIN PREPARATION TEST */ + TransactionDTO transactionDTO = new TransactionDTO(); Date dateTransaction = new Date(); transactionDTO.setEntryDate(dateTransaction); @@ -215,46 +257,54 @@ transactionDTO.setDescription("No comment"); // Il n'y a pas de timeSpan et journal attachés à la transaction // ce qui créé une erreur lors de la création - String result = instanceTransaction.createTransaction(transactionDTO); + String result = serviceTransaction.createTransaction(transactionDTO); Assert.assertEquals(ServiceHelper.TRANSACTION_NOT_JOURNAL,result); // On fournit à transactionDTO un timeSpan valide // debut 1 janvier 2010 - Date dateSearch = new Date(110,0,1); - TimeSpanDTO timeSpanDTO = instanceTimespan.searchTimeSpanDTOByDate(dateSearch); + Date dateSearch = timespan.getBeginTimeSpan(); + TimeSpanDTO timeSpanDTO = serviceTimespan.searchTimeSpanDTOByDate(dateSearch); transactionDTO.setTimeSpanDTO(timeSpanDTO); // On fournit à transactionDTO un journal NON valide (non présent dans la BDD) JournalDTO journalDTO = new JournalDTO(); journalDTO.setLabel("existe pas"); transactionDTO.setJournalDTO(journalDTO); // Ajout de la transaction avec erreur avec le journalDTO - result = instanceTransaction.createTransaction(transactionDTO); + result = serviceTransaction.createTransaction(transactionDTO); Assert.assertEquals(ServiceHelper.TRANSACTION_NOT_JOURNAL,result); /** * Ajout d'un journalDTO valide */ - journalDTO = instanceJournal.searchJournalDTOWithLabel("Journal transaction"); + journalDTO = serviceJournal.searchJournalDTOWithLabel("Journal transaction"); transactionDTO.setJournalDTO(journalDTO); - result = instanceTransaction.createTransaction(transactionDTO); + result = serviceTransaction.createTransaction(transactionDTO); /** * Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) */ //Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // Vérifie le nombre de transactions (égal à deux) - TimeSpan timeSpan = instanceTimespan.searchTimeSpanByDate(dateSearch); - List<TransactionDTO> listTransactionDTO = instanceTransaction.searchListTransactionDTOWithTimeSpan(timeSpan); + TimeSpan timeSpan = serviceTimespan.searchTimeSpanByDate(dateSearch); + List<TransactionDTO> listTransactionDTO = serviceTransaction.searchListTransactionDTOWithTimeSpan(timeSpan); Assert.assertEquals(2,listTransactionDTO.size()); /** * pour effacer par la suite les transactions à la fin des tests */ - // Vérifie si la 1ière transaction est celle deja inscrite (createTransactionTest) + // Vérifie si la 1ière transaction est celle deja inscrite transactionDTO = listTransactionDTO.get(0); - if ( transactionDTO.getId().equals(topiaIDTransaction) ) + String transactionId2; + if ( transactionDTO.getId().equals(transactionId) ) { - topiaIDTransaction2 = listTransactionDTO.get(1).getId(); - } else + transactionId2 = listTransactionDTO.get(1).getId(); + } else // ?????? { - topiaIDTransaction2 = transactionDTO.getId(); + transactionId2 = transactionDTO.getId(); } + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + removeTransaction(serviceTransaction, transactionId2); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -263,25 +313,45 @@ @Test public void addEntryTest () { + log.info("BEGIN addEntryTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + AccountServiceImpl serviceAccount = new AccountServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + /* FIN PREPARATION TEST */ + // On recherche la transaction dans la base de données. - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); // On créé le compte 8 et recherche cet account dans la base de données - instanceAccount.createAccount("8", "Compte essai", "0","actif"); - instanceAccount.createAccount("81", "Compte essai 81", "8","actif"); - Account account = instanceAccount.searchAccount("8"); - Assert.assertEquals("8",account.getAccountNumber()); + Account account = createAccount(serviceAccount,"8", "Compte essai", "0","actif"); + createAccount(serviceAccount,"81", "Compte essai 81", "8","actif"); // Ajout entrée : 300 euros en crédit - String result = instanceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); + String result = serviceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); /** * Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) */ //Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // Ajout entrée : 300 euros en débit - result = instanceTransaction.addEntry("entree2", "300", true, "lettering", "detail", transaction,account); + result = serviceTransaction.addEntry("entree2", "300", true, "lettering", "detail", transaction,account); /** * Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) */ //Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + + /* NETTOYAGE TEST */ + // Les entrees sont supprimees avec la transaction (composition) + removeTransaction(serviceTransaction, transactionId); + serviceAccount.removeAccount("8"); + serviceAccount.removeAccount("81"); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -290,9 +360,26 @@ @Test public void searchEntryTest () { - // On recherche la transaction dans la base de données. - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); - List<EntryDTO> listEntryDTO = instanceEntry.searchEntryDTOWithTransaction(transaction); + log.info("BEGIN searchEntryTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + AccountServiceImpl serviceAccount = new AccountServiceImpl(); + EntryServiceImpl serviceEntry = new EntryServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); + Account account = createAccount(serviceAccount,"8", "Compte essai", "0","actif"); + createAccount(serviceAccount,"81", "Compte essai 81", "8","actif"); + serviceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); + serviceTransaction.addEntry("entree2", "300", true, "lettering", "detail", transaction,account); + /* FIN PREPARATION TEST */ + + List<EntryDTO> listEntryDTO = serviceEntry.searchEntryDTOWithTransaction(transaction); // On doit trouver deux entrées. Assert.assertEquals(2,listEntryDTO.size()); /** @@ -305,6 +392,14 @@ // Trouve le compte 81 accountDTO = accountDTO.getAccountChildDTO().get(0); Assert.assertEquals("81",accountDTO.getAccountNumber()); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + serviceAccount.removeAccount("8"); + serviceAccount.removeAccount("81"); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -313,26 +408,50 @@ @Test public void modifyEntry () { - // On recherche la transaction dans la base de données. - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); + log.info("BEGIN modifyEntry()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + AccountServiceImpl serviceAccount = new AccountServiceImpl(); + EntryServiceImpl serviceEntry = new EntryServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); + Account account = createAccount(serviceAccount,"8", "Compte essai", "0","actif"); + serviceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); + serviceTransaction.addEntry("entree2", "300", true, "lettering", "detail", transaction,account); + /* FIN PREPARATION TEST */ + // Recherche les deux entry en format DTO - List<EntryDTO> listEntryDTO = instanceEntry.searchEntryDTOWithTransaction(transaction); + List<EntryDTO> listEntryDTO = serviceEntry.searchEntryDTOWithTransaction(transaction); + Assert.assertEquals(2,listEntryDTO.size()); // Premier DTO EntryDTO entryDTO = listEntryDTO.get(0); entryDTO.setAmount("800"); - String result = instanceTransaction.modifyEntry(entryDTO); + String result = serviceTransaction.modifyEntry(entryDTO); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // Second DTO entryDTO = listEntryDTO.get(1); entryDTO.setAmount("800"); - + // Modification de l'entrée dans la bdd. - result = instanceTransaction.modifyEntry(entryDTO); + result = serviceTransaction.modifyEntry(entryDTO); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // Vérifie que les deux DTO ont bien été modifiés. - listEntryDTO = instanceEntry.searchEntryDTOWithTransaction(transaction); + listEntryDTO = serviceEntry.searchEntryDTOWithTransaction(transaction); entryDTO = listEntryDTO.get(0); Assert.assertEquals("800,00",entryDTO.getAmount()); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + serviceAccount.removeAccount("8"); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } /** @@ -341,35 +460,147 @@ @Test public void removeEntryTest () { - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); - List<EntryDTO> listEntryDTO = instanceEntry.searchEntryDTOWithTransaction(transaction); + log.info("BEGIN removeEntryTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + AccountServiceImpl serviceAccount = new AccountServiceImpl(); + EntryServiceImpl serviceEntry = new EntryServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); + Account account = createAccount(serviceAccount,"8", "Compte essai", "0","actif"); + serviceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); + serviceTransaction.addEntry("entree2", "300", true, "lettering", "detail", transaction,account); + /* FIN PREPARATION TEST */ + + List<EntryDTO> listEntryDTO = serviceEntry.searchEntryDTOWithTransaction(transaction); // Prend le premier DTO EntryDTO entryDTO = listEntryDTO.get(0); // Supprime cette entrée - String result = instanceTransaction.removeEntry(entryDTO.getId()); + String result = serviceTransaction.removeEntry(entryDTO.getId()); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // Recherche dans la base de données les entrys - listEntryDTO = instanceEntry.searchEntryDTOWithTransaction(transaction); + listEntryDTO = serviceEntry.searchEntryDTOWithTransaction(transaction); // Trouve un seul entry DTO Assert.assertEquals(1,listEntryDTO.size()); + + /* NETTOYAGE TEST */ + removeTransaction(serviceTransaction, transactionId); + serviceAccount.removeAccount("8"); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ } - + /** * Test la suppression d'une transaction et ses entrées. */ @Test public void removeTransactionTest () { + log.info("BEGIN removeEntryTest()"); + PeriodServiceImpl servicePeriod = new PeriodServiceImpl(); + TransactionServiceImpl serviceTransaction = new TransactionServiceImpl(); + JournalServiceImpl serviceJournal = new JournalServiceImpl(); + AccountServiceImpl serviceAccount = new AccountServiceImpl(); + EntryServiceImpl serviceEntry = new EntryServiceImpl(); + + /* PREPARATION TEST */ + // Default period 01/01/2010 -> 31/12/2010 + TimeSpan timespan = createPeriod(servicePeriod); + Journal journal = createJournal(serviceJournal,"Journal transaction", "jt","description"); + String transactionId = createTransaction(serviceTransaction, "Facture 6", "description transaction", timespan, journal); + Transaction transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); + Account account = createAccount(serviceAccount,"8", "Compte essai", "0","actif"); + serviceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); + /* FIN PREPARATION TEST */ + // Supprime cette transaction - String result = instanceTransaction.removeTransaction(topiaIDTransaction); + String result = serviceTransaction.removeTransaction(transactionId); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); // Recherche dans la base de données les entrys - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); - List<EntryDTO> listEntryDTO = instanceEntry.searchEntryDTOWithTransaction(transaction); + transaction = serviceTransaction.searchTransactionWithTopiaId(transactionId); + List<EntryDTO> listEntryDTO = serviceEntry.searchEntryDTOWithTransaction(transaction); Assert.assertEquals(0,listEntryDTO.size()); - // Efface seconde transaction - result = instanceTransaction.removeTransaction(topiaIDTransaction2); + + /* NETTOYAGE TEST */ + serviceAccount.removeAccount("8"); + removeJournals(serviceJournal); + removePeriod(servicePeriod); + /* FIN NETTOYAGE TEST */ + } + + private TimeSpan createPeriod(PeriodServiceImpl servicePeriod) { + TimeSpanServiceImpl serviceTimespan = new TimeSpanServiceImpl(); + // debut 1 janvier 2010 + Date beginTimeSpan = new Date(110,0,1); + // fin 31 décembre 2010 + Date endTimeSpan = new Date(110,11,31); + // Création période avec son découpage sur 12 mois + String result = servicePeriod.createPeriod(beginTimeSpan, endTimeSpan, false); Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + // Recherche du timespan 1 janv au 31 janv 2010 + //Date dateSearch = new Date(110,0,1); + TimeSpan timespan = serviceTimespan.searchTimeSpanByDate(beginTimeSpan); + return timespan; } - + + private void removePeriod(PeriodServiceImpl servicePeriod) { + // Supprime Period & TimeSpan + Date d = new Date(110,0,1); + PeriodDTO periodDTO = servicePeriod.searchPeriodDTOWithDate(d); + servicePeriod.removePeriod(periodDTO); + } + + private Journal createJournal(JournalServiceImpl serviceJournal, + String label, String prefix, String description) { + // Création Journal + String result = serviceJournal.createJournal(label, prefix, description); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + // Recherche du journal pour l'ajouter dans la transaction + Journal journal = serviceJournal.searchJournalWithLabel(label); + Assert.assertNotNull(journal); + return journal; + } + + private void removeJournals(JournalServiceImpl serviceJournal) { + // Supprime Journal + List<JournalDTO> listJournal = serviceJournal.getAllJournal(); + for (JournalDTO journalDTO : listJournal) + { + serviceJournal.removeJournal(journalDTO); + } + } + + private String createTransaction(TransactionServiceImpl serviceTransaction, + String voucherRef, String description, TimeSpan timespan, Journal journal) { + // Création d'une transaction + String transactionId = serviceTransaction.createTransaction( + timespan.getBeginTimeSpan(), voucherRef, description, timespan, journal); + /** + * Si il renvoie succes et non l'identifiant (à commenter dans la classe correspondante) + */ + //Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + Assert.assertFalse(transactionId.equals(ServiceHelper.RESPOND_ERROR)); + log.debug("RESULT createTransaction : " + transactionId); + return transactionId; + } + + private void removeTransaction(TransactionServiceImpl serviceTransaction, String transactionId) { + String result = serviceTransaction.removeTransaction(transactionId); + Assert.assertEquals(ServiceHelper.RESPOND_SUCCESS,result); + } + + private Account createAccount(AccountServiceImpl serviceAccount, + String accountNumber, String label, String masterAccountNumber, String type) { + serviceAccount.createAccount(accountNumber, label, masterAccountNumber, type); + Account account = serviceAccount.searchAccount(accountNumber); + Assert.assertEquals(accountNumber,account.getAccountNumber()); + return account; + } } Added: trunk/callao-service/src/test/resources/Callao_bdd.properties =================================================================== --- trunk/callao-service/src/test/resources/Callao_bdd.properties (rev 0) +++ trunk/callao-service/src/test/resources/Callao_bdd.properties 2009-10-13 16:50:55 UTC (rev 2669) @@ -0,0 +1,24 @@ +# Propri\u00E9t\u00E9s par d\u00E9faut pour une base de donn\u00E9es 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/h2data/callao +#hibernate.connection.url=jdbc:h2:file:~/.callao/callao + + +#topia.service.history=org.nuiton.topia.history.TopiaHistoryServiceImpl + +# Permet de pr\u00C3\u00A9ciser les classes \u00C3\u00A0 persister +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 + +#topia.service.security=org.nuiton.topia.security.TopiaSecurityServiceImpl