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 */
18
19 package org.bejug.javacareers.jobs.service;
20
21 import java.util.List;
22
23 import org.bejug.javacareers.common.exception.DuplicateUserNameException;
24 import org.bejug.javacareers.common.exception.LastAdminException;
25 import org.bejug.javacareers.common.search.SearchCriteria;
26 import org.bejug.javacareers.common.search.SearchCriteriaFactory;
27 import org.bejug.javacareers.generator.StubGenerator;
28 import org.bejug.javacareers.jobs.common.AbstractSpringContextTests;
29 import org.bejug.javacareers.jobs.model.Address;
30 import org.bejug.javacareers.jobs.model.JobOffer;
31 import org.bejug.javacareers.jobs.model.Organisation;
32 import org.bejug.javacareers.jobs.model.OrganisationType;
33 import org.bejug.javacareers.jobs.model.User;
34
35 /***
36 * @author Peter Symoens (Last modified by $Author: shally $)
37 * @version $Revision: 1.16 $ - $Date: 2005/12/20 15:36:47 $)
38 * Todo: this unittest is not correct
39 */
40 public class JobServiceImplTests extends AbstractSpringContextTests {
41
42 /***
43 * The admin service which gets set via an IoC setter injection.
44 */
45 protected AdminService adminService;
46
47 /***
48 * The job service reference which gets set via an IoC setter injection.
49 */
50 protected JobService jobService;
51
52 /***
53 * The SearchCriteriaFactory
54 */
55 protected SearchCriteriaFactory searchCriteriaFactory;
56
57 /***
58 * @return Returns the adminService.
59 */
60 public AdminService getAdminService() {
61 return adminService;
62 }
63
64 /***
65 * @return Returns the jobService.
66 */
67 public JobService getJobService() {
68 return jobService;
69 }
70
71
72 /***
73 * Test if the jobService is configured and injected.
74 */
75 public void testGetJobOfferDao() {
76 assertNotNull(getJobService());
77 }
78
79
80 /***
81 * Todo: Finish this test method!!
82 */
83 public void testGetOffers() {
84
85 assertNotNull(getJobService());
86
87 JobOffer jobOffer = StubGenerator.getStubJobOffer();
88
89 User myUser = StubGenerator.getStubUser();
90 Organisation org = StubGenerator.getStubOrganisation();
91
92 Address address = StubGenerator.getStubAddress();
93
94
95 OrganisationType type = StubGenerator.getStubOrganisationType();
96 org.setOrganisationType(type);
97 getAdminService().storeOrganisationType(type);
98
99 org.setAddress(address);
100 myUser.setOrganisation(org);
101 jobOffer.setUser(myUser);
102
103 try {
104 getAdminService().storeUser(myUser);
105 } catch (DuplicateUserNameException e) {
106 assertTrue("Duplicate username", false);
107 e.printStackTrace();
108 } catch (LastAdminException e) {
109 assertTrue("Last admin username in save", false);
110 }
111 getJobService().storeJobOffer(jobOffer);
112
113 List list = getJobService().getJobOffers();
114 assertNotNull(list);
115 assertTrue(list.size() == 1);
116
117 SearchCriteria searchCriteria =
118 searchCriteriaFactory.createSearchCriteria(JobOffer.class);
119 searchCriteria.addEqualsCriterium("description", "Test");
120 List searchList = null;
121 try {
122 searchList = getJobService().getJobOffers(searchCriteria);
123 } catch (IllegalArgumentException e1) {
124 e1.printStackTrace();
125 assertTrue("illegal argument exception", false);
126 }
127 assertNotNull(searchList);
128 assertTrue(searchList.size() == 1);
129
130 int numberOfJobsInDatabase = getJobService().getJobOfferCount();
131 if (numberOfJobsInDatabase != 1) {
132 assertTrue(false);
133 }
134
135
136 SearchCriteria searchCriteriaIllegal =
137 searchCriteriaFactory.createSearchCriteria(User.class);
138 searchCriteriaIllegal.addEqualsCriterium("description", "Test");
139 searchList = null;
140 boolean exception = false;
141 try {
142 searchList = getJobService().getJobOffers(searchCriteriaIllegal);
143 } catch (IllegalArgumentException e1) {
144 e1.printStackTrace();
145 exception = true;
146 }
147 assertTrue("illegal argument exception", exception);
148 }
149
150
151
152
153
154
155 }
156
157 /***
158 * $Log: JobServiceImplTests.java,v $
159 * Revision 1.16 2005/12/20 15:36:47 shally
160 * CheckStyle and PMD changes.
161 *
162 * Revision 1.15 2005/08/17 09:09:30 schauwvliege
163 * Fixed all unit tests
164 *
165 * Revision 1.14 2005/08/12 08:33:09 bme_jcs
166 * moved profile-methods from jobservice to adminservice
167 *
168 * Revision 1.13 2005/08/11 13:31:36 bavo_jcs
169 * LastAdmin Fix
170 *
171 * Revision 1.12 2005/08/11 08:12:17 bme_jcs
172 * refactoring of adminService
173 *
174 * Revision 1.11 2005/08/04 14:52:00 psong09
175 * Removed test methods
176 *
177 * Revision 1.10 2005/08/03 13:16:03 bme_jcs
178 * getDao's removed and storeObject renamed to store
179 *
180 * Revision 1.9 2005/07/14 09:27:03 bme_jcs
181 * it is not allowed to create a service using the NEW keyword.
182 * The services are managed by Spring.
183 *
184 * Revision 1.8 2005/07/05 10:48:17 psong09
185 * rename of MockObs to StubGenerator
186 *
187 * Revision 1.7 2005/06/29 09:00:27 psong09
188 * comment component updated
189 *
190 * Revision 1.6 2005/06/17 09:32:54 psong09
191 * added subject field to comment
192 *
193 * Revision 1.5 2005/06/17 07:50:16 bavo_jcs
194 * temp commnted out non-compiling code
195 *
196 * Revision 1.4 2005/06/16 14:32:17 psong09
197 * moved creation collaborator objects to StubGenerator
198 *
199 * Revision 1.3 2005/06/14 13:34:59 schauwvliege
200 * fixed tests
201 *
202 * Revision 1.2 2005/06/09 08:19:04 bejug_cc
203 * Fix initial import
204 *
205 * Revision 1.16 2005/06/05 12:28:48 sja
206 * Introduced sourceUrl and sourceName in jobOffer.
207 *
208 * Revision 1.15 2005/06/01 09:12:25 bme
209 * introduction of a factory for the searchCriteria
210 *
211 * Revision 1.14 2005/05/31 07:10:06 bme
212 * added count-methods
213 *
214 * Revision 1.13 2005/05/25 15:38:45 ssc
215 * Optimized tests for search criteria
216 *
217 * Revision 1.12 2005/05/17 11:59:56 ssc
218 * Refactored User and Publisher class to User Class added cvAdded Boolean, added Address to user, Fixed test to work with this setup
219 *
220 * Revision 1.11 2005/05/13 09:17:25 ssc
221 * Test CRUD profile
222 *
223 * Revision 1.10 2005/05/11 20:14:48 kva
224 * fix duplicate JavaCareerException problem
225 *
226 * Revision 1.9 2005/05/11 17:58:42 sja
227 * Corrected import.
228 *
229 * Revision 1.8 2005/05/11 12:49:30 ssc
230 * Checstyle errors
231 *
232 * Revision 1.7 2005/05/11 10:14:52 ssc
233 * Checstyle errors
234 *
235 * Revision 1.6 2005/05/09 13:30:19 bme
236 * updated for the introduction of the 'generalised' parameterhandling
237 *
238 * Revision 1.5 2005/05/04 09:55:06 bme
239 * modified for introduction AOP
240 *
241 * Revision 1.4 2005/05/01 17:37:37 sja
242 * Added ProfileDao related tests.
243 *
244 * Revision 1.3 2005/04/29 18:19:27 sja
245 * Added CVS tags.
246 *
247 */