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.AcademicEducationOffer;
29  import org.bejug.javacareers.jobs.model.Address;
30  import org.bejug.javacareers.jobs.model.CommercialEducationOffer;
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   * tests the EducationService
37   *
38   * @author Bart Meyers
39   * @version $Revision: 1.2 $ $Date: 2005/12/20 15:36:47 $
40   */
41  public class EducationServiceImplTests extends AbstractSpringContextTests {
42  	  /***
43       * The admin service which gets set via an IoC setter injection.
44       */
45      protected AdminService adminService;
46  
47      /***
48       * The Education service reference which gets set via an IoC setter injection.
49       */
50      protected EducationService educationService;
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 educationService.
66       */
67      public EducationService getEducationService() {
68          return educationService;
69      }
70  
71  
72      /***
73       * Test if the educationService is configured and injected.
74       */
75      public void testEducationService() {
76          assertNotNull(getEducationService());
77      }
78  
79  
80      /***
81       * Todo: Finish this test method!!
82       */
83      public void testGetAcademicOffers() {
84  
85          assertNotNull(getEducationService());
86  
87          AcademicEducationOffer educationOffer = StubGenerator.getStubAcademicEducationOffer();
88          //create a user
89          User myUser = StubGenerator.getStubUser();
90          Organisation org = StubGenerator.getStubOrganisation();
91  
92          Address address = StubGenerator.getStubAddress();
93  
94  //      create an organisationtype and save it
95          OrganisationType type = StubGenerator.getStubOrganisationType();
96          org.setOrganisationType(type);
97          getAdminService().storeOrganisationType(type);
98  
99          org.setAddress(address);
100         myUser.setOrganisation(org);
101         educationOffer.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         getEducationService().storeEducationOffer(educationOffer);
112         // test get all
113         List list = getEducationService().getAcademicEducationOffers();
114         assertNotNull(list);
115         assertTrue(list.size() == 1);
116         // test search criteria
117         SearchCriteria searchCriteria =
118                 searchCriteriaFactory.createSearchCriteria(AcademicEducationOffer.class);
119         searchCriteria.addEqualsCriterium("description", "Test");
120         List searchList = null;
121         try {
122             searchList = getEducationService().getAcademicEducationOffers(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 numberOfOffersInDatabase = getEducationService().getAcademicEducationsCount();
131         if (numberOfOffersInDatabase != 1) {
132             assertTrue(false);
133         }
134 
135         //test illegal argument exception
136         SearchCriteria searchCriteriaIllegal =
137                 searchCriteriaFactory.createSearchCriteria(User.class);
138         searchCriteriaIllegal.addEqualsCriterium("description", "Test");
139         searchList = null;
140         boolean exception = false;
141         try {
142             searchList = getEducationService().getAcademicEducationOffers(searchCriteriaIllegal);
143         } catch (IllegalArgumentException e1) {
144             e1.printStackTrace();
145             exception = true;
146         }
147         assertTrue("illegal argument exception", exception);
148     }
149     
150     /***
151      * Todo: Finish this test method!!
152      */
153     public void testGetCommercialOffers() {
154 
155         assertNotNull(getEducationService());
156 
157         CommercialEducationOffer educationOffer = StubGenerator.getStubCommercialEducationOffer();
158         //create a user
159         User myUser = StubGenerator.getStubUser();
160         Organisation org = StubGenerator.getStubOrganisation();
161 
162         Address address = StubGenerator.getStubAddress();
163 
164 //      create an organisationtype and save it
165         OrganisationType type = StubGenerator.getStubOrganisationType();
166         org.setOrganisationType(type);
167         getAdminService().storeOrganisationType(type);
168 
169         org.setAddress(address);
170         myUser.setOrganisation(org);
171         educationOffer.setUser(myUser);
172 
173         try {
174             getAdminService().storeUser(myUser);
175         } catch (DuplicateUserNameException e) {
176             assertTrue("Duplicate username", false);
177             e.printStackTrace();
178         } catch (LastAdminException e) {
179             assertTrue("Last admin username in save", false);
180         }
181         getEducationService().storeEducationOffer(educationOffer);
182         // test get all
183         List list = getEducationService().getCommercialEducationOffers();
184         assertNotNull(list);
185         assertTrue(list.size() == 1);
186         // test search criteria
187         SearchCriteria searchCriteria =
188                 searchCriteriaFactory.createSearchCriteria(CommercialEducationOffer.class);
189         searchCriteria.addEqualsCriterium("description", "Test");
190         List searchList = null;
191         try {
192             searchList = getEducationService().getCommercialEducationOffers(searchCriteria);
193         } catch (IllegalArgumentException e1) {
194             e1.printStackTrace();
195             assertTrue("illegal argument exception", false);
196         }
197         assertNotNull(searchList);
198         assertTrue(searchList.size() == 1);
199 
200         int numberOfOffersInDatabase = getEducationService().getCommercialEducationsCount();
201         if (numberOfOffersInDatabase != 1) {
202             assertTrue(false);
203         }
204 
205         //test illegal argument exception
206         SearchCriteria searchCriteriaIllegal =
207                 searchCriteriaFactory.createSearchCriteria(User.class);
208         searchCriteriaIllegal.addEqualsCriterium("description", "Test");
209         searchList = null;
210         boolean exception = false;
211         try {
212             searchList = getEducationService().getCommercialEducationOffers(searchCriteriaIllegal);
213         } catch (IllegalArgumentException e1) {
214             e1.printStackTrace();
215             exception = true;
216         }
217         assertTrue("illegal argument exception", exception);
218     }
219 
220 
221 }
222 
223 /***
224  * $Log: EducationServiceImplTests.java,v $
225  * Revision 1.2  2005/12/20 15:36:47  shally
226  * CheckStyle and PMD changes.
227  *
228  * Revision 1.1  2005/08/17 09:08:56  schauwvliege
229  * added education en service offer services
230  *
231  * Revision 1.4  2005/08/11 08:12:17  bme_jcs
232  * refactoring of adminService
233  *
234  * Revision 1.3  2005/06/29 09:00:27  psong09
235  * comment component updated
236  *
237  * Revision 1.2  2005/06/09 08:19:04  bejug_cc
238  * Fix initial import
239  *
240  * Revision 1.2  2005/05/12 08:23:55  ssc
241  * Checkstyle errors
242  *
243  * Revision 1.1  2005/05/04 09:55:06  bme
244  * modified for introduction AOP
245  *
246  */