View Javadoc
1   /*
2    * #%L
3    * $Id: TopiaDAOTest.java 4156 2014-12-09 11:27:18Z echatellier $
4    * $HeadURL: https://svn.codelutin.com/isis-fish/tags/isis-fish-4.4.0.2/src/test/java/fr/ifremer/isisfish/entity/TopiaDAOTest.java $
5    * %%
6    * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chatellier Eric
7    * %%
8    * This program is free software: you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as
10   * published by the Free Software Foundation, either version 3 of the 
11   * License, or (at your option) any later version.
12   * 
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   * 
18   * You should have received a copy of the GNU General Public 
19   * License along with this program.  If not, see
20   * <http://www.gnu.org/licenses/gpl-3.0.html>.
21   * #L%
22   */
23  
24  package fr.ifremer.isisfish.entity;
25  
26  import java.io.IOException;
27  import java.util.List;
28  
29  import org.junit.Assert;
30  import org.junit.Test;
31  import org.nuiton.topia.TopiaContext;
32  import org.nuiton.topia.TopiaException;
33  
34  import fr.ifremer.isisfish.AbstractIsisFishTest;
35  import fr.ifremer.isisfish.IsisFishDAOHelper;
36  import fr.ifremer.isisfish.datastore.SimulationStorage;
37  import fr.ifremer.isisfish.datastore.StorageException;
38  import fr.ifremer.isisfish.entities.Population;
39  import fr.ifremer.isisfish.entities.PopulationDAO;
40  import fr.ifremer.isisfish.simulator.SimulationParameter;
41  import fr.ifremer.isisfish.simulator.SimulationParameterImpl;
42  
43  /**
44   * Copie d'un test important de topia concernant le flush mode.
45   * 
46   * @author chatellier
47   * @version $Revision: 4156 $
48   * 
49   * Last update : $Date: 2014-12-09 12:27:18 +0100 (Tue, 09 Dec 2014) $
50   * By : $Author: echatellier $
51   */
52  public class TopiaDAOTest extends AbstractIsisFishTest {
53  
54      /**
55       * Test de creer une entité et de verifier qu'elle est
56       * présente dans la persistence au sein de la transaction.
57       *
58       * @throws TopiaException
59       * @throws IOException
60       * @throws StorageException 
61       */
62      @Test
63      public void testCreateAndFindInTransaction() throws TopiaException, IOException, StorageException {
64  
65          SimulationParameter parameters = new SimulationParameterImpl();
66          SimulationStorage simulation = SimulationStorage.create("testdao", parameters);
67          TopiaContext rootContext = simulation.getStorage();
68  
69          TopiaContext context = rootContext.beginTransaction();
70          context.createSchema();
71  
72          PopulationDAO populationDAO = IsisFishDAOHelper.getPopulationDAO(context);
73  
74          // appel 1 find all
75          Population population = populationDAO.create();
76          population.setName("langoustine");
77          List<Population> allPopulation = populationDAO.findAll();
78          Assert.assertEquals(1, allPopulation.size());
79          context.commitTransaction();
80  
81          // recherce la personne créée dans la même transaction
82          Population population2 = populationDAO.create();
83          population2.setName("thon");
84          allPopulation = populationDAO.findAll();
85          Assert.assertEquals(2, allPopulation.size());
86          Assert.assertTrue(allPopulation.contains(population2));
87  
88          context.rollbackTransaction();
89  
90          // meme test apres roolback
91          Population population3 = populationDAO.create();
92          population3.setName("requin");
93          allPopulation = populationDAO.findAll();
94          Assert.assertEquals(2, allPopulation.size());
95          Assert.assertTrue(allPopulation.contains(population3));
96  
97          context.commitTransaction();
98          simulation.closeStorage();
99      }
100 }