Author: tchemit Date: 2011-08-11 16:06:50 +0200 (Thu, 11 Aug 2011) New Revision: 3264 Url: http://chorem.org/repositories/revision/lima/3264 Log: try to fix some tests Modified: trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 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-11 13:02:50 UTC (rev 3263) +++ trunk/lima-business/src/test/java/org/chorem/lima/business/EntryBookServiceImplTest.java 2011-08-11 14:06:50 UTC (rev 3264) @@ -25,21 +25,23 @@ package org.chorem.lima.business; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ejb.EntryBookServiceImpl; +import org.chorem.lima.business.ejbinterface.EntryBookService; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; -import org.junit.AfterClass; +import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import java.util.List; + /** * Tests pour la gestion des journaux - * + * <p/> * L'application peut gérer plusieurs journaux pour la gestion des transactions. * Il est tester ici l'ajout, la recherche. * @@ -52,73 +54,115 @@ private static EntryBookServiceImpl instance; - /** - * On nettoie la base de données - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownClass() throws Exception { - List<EntryBook> list = instance.getAllEntryBooks(); - // On supprime chaque journal - for (EntryBook entryBook : list) { - instance.removeEntryBook(entryBook); - } + public static final String JOURNAL_DES_VENTES = "Journal des ventes"; + + public static final String NEW_CODE = "New Code"; + + // /** +// * On nettoie la base de données +// * @throws java.lang.Exception +// */ +// @AfterClass +// public static void tearDownClass() throws Exception { +// List<EntryBook> list = instance.getAllEntryBooks(); +// // On supprime chaque journal +// for (EntryBook entryBook : list) { +// instance.removeEntryBook(entryBook); +// } +// } + + @BeforeClass + public static void beforeclass() throws LimaException { + deleteAllBookEntries(); } @Before - public void setUp() { + public void setUp() throws LimaException { instance = new EntryBookServiceImpl(); - } - public EntryBookServiceImplTest() { - } - - /** - * Permet de tester l'ajout d'un journal dans la base de données. - * @throws LimaException - */ - @Test - public void createJournalTest() throws LimaException { + // create a entry book EntryBook entryBook = new EntryBookImpl(); - entryBook.setLabel("Journal des ventes"); + entryBook.setLabel(JOURNAL_DES_VENTES); entryBook.setCode("jdv"); instance.createEntryBook(entryBook); } + @After + public void tearDown() throws LimaException { + deleteAllBookEntries(); + } + + private static void deleteAllBookEntries() throws LimaException { + EntryBookService instance = new EntryBookServiceImpl(); + List<EntryBook> list = instance.getAllEntryBooks(); + // On supprime chaque journal + for (EntryBook entryBook : list) { + instance.removeEntryBook(entryBook); + } + } + +// /** +// * Permet de tester l'ajout d'un journal dans la base de données. +// * @throws LimaException +// */ +// @Test +// public void createJournalTest() throws LimaException { +// EntryBook entryBook = new EntryBookImpl(); +// entryBook.setLabel("Journal des ventes"); +// entryBook.setCode("jdv"); +// instance.createEntryBook(entryBook); +// } + /** * Permet de tester la recherche d'un journal suivant son préfixe. - * @throws LimaException + * + * @throws LimaException */ @Test public void searchJournalWithLabelTest() throws LimaException { - List<EntryBook> result = instance.getAllEntryByProperty(EntryBook.LABEL, "Journal des ventes"); - if ((result != null) && (result.size() != 0)) { - Assert.assertEquals("Journal des ventes", result.get(0).getLabel()); - } + List<EntryBook> result = instance.getAllEntryByProperty(EntryBook.LABEL, JOURNAL_DES_VENTES); + Assert.assertNotNull(result); + Assert.assertEquals(1, result.size()); + + EntryBook entryBook = result.get(0); + Assert.assertNotNull(entryBook); + Assert.assertEquals("Journal des ventes", entryBook.getLabel()); + + // On ne sait pas ici si ça existe ?! result = instance.getAllEntryByProperty(EntryBook.LABEL, "Journal des achats"); - if ((result != null) && (result.size() != 0)) { - Assert.assertEquals("Journal des achats", result.get(0).getLabel()); - } + Assert.assertNotNull(result); + Assert.assertTrue(result.isEmpty()); + // TODO Il faut que ca soit vide : cette entree n'existe pas (pas créée dans le test) +// Assert.assertTrue(result.isEmpty()); + } /** * Permet de tester la modification d'un journal suivant son préfixe. - * @throws LimaException + * + * @throws LimaException */ @Test public void modifyJournalTest() throws LimaException { - List<EntryBook> entryBooksList = instance.getAllEntryByProperty(EntryBook.LABEL, "Journal des ventes"); - if (entryBooksList != null) { - Assert.assertEquals("Journal des ventes", entryBooksList.get(0).getLabel()); - entryBooksList.get(0).setCode("New Code"); - instance.updateEntryBook(entryBooksList.get(0)); - } + EntryBook entryBook; + List<EntryBook> entryBooksList; + entryBooksList = instance.getAllEntryByProperty(EntryBook.LABEL, JOURNAL_DES_VENTES); + Assert.assertNotNull(entryBooksList); + Assert.assertEquals(1, entryBooksList.size()); + entryBook = entryBooksList.get(0); + Assert.assertNotNull(entryBook); + Assert.assertEquals(JOURNAL_DES_VENTES, entryBook.getLabel()); + entryBook.setCode(NEW_CODE); + instance.updateEntryBook(entryBook); + // Recherche du journal dans la bdd - entryBooksList = instance.getAllEntryByProperty(EntryBook.LABEL, "Journal des ventes"); - if (entryBooksList != null) { - Assert.assertEquals("New Code", entryBooksList.get(0).getCode()); - } + entryBooksList = instance.getAllEntryByProperty(EntryBook.LABEL, JOURNAL_DES_VENTES); + Assert.assertNotNull(entryBooksList); + Assert.assertEquals(1, entryBooksList.size()); + entryBook = entryBooksList.get(0); + Assert.assertNotNull(entryBook); + Assert.assertEquals(NEW_CODE, entryBook.getCode()); } } \ No newline at end of file