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.Comment;
23 import org.springframework.dao.DataAccessException;
24
25 /***
26 * @author Sven Schauwvliege (Last modified by $Author: shally $)
27 * @version $Revision: 1.10 $ - $Date: 2005/12/20 15:36:47 $
28 */
29
30
31 public class CommentDaoImplTests 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", "Offer_OfferType", "Offer_Profile","JobOffer", "Comment"};
37 /***
38 * the columns to ignore.
39 */
40 private static final String[] IGNORE = {"id", "modificationdate"};
41 /***
42 * the jobofferdao, injected through field-injection.
43 */
44 protected CommentDao commentDao;
45
46 /***
47 * @return Returns the commentDao.
48 */
49 public CommentDao getCommentDao() {
50 return commentDao;
51 }
52
53 /***
54 * Test the Create, Read, Read all, Update and Delete functions for a Comment.
55 *
56 * @throws DataAccessException Thrown when a database exceptions occurs.
57 */
58 public void testCRUDComment() throws DataAccessException {
59
60 Integer userId = new Integer(500);
61
62
63
64
65 List offers = commentDao.getComments(userId, false);
66 assertTrue("read failed, amount of found objects not 5 but " + (offers.size()), offers.size() == 5);
67 assertTrue("read failed ", offers.get(0).getClass() == Comment.class);
68
69
70 Comment com50 = getCommentDao().getComment(new Integer(50));
71 Comment com51 = getCommentDao().getComment(new Integer(51));
72 Comment com52 = getCommentDao().getComment(new Integer(52));
73 Comment com53 = getCommentDao().getComment(new Integer(53));
74 Comment com54 = getCommentDao().getComment(new Integer(54));
75
76
77
78
79
80 Comment deleteComment = getCommentDao().getComment(new Integer(54));
81
82 getCommentDao().deleteComment(new Integer(50));
83
84 getCommentDao().deleteComment(deleteComment);
85
86
87
88
89 List emptyComments = getCommentDao().getComments(userId, false);
90 assertTrue("delete faled ", emptyComments.size() == 0);
91
92
93 com50.setParentComment(null);
94 com50.getChildComments().clear();
95 com50.setVersion(null);
96 com51.setParentComment(null);
97 com51.getChildComments().clear();
98 com51.setVersion(null);
99 com52.setParentComment(null);
100 com52.getChildComments().clear();
101 com52.setVersion(null);
102 com53.setParentComment(null);
103 com53.getChildComments().clear();
104 com53.setVersion(null);
105 com54.setParentComment(null);
106 com54.getChildComments().clear();
107 com54.setVersion(null);
108
109
110
111
112
113 getCommentDao().store(com50);
114
115 com50.addChildComment(com51);
116 getCommentDao().store(com50);
117
118 com51.addChildComment(com52);
119 getCommentDao().store(com51);
120
121 com50.addChildComment(com53);
122 getCommentDao().store(com50);
123
124 getCommentDao().store(com54);
125
126 List foundComments = getCommentDao().getComments(userId, false);
127 assertTrue("save failed, amount of found objects not 5 but " + foundComments.size(), foundComments.size() == 5);
128
129
130 assertDBAsExpected(TABLE_NAMES, IGNORE);
131 }
132
133 /***
134 * Test the update/ get by id.
135 *
136 * @throws DataAccessException Thrown when a database exceptions occurs.
137 */
138 public void testUpdateReadComment() throws DataAccessException {
139
140
141 Comment foundComment = getCommentDao().getComment(new Integer(50));
142 assertEquals("error in get by id", foundComment.getContent(), "Test comment 1");
143 assertEquals("error in get by id", foundComment.getId(), new Integer(50));
144
145
146 foundComment.setContent("update");
147 getCommentDao().store(foundComment);
148 Comment newComment = getCommentDao().getComment(new Integer(50));
149 assertEquals("error in update", newComment.getContent(), "update");
150 assertEquals("error in update", newComment.getId(), new Integer(50));
151 }
152
153 /***
154 * {@inheritDoc}
155 */
156 public void onSetUpInTransaction() throws Exception {
157 init(TABLE_NAMES);
158
159 }
160
161 }
162
163 /***
164 * $Log: CommentDaoImplTests.java,v $
165 * Revision 1.10 2005/12/20 15:36:47 shally
166 * CheckStyle and PMD changes.
167 *
168 * Revision 1.9 2005/08/24 08:12:19 schauwvliege
169 * addded resume
170 *
171 * Revision 1.8 2005/08/03 13:16:03 bme_jcs
172 * getDao's removed and storeObject renamed to store
173 *
174 * Revision 1.7 2005/08/03 09:10:58 ge0ffrey
175 * JAVACAREERS-247
176 *
177 * Revision 1.6 2005/07/06 12:10:10 schauwvliege
178 * added person/contact and location to model
179 *
180 * Revision 1.5 2005/07/05 15:09:30 schauwvliege
181 * added person/contact and location to model
182 *
183 * Revision 1.4 2005/06/29 09:00:26 psong09
184 * comment component updated
185 *
186 * Revision 1.3 2005/06/14 13:34:56 schauwvliege
187 * fixed tests
188 *
189 * Revision 1.2 2005/06/09 08:19:04 bejug_cc
190 * Fix initial import
191 *
192 * Revision 1.1 2005/05/25 11:06:53 ssc
193 * added DBUnit tests and fixed some errors
194 *
195 **/