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.view.jsf.model;
19  
20  import java.util.Calendar;
21  import java.util.Date;
22  import java.util.List;
23  
24  import org.bejug.javacareers.jobs.common.AbstractSpringContextTests;
25  import org.bejug.javacareers.jobs.model.JobOffer;
26  import org.bejug.javacareers.jobs.model.User;
27  import org.bejug.javacareers.jobs.service.AdminService;
28  import org.bejug.javacareers.jobs.service.JobService;
29  
30  /***
31   * @author kva (last modified by $Author: schauwvliege $)
32   * @version $Revision: 1.6 $ - $Date: 2005/09/13 08:11:06 $
33   */
34  public class MailBeanTests extends AbstractSpringContextTests {
35  
36      /***
37       * the admin service to use.
38       */
39      protected AdminService adminService;
40  
41      /***
42       * the job service to use.
43       */
44      protected JobService jobService;
45  
46      /***
47       * the job digest query and mailer.
48       */
49      protected MailBean mailBean;
50  
51      /***
52       * With no jobs posted the job digest should be empty.
53       */
54      public void testEmptyJobDigest() {
55          List list = mailBean.getJobsPostedInLast24Hours();
56          assertNotNull("Expected non-null list", list);
57          assertTrue("Expected empty list", list.size() == 0);
58      }
59  
60      /***
61       * Post two jobs, expect one to be returned.
62       */
63      public void testNonEmptyJobDigest() {
64          Calendar yesterday = Calendar.getInstance();
65          Calendar twoDaysAgo = Calendar.getInstance();
66          Date now = new Date();
67  
68          /* calculate two days ago */
69          twoDaysAgo.add(Calendar.DATE, -2);
70  
71          /* post a job with publication date two days ago */
72          postSomeJob(twoDaysAgo.getTime());
73  
74          /* post a job with publication date now */
75          postSomeJob(now);
76  
77          /* calculate yesterday */
78          yesterday.add(Calendar.DATE, -1);
79  
80          /* get the jobs posted since yesterday */
81          List list = mailBean.getJobsPostedInLast24Hours();
82  
83          assertNotNull("Expected non-null list", list);
84          assertTrue("Expected one job in list", list.size() == 1);
85  
86          JobOffer job = (JobOffer) list.get(0);
87          assertEquals("Expected matching description", "Test",
88                  job.getDescription());
89          assertEquals("Expected matching publication dates",
90                  now, job.getPublicationDate());
91      }
92  
93      /***
94       * Post a job with a certain publication date.
95       *
96       * @param pubDate publication date.
97       */
98      private void postSomeJob(Date pubDate) {
99          User user = adminService.getUserByUserName("user");
100 
101         JobOffer jobOffer = new JobOffer();
102         jobOffer.setPublicationDate(pubDate);
103         jobOffer.setDescription("Test");
104         jobOffer.setLocation("Gent");
105         jobOffer.setSourceName("BeJUG");
106         jobOffer.setSourceUrl("http://www.bejug.org");
107         jobOffer.setTitle("Senior Developer");
108         jobOffer.setStatus(1);
109         jobOffer.setUser(user);
110 
111         jobService.storeJobOffer(jobOffer);
112     }
113 
114     /***
115      * @param jobDigest The mailBean to set.
116      */
117     public void setMailBean(MailBean jobDigest) {
118         this.mailBean = jobDigest;
119     }
120 
121     /***
122      * @param jobService The jobService to set.
123      */
124     public void setJobService(JobService jobService) {
125         this.jobService = jobService;
126     }
127 }
128 
129 /***
130  * $Log: MailBeanTests.java,v $
131  * Revision 1.6  2005/09/13 08:11:06  schauwvliege
132  * organize imports
133  *
134  * Revision 1.5  2005/08/30 13:07:48  psong09
135  * renamed author: psong09
136  *
137  * Revision 1.4  2005/06/29 09:00:27  psong09
138  * comment component updated
139  *
140  * Revision 1.3  2005/06/14 13:34:59  schauwvliege
141  * fixed tests
142  *
143  * Revision 1.2  2005/06/09 08:19:04  bejug_cc
144  * Fix initial import
145  *
146  * Revision 1.2  2005/06/05 12:28:48  sja
147  * Introduced sourceUrl and sourceName in jobOffer.
148  *
149  * Revision 1.1  2005/06/01 08:54:15  kva
150  * added page to handle forgotten passwords
151  *
152  * Revision 1.1  2005/05/26 10:41:39  kva
153  * added job digest mail
154  *
155  */