KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > DirectSchedulerFactoryTest


1 /*
2  * Copyright 2004-2006 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  */

16 package org.quartz.impl;
17
18 import java.util.Collections JavaDoc;
19
20 import junit.framework.TestCase;
21
22 import org.quartz.Scheduler;
23 import org.quartz.simpl.RAMJobStore;
24 import org.quartz.simpl.SimpleThreadPool;
25 import org.quartz.spi.SchedulerPlugin;
26 import org.quartz.spi.ThreadPool;
27
28 public class DirectSchedulerFactoryTest extends TestCase {
29     public void testPlugins() throws Exception JavaDoc {
30         final StringBuffer JavaDoc result = new StringBuffer JavaDoc();
31         
32         SchedulerPlugin testPlugin = new SchedulerPlugin() {
33             public void initialize(String JavaDoc name, org.quartz.Scheduler scheduler) throws org.quartz.SchedulerException {
34                 result.append(name).append("|").append(scheduler.getSchedulerName());
35             };
36             public void start() {
37                 result.append("|start");
38             };
39             public void shutdown() {
40                 result.append("|shutdown");
41             };
42         };
43         
44         ThreadPool threadPool = new SimpleThreadPool(1, 5);
45         threadPool.initialize();
46         DirectSchedulerFactory.getInstance().createScheduler(
47                 "MyScheduler", "Instance1", threadPool,
48                 new RAMJobStore(), Collections.singletonMap("TestPlugin", testPlugin),
49                 null, -1, 0, 0);
50         
51         Scheduler scheduler = DirectSchedulerFactory.getInstance().getScheduler("MyScheduler");
52         scheduler.start();
53         scheduler.shutdown();
54         
55         assertEquals("TestPlugin|MyScheduler|start|shutdown", result.toString());
56     }
57 }
58
Popular Tags