01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.bpmscript.jbi.tasklist;
18:
19: import java.util.List;
20: import java.util.Properties;
21:
22: import junit.framework.TestCase;
23:
24: import org.apache.activemq.ActiveMQConnectionFactory;
25: import org.apache.activemq.xbean.BrokerFactoryBean;
26: import org.apache.log4j.PropertyConfigurator;
27: import org.bpmscript.IPagedResult;
28: import org.bpmscript.Query;
29: import org.bpmscript.jms.JmsTemplate;
30: import org.springframework.core.io.ClassPathResource;
31:
32: public class JmsTaskListStoreTest extends TestCase {
33:
34: protected void setUp() throws Exception {
35: super .setUp();
36: }
37:
38: protected void tearDown() throws Exception {
39: super .tearDown();
40: }
41:
42: public void testSomething() throws Exception {
43: Properties properties = new Properties();
44: properties.put("log4j.rootCategory", "INFO, stdout");
45: properties.put("log4j.appender.stdout",
46: "org.apache.log4j.ConsoleAppender");
47: properties.put("log4j.appender.stdout.layout",
48: "org.apache.log4j.PatternLayout");
49: PropertyConfigurator.configure(properties);
50: BrokerFactoryBean bean = new BrokerFactoryBean();
51: bean.setConfig(new ClassPathResource("inmemoryactivemq.xml"));
52: bean.afterPropertiesSet();
53:
54: final JmsTaskListStore taskListStore = new JmsTaskListStore();
55: JmsTemplate jmsTemplate = new JmsTemplate(
56: new ActiveMQConnectionFactory());
57: jmsTemplate.afterPropertiesSet();
58: taskListStore.setTemplate(jmsTemplate);
59: taskListStore
60: .setQueueName("org.bpmscript.jbi.tasklist.JmsTaskListStore");
61: taskListStore.afterPropertiesSet();
62:
63: try {
64: String taskId = taskListStore.createTask(null,
65: new TaskRequest());
66: ITask task = taskListStore.getTask(taskId);
67: assertNotNull(task);
68: assertEquals(TaskState.OPEN.name(), task.getState());
69: IPagedResult<ITask> tasks = taskListStore
70: .getTasks(Query.ALL);
71: assertEquals(1, tasks.getTotalResults());
72: List<ITask> results = tasks.getResults();
73: assertNotNull(results);
74: assertEquals(1, results.size());
75: ITask firstTask = results.get(0);
76: assertNotNull(firstTask);
77: taskListStore.closeTask(firstTask.getId());
78: task = taskListStore.getTask(taskId);
79: assertEquals(TaskState.CLOSED.name(), task.getState());
80: } finally {
81: List<ITask> tasks = taskListStore.clearTasks();
82: for (ITask task : tasks) {
83: System.out
84: .println(task.getId() + " " + task.getState());
85: }
86: }
87:
88: jmsTemplate.destroy();
89: bean.destroy();
90: }
91:
92: }
|