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 package org.bejug.javacareers.jobs.service;
19
20 import java.util.List;
21
22 import org.bejug.javacareers.common.exception.DuplicateUserNameException;
23 import org.bejug.javacareers.common.exception.LastAdminException;
24 import org.bejug.javacareers.common.search.SearchCriteria;
25 import org.bejug.javacareers.common.search.SearchCriteriaFactory;
26 import org.bejug.javacareers.generator.StubGenerator;
27 import org.bejug.javacareers.jobs.common.AbstractSpringContextTests;
28 import org.bejug.javacareers.jobs.model.Address;
29 import org.bejug.javacareers.jobs.model.ConsultingServiceOffer;
30 import org.bejug.javacareers.jobs.model.EducationServiceOffer;
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 * This class unittests all the functionalities of the serviceofferservice.
37 *
38 * @author Bart Meyers
39 * @version $Revision: 1.5 $ $Date: 2005/12/20 15:36:47 $
40 */
41 public class ServiceOfferServiceImplTests extends AbstractSpringContextTests {
42
43 /***
44 * The admin service which gets set via an IoC setter injection.
45 */
46 protected AdminService adminService;
47
48 /***
49 * The Education service reference which gets set via an IoC setter injection.
50 */
51 protected ServiceOfferService serviceOfferService;
52
53 /***
54 * The SearchCriteriaFactory
55 */
56 protected SearchCriteriaFactory searchCriteriaFactory;
57
58 /***
59 * @return Returns the adminService.
60 */
61 public AdminService getAdminService() {
62 return adminService;
63 }
64
65 /***
66 * @return Returns the serviceOfferService.
67 */
68 public ServiceOfferService getServiceOfferService() {
69 return serviceOfferService;
70 }
71
72
73 /***
74 * Test if the serviceOfferService is configured and injected.
75 */
76 public void testServiceOfferService() {
77 assertNotNull(getServiceOfferService());
78 }
79
80
81 /***
82 * Todo: Finish this test method!!
83 */
84 public void testGetServiceOffers() {
85
86 assertNotNull(getServiceOfferService());
87
88 EducationServiceOffer serviceOffer = StubGenerator.getStubEducationServiceOffer();
89
90 User myUser = StubGenerator.getStubUser();
91 Organisation org = StubGenerator.getStubOrganisation();
92
93 Address address = StubGenerator.getStubAddress();
94
95
96 OrganisationType type = StubGenerator.getStubOrganisationType();
97 org.setOrganisationType(type);
98 getAdminService().storeOrganisationType(type);
99
100 org.setAddress(address);
101 myUser.setOrganisation(org);
102 serviceOffer.setUser(myUser);
103
104 try {
105 getAdminService().storeUser(myUser);
106 } catch (DuplicateUserNameException e) {
107 assertTrue("Duplicate username", false);
108 e.printStackTrace();
109 } catch (LastAdminException e) {
110 assertTrue("Last admin username in save", false);
111 }
112 getServiceOfferService().storeServiceOffer(serviceOffer);
113
114 List list = getServiceOfferService().getEducationServiceOffers();
115 assertNotNull(list);
116 assertTrue(list.size() == 1);
117
118 SearchCriteria searchCriteria =
119 searchCriteriaFactory.createSearchCriteria(EducationServiceOffer.class);
120 searchCriteria.addEqualsCriterium("description", "Test");
121 List searchList = null;
122 try {
123 searchList = getServiceOfferService().getEducationServiceOffers(searchCriteria);
124 } catch (IllegalArgumentException e1) {
125 e1.printStackTrace();
126 assertTrue("illegal argument exception", false);
127 }
128 assertNotNull(searchList);
129 assertTrue(searchList.size() == 1);
130
131 int numberOfOffersInDatabase = getServiceOfferService().getEducationServiceOffersCount();
132 if (numberOfOffersInDatabase != 1) {
133 assertTrue(false);
134 }
135
136
137 SearchCriteria searchCriteriaIllegal =
138 searchCriteriaFactory.createSearchCriteria(User.class);
139 searchCriteriaIllegal.addEqualsCriterium("description", "Test");
140 searchList = null;
141 boolean exception = false;
142 try {
143 searchList = getServiceOfferService().getEducationServiceOffers(searchCriteriaIllegal);
144 } catch (IllegalArgumentException e1) {
145 e1.printStackTrace();
146 exception = true;
147 }
148 assertTrue("illegal argument exception", exception);
149 }
150
151 /***
152 * Todo: Finish this test method!!
153 */
154 public void testGetCommercialOffers() {
155
156 assertNotNull(getServiceOfferService());
157
158 ConsultingServiceOffer serviceOffer = StubGenerator.getStubConsultingServiceOffer();
159
160 User myUser = StubGenerator.getStubUser();
161 Organisation org = StubGenerator.getStubOrganisation();
162
163 Address address = StubGenerator.getStubAddress();
164
165
166 OrganisationType type = StubGenerator.getStubOrganisationType();
167 org.setOrganisationType(type);
168 getAdminService().storeOrganisationType(type);
169
170 org.setAddress(address);
171 myUser.setOrganisation(org);
172 serviceOffer.setUser(myUser);
173
174 try {
175 getAdminService().storeUser(myUser);
176 } catch (DuplicateUserNameException e) {
177 assertTrue("Duplicate username", false);
178 e.printStackTrace();
179 } catch (LastAdminException e) {
180 assertTrue("Last admin username in save", false);
181 }
182 getServiceOfferService().storeServiceOffer(serviceOffer);
183
184 List list = getServiceOfferService().getConsultingServiceOffers();
185 assertNotNull(list);
186 assertTrue(list.size() == 1);
187
188 SearchCriteria searchCriteria =
189 searchCriteriaFactory.createSearchCriteria(ConsultingServiceOffer.class);
190 searchCriteria.addEqualsCriterium("description", "Test");
191 List searchList = null;
192 try {
193 searchList = getServiceOfferService().getConsultingServiceOffers(searchCriteria);
194 } catch (IllegalArgumentException e1) {
195 e1.printStackTrace();
196 assertTrue("illegal argument exception", false);
197 }
198 assertNotNull(searchList);
199 assertTrue(searchList.size() == 1);
200
201 int numberOfOffersInDatabase = getServiceOfferService().getConsultingServiceOffersCount();
202 if (numberOfOffersInDatabase != 1) {
203 assertTrue(false);
204 }
205
206
207 SearchCriteria searchCriteriaIllegal =
208 searchCriteriaFactory.createSearchCriteria(User.class);
209 searchCriteriaIllegal.addEqualsCriterium("description", "Test");
210 searchList = null;
211 boolean exception = false;
212 try {
213 searchList = getServiceOfferService().getConsultingServiceOffers(searchCriteriaIllegal);
214 } catch (IllegalArgumentException e1) {
215 e1.printStackTrace();
216 exception = true;
217 }
218 assertTrue("illegal argument exception", exception);
219 }
220 }
221
222 /***
223 * $Log: ServiceOfferServiceImplTests.java,v $
224 * Revision 1.5 2005/12/20 15:36:47 shally
225 * CheckStyle and PMD changes.
226 *
227 * Revision 1.4 2005/08/17 09:08:56 schauwvliege
228 * added education en service offer services
229 *
230 * Revision 1.3 2005/06/29 09:00:27 psong09
231 * comment component updated
232 *
233 * Revision 1.2 2005/06/09 08:19:04 bejug_cc
234 * Fix initial import
235 *
236 * Revision 1.1 2005/05/04 09:55:06 bme
237 * modified for introduction AOP
238 *
239 */