This is an automated email from the git hooks/post-receive script. New commit to branch feature/1233 in repository lima. See http://git.chorem.org/lima.git commit 391ae16b10a4f7645850c16a376e95a4afdfe29c Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Mon Jun 1 15:42:03 2015 +0200 refs #1233 : test du service des journaux --- .../lima/business/EntryBookServiceImplTest.java | 146 +++++++++++++++++---- 1 file changed, 119 insertions(+), 27 deletions(-) diff --git a/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java b/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java index abf3005..8455e99 100644 --- a/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java +++ b/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java @@ -22,19 +22,17 @@ package org.chorem.lima.business; +import org.chorem.lima.business.exceptions.AlreadyExistEntryBookException; import org.chorem.lima.business.exceptions.LimaException; import org.chorem.lima.business.exceptions.UsedEntryBookException; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; -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.Assert; import org.junit.Before; import org.junit.Test; -import java.text.ParseException; +import java.util.Iterator; +import java.util.List; /** * Tests pour la gestion des journaux. @@ -53,6 +51,104 @@ public class EntryBookServiceImplTest extends AbstractLimaTest { createEntryBooks(); } + @Test + public void getEntryBookByCodeTest() { + + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + Assert.assertNotNull(entryBook); + Assert.assertEquals("jdv", entryBook.getCode()); + Assert.assertEquals("Journal des ventes", entryBook.getLabel()); + + entryBook = entryBookService.getEntryBookByCode("XXX"); + Assert.assertNull(entryBook); + } + + @Test + public void getAllEntryBooksTest() throws LimaException { + List<EntryBook> allEntryBooks = entryBookService.getAllEntryBooks(); + + Assert.assertEquals(3, allEntryBooks.size()); + + Iterator<EntryBook> iterator = allEntryBooks.iterator(); + + EntryBook entryBook = iterator.next(); + Assert.assertEquals("JRN", entryBook.getCode()); + Assert.assertEquals("MyJournal", entryBook.getLabel()); + + entryBook = iterator.next(); + Assert.assertEquals("jda", entryBook.getCode()); + Assert.assertEquals("Journal des achats", entryBook.getLabel()); + + entryBook = iterator.next(); + Assert.assertEquals("jdv", entryBook.getCode()); + Assert.assertEquals("Journal des ventes", entryBook.getLabel()); + } + + @Test + public void createNewEntryBookTest() { + EntryBook newEntryBook = entryBookService.createNewEntryBook(); + Assert.assertNull(newEntryBook.getCode()); + Assert.assertNull(newEntryBook.getLabel()); + + List<EntryBook> allEntryBooks = entryBookService.getAllEntryBooks(); + + Assert.assertEquals(3, allEntryBooks.size()); + Assert.assertFalse(allEntryBooks.contains(newEntryBook)); + } + + @Test + public void createOrUpdateEntryBookTest() { + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode("jdm"); + entryBook.setLabel("journal des machins"); + boolean updated = entryBookService.createOrUpdateEntryBook(entryBook); + Assert.assertFalse(updated); + Assert.assertEquals(4, entryBookService.getAllEntryBooks().size()); + entryBook = entryBookService.getEntryBookByCode("jdm"); + Assert.assertNotNull(entryBook); + Assert.assertEquals("jdm", entryBook.getCode()); + Assert.assertEquals("journal des machins", entryBook.getLabel()); + + entryBook = new EntryBookImpl(); + entryBook.setCode("jdv"); + entryBook.setLabel("journal des ventes bis"); + updated = entryBookService.createOrUpdateEntryBook(entryBook); + Assert.assertTrue(updated); + Assert.assertEquals(4, entryBookService.getAllEntryBooks().size()); + entryBook = entryBookService.getEntryBookByCode("jdv"); + Assert.assertNotNull(entryBook); + Assert.assertEquals("jdv", entryBook.getCode()); + Assert.assertEquals("journal des ventes bis", entryBook.getLabel()); + } + + @Test + public void createEntryBookTest() throws AlreadyExistEntryBookException { + + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode("jdm"); + entryBook.setLabel("journal des machins"); + + entryBook = entryBookService.createEntryBook(entryBook); + Assert.assertEquals("jdm", entryBook.getCode()); + Assert.assertEquals("journal des machins", entryBook.getLabel()); + + List<EntryBook> allEntryBooks = entryBookService.getAllEntryBooks(); + + Assert.assertEquals(4, allEntryBooks.size()); + Assert.assertTrue(allEntryBooks.contains(entryBook)); + } + + @Test(expected = AlreadyExistEntryBookException.class) + public void createEntryBookFailAlreadyExistTest() throws AlreadyExistEntryBookException { + + EntryBook entryBook = new EntryBookImpl(); + entryBook.setCode("jdv"); + entryBook.setLabel("journal des ventes bis"); + + entryBookService.createEntryBook(entryBook); + } + + /** * Permet de tester la modification d'un journal suivant son préfixe. * @@ -60,7 +156,6 @@ public class EntryBookServiceImplTest extends AbstractLimaTest { */ @Test public void modifyJournalTest() throws LimaException { - entryBookService.getAllEntryBooks(); EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); Assert.assertNotNull(entryBook); Assert.assertEquals(JOURNAL_DES_VENTES, entryBook.getLabel()); @@ -79,21 +174,10 @@ public class EntryBookServiceImplTest extends AbstractLimaTest { * @throws LimaException */ @Test(expected=UsedEntryBookException.class) - public void deleteUsedEntryBook() throws LimaException, ParseException { + public void deleteUsedEntryBook() throws Exception { + createFiscalPeriod(); + createFinancialTransaction(); EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); - Assert.assertNotNull(entryBook); - - // make transaction used - // creation d'un exercice fiscal - FiscalPeriod fiscalPeriod = new FiscalPeriodImpl(); - fiscalPeriod.setBeginDate(df.parse("January 1, 2012")); - fiscalPeriod.setEndDate(df.parse("December 31, 2012")); - fiscalPeriodService.createFiscalPeriod(fiscalPeriod); - - FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - financialTransaction.setTransactionDate(df.parse("January 1, 2012")); - financialTransaction.setEntryBook(entryBook); - financialTransactionService.createFinancialTransaction(financialTransaction); entryBookService.removeEntryBook(entryBook); } @@ -107,14 +191,22 @@ public class EntryBookServiceImplTest extends AbstractLimaTest { @Test public void deleteNonUsedEntryBookTest() throws LimaException { - EntryBook myEntryBook = new EntryBookImpl(); - myEntryBook.setCode("JRN2"); - myEntryBook.setLabel("MyJournal"); - myEntryBook = entryBookService.createEntryBook(myEntryBook); - int nbEntryBooks = entryBookService.getAllEntryBooks().size(); - entryBookService.removeEntryBook(myEntryBook); + EntryBook entryBook = entryBookService.getEntryBookByCode("jdv"); + + entryBookService.removeEntryBook(entryBook); + List<EntryBook> allEntryBooks = entryBookService.getAllEntryBooks(); + + Assert.assertEquals(2, allEntryBooks.size()); - Assert.assertEquals(nbEntryBooks -1, entryBookService.getAllEntryBooks().size()); + Iterator<EntryBook> iterator = allEntryBooks.iterator(); + + entryBook = iterator.next(); + Assert.assertEquals("JRN", entryBook.getCode()); + Assert.assertEquals("MyJournal", entryBook.getLabel()); + + entryBook = iterator.next(); + Assert.assertEquals("jda", entryBook.getCode()); + Assert.assertEquals("Journal des achats", entryBook.getLabel()); } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.