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.Iterator;
20 import java.util.List;
21
22 import org.bejug.javacareers.jobs.common.AbstractSpringContextDBUnitTests;
23 import org.bejug.javacareers.jobs.model.CommercialEducationOffer;
24 import org.springframework.dao.DataAccessException;
25
26 /***
27 * @author Sven Schauwvliege (Last modified by $Author: shally $)
28 * @version $Revision: 1.10 $ - $Date: 2005/12/09 10:46:57 $
29 */
30
31 public class CommercialEducationOfferDaoImplTests extends AbstractSpringContextDBUnitTests {
32
33 /***
34 * the names of the tables need to be compaired
35 */
36 private static final String[] TABLE_NAMES = {"Resume", "Parameter", "Country", "Region", "Address", "Contact", "Organisation", "Person", "User", "Offer",
37 "EducationOffer", "CommercialEducationOffer", "Offer_OfferType", "Offer_Profile"};
38 /***
39 * the columns to ignore.
40 */
41 private static final String[] IGNORE = {"id", "modificationdate", "addressid", "contactId"};
42 /***
43 * the jobofferdao, injected through field-injection.
44 */
45 protected OfferDao commercialEducationOfferDao;
46
47 /***
48 * @return Returns the commercialEducationOfferDao.
49 */
50 public OfferDao getCommercialEducationOfferDao() {
51 return commercialEducationOfferDao;
52 }
53
54 /***
55 * Test the Create, Read, Read all, Update and Delete functions for a CommercialEducationOffer.
56 *
57 * @throws DataAccessException Thrown when a database exceptions occurs.
58 */
59 public void testCRUDOffer() throws DataAccessException {
60
61
62
63 List offers = commercialEducationOfferDao.getOffers();
64 assertTrue("read failed, amount of found objects not 5 but " + (offers.size() + 1), offers.size() == 5);
65 assertTrue("read failed ", offers.get(0).getClass() == CommercialEducationOffer.class);
66
67
68
69
70 boolean change = true;
71 for (Iterator i = offers.iterator(); i.hasNext();) {
72 CommercialEducationOffer commercialEducationOffer = (CommercialEducationOffer) i.next();
73 if (change) {
74 getCommercialEducationOfferDao().deleteOffer(commercialEducationOffer.getId());
75 } else {
76 getCommercialEducationOfferDao().deleteOffer(commercialEducationOffer);
77 }
78 change = !change;
79 }
80 List emptyCommercialEducationOffers = getCommercialEducationOfferDao().getOffers();
81 assertTrue("delete faled ", emptyCommercialEducationOffers.size() == 0);
82
83
84
85
86 for (Iterator i = offers.iterator(); i.hasNext();) {
87 CommercialEducationOffer commercialEducationOffer = (CommercialEducationOffer) i.next();
88 commercialEducationOffer.setVersion(null);
89 commercialEducationOffer.setId(null);
90 commercialEducationOffer.getAddress().setVersion(null);
91 getCommercialEducationOfferDao().store(commercialEducationOffer);
92 }
93 List foundCommercialEducationOffers = getCommercialEducationOfferDao().getOffers();
94 assertTrue("save failed, amount of found objects not 5 but " + foundCommercialEducationOffers.size() + 1, foundCommercialEducationOffers.size() == 5);
95 assertDBAsExpected(TABLE_NAMES, IGNORE);
96 }
97
98 /***
99 * Test the update/ get by id.
100 *
101 * @throws DataAccessException Thrown when a database exceptions occurs.
102 */
103 public void testUpdate() throws DataAccessException {
104
105
106 CommercialEducationOffer foundCommercialEducationOffer = (CommercialEducationOffer) getCommercialEducationOfferDao().getOffer(new Integer(500));
107 assertEquals("error in get by id", foundCommercialEducationOffer.getTitle(), "Java developer");
108 assertEquals("error in get by id", foundCommercialEducationOffer.getId(), new Integer(500));
109
110
111 foundCommercialEducationOffer.setTitle("update");
112 getCommercialEducationOfferDao().store(foundCommercialEducationOffer);
113 CommercialEducationOffer newCommercialEducationOffer = (CommercialEducationOffer) getCommercialEducationOfferDao().getOffer(new Integer(500));
114 assertEquals("error in update", newCommercialEducationOffer.getTitle(), "update");
115 assertEquals("error in update", newCommercialEducationOffer.getId(), new Integer(500));
116 }
117
118 /***
119 * {@inheritDoc}
120 */
121 public void onSetUpInTransaction() throws Exception {
122 init(TABLE_NAMES);
123
124 }
125
126
127 }
128
129 /***
130 * $Log: CommercialEducationOfferDaoImplTests.java,v $
131 * Revision 1.10 2005/12/09 10:46:57 shally
132 * Opkuis voor checkstyle en PMD
133 *
134 * Revision 1.9 2005/08/24 08:12:19 schauwvliege
135 * addded resume
136 *
137 * Revision 1.8 2005/08/03 13:16:02 bme_jcs
138 * getDao's removed and storeObject renamed to store
139 *
140 * Revision 1.7 2005/08/03 09:10:59 ge0ffrey
141 * JAVACAREERS-247
142 *
143 * Revision 1.6 2005/07/06 12:10:10 schauwvliege
144 * added person/contact and location to model
145 *
146 * Revision 1.5 2005/07/05 15:09:30 schauwvliege
147 * added person/contact and location to model
148 *
149 * Revision 1.4 2005/06/29 09:00:26 psong09
150 * comment component updated
151 *
152 * Revision 1.3 2005/06/14 13:34:56 schauwvliege
153 * fixed tests
154 *
155 * Revision 1.2 2005/06/09 08:19:04 bejug_cc
156 * Fix initial import
157 *
158 * Revision 1.1 2005/05/25 11:06:53 ssc
159 * added DBUnit tests and fixed some errors
160 *
161 **/