Author: vsalaun Date: 2011-08-11 15:02:50 +0200 (Thu, 11 Aug 2011) New Revision: 3263 Url: http://chorem.org/repositories/revision/lima/3263 Log: update tests Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 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 2011-08-11 09:58:10 UTC (rev 3262) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/FiscalPeriodServiceImplTest.java 2011-08-11 13:02:50 UTC (rev 3263) @@ -25,12 +25,29 @@ package org.chorem.lima.business; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.ejb.FinancialPeriodServiceImpl; import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; +import org.chorem.lima.business.ejbinterface.FiscalPeriodService; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialPeriodImpl; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodDAO; +import org.chorem.lima.entity.FiscalPeriodImpl; +import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; /** * Tests pour la gestion des périodes @@ -50,6 +67,19 @@ .getLog(FiscalPeriodServiceImplTest.class); private static FiscalPeriodServiceImpl instance; + + private TopiaContext rootContext; + + public FiscalPeriodServiceImplTest() { + LimaConfig config = LimaTestConfig.getInstance(); + try { + rootContext = TopiaContextFactory.getContext(config.getOptions()); + } catch (TopiaNotFoundException ex) { + if (log.isErrorEnabled()) { + log.error("Can't init topia context", ex); + } + } + } @BeforeClass public static void setUpClass() throws Exception { @@ -74,16 +104,14 @@ @Test public void blockFiscalPeriodTest() throws Exception { - /* - TopiaContext rootcontext; - TopiaContext transaction=null; - rootcontext = TopiaContextFactory.getContext(LimaConfigTest.getInstance().getOptions()); + + /*TopiaContext transaction = null; FiscalPeriod recentFiscalPeriod = new FiscalPeriodImpl(); FiscalPeriod oldestFiscalPeriod = new FiscalPeriodImpl(); try { - transaction = rootcontext.beginTransaction(); + transaction = beginTransaction(); FiscalPeriodDAO fiscalPeriodDAO = LimaCallaoDAOHelper.getFiscalPeriodDAO(transaction); @@ -101,7 +129,10 @@ recentFiscalPeriod.setEndDate(endCalendar.getTime()); fiscalPeriodDAO.create(recentFiscalPeriod); recentFiscalPeriod.addFinancialPeriod(financialPeriod); - financialPeriodService.createFinancialPeriod(financialPeriod); + + List<FinancialPeriod> financialPeriodsList = new ArrayList<FinancialPeriod>(); + financialPeriodsList.add(financialPeriod); + financialPeriodService.createFinancialPeriods(financialPeriodsList); //une plus ancienne @@ -126,20 +157,20 @@ try{ - - - fiscalPeriodService.blockFiscalPeriod(oldestFiscalPeriod); + fiscalPeriodService.blockFiscalPeriod(oldestFiscalPeriod); } catch (Exception ex){ log.debug("Error test block Period", ex); Assert.assertEquals(LimaBusinessException.class, ex.getClass()); } - try { + try { fiscalPeriodService.blockFiscalPeriod(recentFiscalPeriod); } catch (Exception ex){ log.debug("Error test block Period", ex); Assert.assertEquals(LimaBusinessException.class, ex.getClass()); }*/ } + + /** * Permet de tester l'ajout d'une période. */ @@ -279,5 +310,14 @@ // Nombre 12 timeSpans mensuels Assert.assertEquals(12, listTimeSpanDTO.size());*/ } + + protected TopiaContext beginTransaction() throws TopiaException { + // basic check done, make check in database + // TODO move it into JTA + TopiaContext topiaTransaction; + topiaTransaction = rootContext.beginTransaction(); + log.trace("beginTransaction" + topiaTransaction); + return topiaTransaction; + } } \ No newline at end of file Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java =================================================================== --- trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2011-08-11 09:58:10 UTC (rev 3262) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/GeneratorTest.java 2011-08-11 13:02:50 UTC (rev 3263) @@ -25,6 +25,14 @@ package org.chorem.lima.business; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.transaction.Transaction; + +import org.apache.activeio.journal.Journal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ejb.AccountServiceImpl; @@ -34,8 +42,14 @@ import org.chorem.lima.business.ejb.FiscalPeriodServiceImpl; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; +import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.entity.FinancialTransactionImpl; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.entity.FiscalPeriodImpl; import org.junit.Before; import org.junit.Test; @@ -70,8 +84,7 @@ * @throws LimaException */ @Test - public void generate () throws LimaException - { + public void generate () throws LimaException { // Création Journal EntryBook entryBook1 = new EntryBookImpl(); @@ -137,39 +150,75 @@ instanceAccount.createAccount(207, "Fonds commercial", 20); instanceAccount.createAccount(21, "Immobilisations corporelles", 2);*/ - /*Date beginDate; + Date beginDate; Date endDate; Date dateSearch; - - for (int annee = 109 ; annee < 115 ; annee++) { - beginDate = new Date(annee,0,1); - endDate = new Date(annee,11,31); + 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); - instanceFiscalPeriod.createFiscalPeriod(fiscalPeriod); + //create the current year + //instanceFiscalPeriod.createFiscalPeriod(fiscalPeriod); - for (int mois = 0 ; mois<11 ; mois++) { - dateSearch = new Date(annee,mois,1); + // 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++) { - Journal journal = instanceJournal.searchJournalWithLabel("Journal des ventes"); + + entryBooksList.clear(); + + entryBooksList = instanceJournal.getAllEntryByProperty(EntryBook.LABEL, "Journal des ventes"); + + FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - topiaIDTransaction = instanceTransaction.createTransaction(dateSearch, "Facture 6", "description transaction", timespan, journal); + topiaIDTransaction = instanceTransaction.createFinancialTransaction(financialTransaction); createTransaction(dateSearch, "Facture 6", "description transaction", timespan, journal); - Transaction transaction = instanceTransaction.searchTransactionWithTopiaId(topiaIDTransaction); + FinancialTransaction transaction = instanceTransaction.getsearchTransactionWithTopiaId(topiaIDTransaction); - Account account = instanceAccount.searchAccount(1); - - instanceTransaction.addEntry("entree1", "300", false, "lettering", "detail", transaction,account); - instanceTransaction.addEntry("entree2", "300", true, "lettering", "detail", transaction,account); + 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); - instancePeriod.blockAllTimeSpanOfPeriod(period); - instancePeriod.blockPeriod(period); - }*/ + }*/ + //Period period = instancePeriod.searchPeriodWithDate(beginTimeSpan); + //instanceFiscalPeriod.blockFiscalPeriod(fiscalPeriod); //blockAllTimeSpanOfPeriod(period); + //instanceFiscalPeriod.blockPeriod(period); + } }
participants (1)
-
vsalaun@users.chorem.org