1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.services.scheduling.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.core.InvalidParameterException;
19 import org.figure8.join.services.scheduling.QuartzCronInfo;
20 import org.figure8.join.services.scheduling.QuartzCronParameterInfo;
21 /**
22 * JUnit test case for testing QuartzCronInfoDao implementation.
23 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
24 * @version Revision$
25 */
26 public class QuartzCronInfoDaoTest extends SpringTestCase{
27
28
29
30 /** Spring configuration files */
31 private String[] configLocations = new String[]{"classpath:/org/figure8/join/services/scheduling/persistence/spring.xml"};
32
33
34
35
36 /** The QuartzCronInfo dao implementation to test. */
37 protected QuartzCronInfoDao dao = null;
38
39
40
41
42 /** Retrieve QuartzCronInfo dao after having initialized context */
43 public void setUp(){
44 super.setUp();
45
46 dao = (QuartzCronInfoDao)context.getBean("cronInfoDao");
47 }
48
49
50
51
52 /** Test the creation of QuartzCronInfo. */
53 public void testCronInfoCreation(){
54 try{
55
56 QuartzCronInfo info = new QuartzCronInfo("creation", "expression", "type",
57 "org.figure8.join.services.scheduling.EchoQuartzJob");
58 int size = getCronInfoListSize();
59 dao.save(info);
60
61 assertEquals("QuartzCronInfo is successfully created", size + 1, dao.findAll().size());
62 }
63 catch (InvalidParameterException e){
64 fail("No InvalidParameterException should have been thrown ...");
65 }
66 }
67
68 /** Test the getByName() method on dao. */
69 public void testFindByName(){
70 try{
71
72 QuartzCronInfo info1 = new QuartzCronInfo("cron1", "expression1", "type",
73 "org.figure8.join.services.scheduling.EchoQuartzJob");
74 QuartzCronInfo info2 = new QuartzCronInfo("cron2", "expression2", "type",
75 "org.figure8.join.services.scheduling.EchoQuartzJob");
76 QuartzCronParameterInfo param1 = new QuartzCronParameterInfo("name1", "value1", false);
77 QuartzCronParameterInfo param2 = new QuartzCronParameterInfo("name2", "value2", false);
78 info2.addJobParameterInfo(param1);
79 info2.addJobParameterInfo(param2);
80 int size = getCronInfoListSize();
81 dao.save(info1);
82 dao.save(info2);
83
84 assertEquals("QuartzCronInfos are successfully created", size + 2, dao.findAll().size());
85
86 QuartzCronInfo foundInfo = dao.getQuartzCronInfo("cron2");
87 assertNotNull("Found an info", foundInfo);
88 assertEquals("Found an info with correct name", "cron2", foundInfo.getName());
89 assertEquals("Found an info with correct expression", "expression2", foundInfo.getCronExpression());
90 assertEquals("Found an info with correct job class", "org.figure8.join.services.scheduling.EchoQuartzJob", foundInfo.getJobClass());
91 assertEquals("Found an info with correct job params", 2, foundInfo.getJobParameterInfos().size());
92 }
93 catch (InvalidParameterException e){
94 fail("No InvalidParameterException should have been thrown ...");
95 }
96 }
97
98 /** Test the removal of QuartzCronInfo. */
99 public void testCronInfoRemoval(){
100 try{
101
102 QuartzCronInfo info = new QuartzCronInfo("removal", "expression", "type",
103 "org.figure8.join.services.scheduling.EchoQuartzJob");
104 int size = getCronInfoListSize();
105 dao.save(info);
106
107 assertEquals("QuartzCronInfo is successfully created", size + 1, dao.findAll().size());
108
109 dao.remove(info);
110 assertEquals("QuartzCronInfo is successfully removed", size, dao.findAll().size());
111 }
112 catch (InvalidParameterException e){
113 fail("No InvalidParameterException should have been thrown ...");
114 }
115 }
116
117
118
119
120 /** Test the findAll on conr */
121 protected int getCronInfoListSize(){
122 return dao.findAll().size();
123 }
124
125
126
127
128 /** @return configLocations inner field */
129 public String[] getConfigLocations(){
130 return configLocations;
131 }
132 }