1   /***
2    Copyright (C) 2005 The Java Community
3   
4    This program is free software; you can redistribute it and/or modify  it under
5    the terms of the GNU General Public License as published by  the Free Software
6    Foundation; either version 2 of the License, or  (at your option) any later
7    version.
8   
9    This program is distributed in the hope that it will be useful,  but WITHOUT
10   ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
12  
13   You should have received a copy of the GNU General Public License  along with
14   this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
15   Place, Suite 330, Boston, MA 02111-1307 USA.
16   */
17  package org.bejug.javacareers.jobs.dao;
18  
19  import java.util.List;
20  
21  import org.bejug.javacareers.jobs.common.AbstractSpringContextDBUnitTests;
22  import org.bejug.javacareers.jobs.model.Organisation;
23  import org.springframework.dao.DataAccessException;
24  
25  /***
26   * @author Sven Schauwvliege (Last modified by $Author: shally $)
27   * @version $Revision: 1.8 $ - $Date: 2005/12/20 15:36:47 $
28   */
29  
30  
31  public class OrganisationDaoImplTests extends AbstractSpringContextDBUnitTests {
32  
33      /***
34       * the names of the tables need to be compaired
35       */
36      private static final String[] TABLE_NAMES = {"Parameter", "Country", "Region", "Address", "Organisation"};
37      
38      /***
39       * the jobofferdao, injected through field-injection.
40       */
41      protected OrganisationDao organisationDao;
42  
43      /***
44       * @return Returns the organisationDao.
45       */
46      public OrganisationDao getOrganisationDao() {
47          return organisationDao;
48      }
49  
50      /***
51       * Test the Create, Read, Read all, Update and Delete functions for a Organisation.
52       *
53       * @throws DataAccessException Thrown when a database exceptions occurs.
54       */
55      public void testRUOrganisation() throws DataAccessException {
56          //
57          // (1) Get a organisation by id
58          // 
59          Organisation foundOrganisation = getOrganisationDao().getOrganisation(new Integer(1000));
60          assertEquals("error in get by id", foundOrganisation.getName(), "Real Software");
61          assertEquals("error in get by id", foundOrganisation.getId(), new Integer(1000));
62          
63          //
64          // (2) Update the Organisation
65          //
66          foundOrganisation.setName("update");
67          getOrganisationDao().store(foundOrganisation);
68          Organisation newOrganisation = getOrganisationDao().getOrganisation(new Integer(1000));
69          assertEquals("error in update", newOrganisation.getName(), "update");
70          assertEquals("error in update", newOrganisation.getId(), new Integer(1000));
71          
72          //
73          // (3) Read al organisations from the database to a list.
74          //
75          List organisations = getOrganisationDao().getOrganisations();
76          assertTrue("read failed, amount of found objects not 5 but " + (organisations.size() + 1), organisations.size() == 5);
77          assertTrue("read failed ", organisations.get(0) instanceof Organisation);
78  
79      }
80  
81      /***
82       * {@inheritDoc}
83       */
84      public void onSetUpInTransaction() throws Exception {
85          init(TABLE_NAMES);
86  
87      }
88  
89  }
90  
91  /*** 
92   * $Log: OrganisationDaoImplTests.java,v $
93   * Revision 1.8  2005/12/20 15:36:47  shally
94   * CheckStyle and PMD changes.
95   *
96   * Revision 1.7  2005/08/03 13:16:03  bme_jcs
97   * getDao's removed and storeObject renamed to store
98   *
99   * Revision 1.6  2005/08/03 09:10:59  ge0ffrey
100  * JAVACAREERS-247
101  *
102  * Revision 1.5  2005/07/05 15:09:31  schauwvliege
103  * added person/contact and location to model
104  *
105  * Revision 1.4  2005/06/29 09:00:26  psong09
106  * comment component updated
107  *
108  * Revision 1.3  2005/06/14 13:34:56  schauwvliege
109  * fixed tests
110  *
111  * Revision 1.2  2005/06/09 08:19:04  bejug_cc
112  * Fix initial import
113  *
114  * Revision 1.1  2005/05/25 11:06:53  ssc
115  * added DBUnit tests and fixed some errors
116  * 
117  **/