    1   /***
    2    * @(#)QuartzServiceImplTest.java
    3    *
    4    * JFoxSOAF, Service-Oriented Application Framework
    5    *
    6    * Copyright(c) JFoxSOAF Team
    7    *
    8    * Licensed under the GNU LGPL, Version 2.1 (the "License");
    9    * you may not use this file except in compliance with the License.
    10   * You may obtain a copy of the License at
    11   *
    12   * http://www.gnu.org/copyleft/lesser.html
    13   *
    14   * Unless required by applicable law or agreed to in writing, software
    15   * distributed under the License is distributed on an "AS IS" BASIS,
    16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17   * See the License for the specific language governing permissions and
    18   * limitations under the License.
    19   *
    20   * For more information, please visit:
    21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
    22   * http://www.huihoo.org/jfox/jfoxsoaf
    23   */
    24
    25  package org.huihoo.jfox.soaf.services.timer;
    26
    27  import java.util.Date;
    28
    29  import junit.framework.TestCase;
    30
    31  import org.apache.commons.logging.Log;
    32  import org.apache.commons.logging.LogFactory;
    33  import org.huihoo.jfox.soaf.container.ServiceFactory;
    34  import org.huihoo.jfox.soaf.container.ServiceLoader;
    35  import org.quartz.JobDetail;
    36  import org.quartz.Scheduler;
    37  import org.quartz.SchedulerException;
    38  import org.quartz.SimpleTrigger;
    39  import org.quartz.helpers.TriggerUtils;
    40
    41  /***
    42   * JUnit test case for the
    43   * {@link org.huihoo.jfox.soaf.services.timer.QuartzServiceImpl).
    44   *
    45   * @author <a href="mailto:founder_chen@yahoo.com">Peter Cheng </a>
    46   * @version $Revision:$ $Date:$
    47   * @version Revision: 1.0
    48   */
    49
    50  public class QuartzServiceImplTest extends TestCase {
    51
    52  	private static final Log log = LogFactory.getLog(QuartzServiceImplTest.class);
    53
    54  	private ServiceLoader sl = ServiceLoader.getInstance();
    55
    56  	private ServiceFactory sf = ServiceFactory.getInstance();
    57
    58  	private QuartzService quartzService;
    59
    60  	public static void main(String[] args) {
    61  		QuartzServiceImplTest quartzServiceImplTest = new QuartzServiceImplTest();
    62  		try {
    63  			quartzServiceImplTest.setUp();
    64  		} catch (Exception e) {
    65  			e.printStackTrace();
    66  		}
    67  		quartzServiceImplTest.testGetScheduler();
    68  	}
    69
    70  	/*
    71  	 * @see TestCase#setUp()
    72  	 */
    73  	protected void setUp() throws Exception {
    74
    75  		if (!sl.isServiceLoaded()) {
    76  			sl.initService("jfoxsoaf-config.xml");
    77  		}
    78  		quartzService = (QuartzService) sf.getService(QuartzService.class);
    79  	}
    80
    81  	/*
    82  	 * @see TestCase#tearDown()
    83  	 */
    84  	protected void tearDown() throws Exception {
    85
    86  	}
    87
    88  	public void testGetScheduler() {
    89  		long ts = TriggerUtils.getNextGivenSecondDate(null, 15).getTime();
    90  		JobDetail job = new JobDetail("job1", "group1", DumbJob.class);
    91          SimpleTrigger trigger = new SimpleTrigger("trigg1", "group1", new Date(
    92                  ts));
    93          Scheduler sched = quartzService.getScheduler();
    94          try {
    95  			Date ft = sched.scheduleJob(job, trigger);
    96  		} catch (SchedulerException e) {
    97  			log.info(e.getMessage());
    98  		}
    99  	}
    100
    101 }