Author: echatellier Date: 2012-02-22 14:01:41 +0100 (Wed, 22 Feb 2012) New Revision: 3342 Url: http://chorem.org/repositories/revision/lima/3342 Log: Refactor test to not inject test data for all test and allow import test to use their own data Modified: 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/FinancialTransactionServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java 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-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AbstractLimaTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -197,11 +197,17 @@ /** * Create a basic database with some objects to reuse then in subtests. * + * Not called by default (<code>@Before</code>) to allow init test with + * CSV or EBP import. + * * @throws LimaException * @throws ParseException */ - @Before - public void initTestDatabase() throws LimaException, ParseException { + protected void initTestDatabase() throws LimaException, ParseException { + + // clear database + clearService.clearDatabase(); + initTestAccounts(); initTestTransactions(); } @@ -213,8 +219,6 @@ * @throws ParseException */ protected void initTestAccounts() throws LimaException, ParseException { - // clear database - clearService.clearDatabase(); // creation d'un plan compatble de test Account classFinancier = new AccountImpl(); @@ -226,6 +230,16 @@ accountVmp.setAccountNumber("50"); accountVmp.setLabel("Valeurs mobilières de placement"); accountService.createAccount(classFinancier, accountVmp); + + Account accountPel = new AccountImpl(); + accountPel.setAccountNumber("501"); + accountPel.setLabel("Parts dans des entreprises liées"); + accountService.createAccount(accountVmp, accountPel); + + Account accountAP = new AccountImpl(); + accountAP.setAccountNumber("502"); + accountAP.setLabel("Actions propres"); + accountService.createAccount(accountVmp, accountAP); Account accountBefa = new AccountImpl(); accountBefa.setAccountNumber("51"); 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-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/AccountServiceImplTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -25,11 +25,13 @@ package org.chorem.lima.business; +import java.text.ParseException; import java.util.List; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** @@ -44,6 +46,11 @@ */ public class AccountServiceImplTest extends AbstractLimaTest { + @Before + public void initTest() throws LimaException, ParseException { + initTestDatabase(); + } + /** * Création d'un compte dans le plan comptable. * @throws LimaException @@ -167,7 +174,7 @@ @Test public void getAllAccountTest() throws LimaException { List<Account> listAccount = accountService.getAllAccounts(); - Assert.assertEquals(5, listAccount.size()); + Assert.assertEquals(7, listAccount.size()); } /** @@ -177,14 +184,14 @@ */ @Test public void removeAccountTest() throws LimaException { - Account accountToRemove = accountService.getAccountByNumber("51"); + Account accountToRemove = accountService.getAccountByNumber("50"); // 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()); + // Il ne doit rester que 4 compte (5, 51, 511, 512) + Assert.assertEquals(4, accountService.getAllAccounts().size()); } /** 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-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -25,9 +25,12 @@ package org.chorem.lima.business; +import java.text.ParseException; + import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; import org.junit.Assert; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -43,6 +46,11 @@ protected static final String JOURNAL_DES_VENTES = "Journal des ventes"; + @Before + public void initTest() throws LimaException, ParseException { + initTestDatabase(); + } + /** * Permet de tester l'ajout d'un journal dans la base de données. * (erreur duplication). 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-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialPeriodServiceImplTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -25,6 +25,9 @@ package org.chorem.lima.business; +import java.text.ParseException; + +import org.junit.Before; import org.junit.Test; /** @@ -41,6 +44,11 @@ */ public class FinancialPeriodServiceImplTest extends AbstractLimaTest { + @Before + public void initTest() throws LimaException, ParseException { + initTestDatabase(); + } + /** * Permet de tester l'ajout d'un timespan. */ Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java 2012-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FinancialTransactionServiceImplTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -50,6 +50,11 @@ */ public class FinancialTransactionServiceImplTest extends AbstractLimaTest { + @Before + public void initTest() throws LimaException, ParseException { + initTestDatabase(); + } + /** * Test to find all unbalanced transactions. * Nothing wrong here. 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-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -25,10 +25,13 @@ package org.chorem.lima.business; +import java.text.ParseException; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; import org.junit.AfterClass; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.topia.TopiaContext; @@ -57,6 +60,11 @@ private TopiaContext rootContext; + @Before + public void initTest() throws LimaException, ParseException { + initTestDatabase(); + } + public FiscalPeriodServiceImplTest() { LimaConfig config = LimaConfig.getInstance(); try { Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java 2012-02-22 13:01:01 UTC (rev 3341) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/ReportServiceImplTest.java 2012-02-22 13:01:41 UTC (rev 3342) @@ -38,6 +38,7 @@ import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionImpl; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; /** @@ -45,6 +46,11 @@ */ public class ReportServiceImplTest extends AbstractLimaTest { + @Before + public void initTest() throws LimaException, ParseException { + initTestDatabase(); + } + /** * Test de génération du rapport des comptes. *