001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.bpmscript.jbi.component;
018:
019: import java.util.List;
020: import java.util.Properties;
021:
022: import javax.jbi.messaging.InOut;
023: import javax.jbi.messaging.MessagingException;
024: import javax.jbi.messaging.NormalizedMessage;
025: import javax.xml.namespace.QName;
026:
027: import org.apache.log4j.PropertyConfigurator;
028: import org.apache.servicemix.client.DefaultServiceMixClient;
029: import org.apache.servicemix.tck.SpringTestSupport;
030: import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
031: import org.bpmscript.Query;
032: import org.bpmscript.TimeoutRuntimeException;
033: import org.bpmscript.XStreamMarshaler;
034: import org.bpmscript.jbi.PojoServiceProxyFactoryBean;
035: import org.bpmscript.jbi.tasklist.ComplexType;
036: import org.bpmscript.jbi.tasklist.IAllowableResponse;
037: import org.bpmscript.jbi.tasklist.IRemoteTaskListManager;
038: import org.bpmscript.jbi.tasklist.ITask;
039: import org.bpmscript.jbi.tasklist.SimpleType;
040: import org.bpmscript.jbi.tasklist.TaskRequest;
041: import org.bpmscript.jbi.tasklist.TaskState;
042: import org.springframework.context.support.AbstractXmlApplicationContext;
043:
044: public class TaskListSmokeTest extends SpringTestSupport {
045:
046: public TaskListSmokeTest() {
047: Properties properties = new Properties();
048: properties.put("log4j.rootCategory", "INFO, stdout");
049: properties.put("log4j.appender.stdout",
050: "org.apache.log4j.ConsoleAppender");
051: properties.put("log4j.appender.stdout.layout",
052: "org.apache.log4j.PatternLayout");
053: properties.put(
054: "log4j.appender.stdout.layout.ConversionPattern",
055: "%p [%t] %c{1}.%M(%L) | %m%n");
056: PropertyConfigurator.configure(properties);
057: }
058:
059: public void testTaskList() throws Exception {
060:
061: final DefaultServiceMixClient client = new DefaultServiceMixClient(
062: jbi);
063:
064: final InOut out = client.createInOutExchange(new QName(
065: "http://bpmscript.org/jbi", "taskList"), null, null);
066: final XStreamMarshaler marshaler = new XStreamMarshaler();
067: NormalizedMessage inMessage = out.createMessage();
068: TaskRequest taskRequest = new TaskRequest(
069: "What should I do next?");
070: taskRequest.response("skip", "Please enter the partyId:",
071: SimpleType.INTEGER);
072: taskRequest.response("retry", "Retry");
073: ComplexType complexType = new ComplexType();
074: complexType.setName("person");
075: complexType.field("firstName").string();
076: complexType.field("surname").string();
077:
078: taskRequest.response("panic",
079: "Please enter the person details:", complexType);
080: marshaler.marshal(out, inMessage, taskRequest);
081: out.setInMessage(inMessage);
082:
083: Thread thread = new Thread(new Runnable() {
084:
085: public void run() {
086: try {
087: boolean processed = client.sendSync(out, 30000);
088: if (!processed) {
089: throw new TimeoutRuntimeException();
090: }
091: if (out.getError() != null) {
092: throw out.getError();
093: }
094: System.out.println(marshaler.unmarshal(out, out
095: .getOutMessage()));
096: } catch (MessagingException e) {
097: fail(e.getMessage());
098: } catch (Exception e) {
099: fail(e.getMessage());
100: }
101: }
102: });
103:
104: thread.start();
105:
106: Thread.sleep(1000);
107:
108: PojoServiceProxyFactoryBean bean = new PojoServiceProxyFactoryBean();
109: bean.setClient(client);
110: bean.setInterfaceClass(IRemoteTaskListManager.class);
111: bean.setService(new QName("http://bpmscript.org/jbi",
112: "remoteTaskListManager"));
113: bean.setMarshaler(new XStreamMarshaler());
114: IRemoteTaskListManager manager = (IRemoteTaskListManager) bean
115: .getObject();
116: List<ITask> tasks = manager.getTasks(Query.ALL).getResults();
117: assertNotNull(tasks);
118: System.out.println(tasks.size());
119: for (ITask task : tasks) {
120: System.out.println(task.getId() + ": " + task.getState());
121: if (task.getState().equals(TaskState.OPEN.name())) {
122: List<IAllowableResponse> allowableResponses = task
123: .getTaskRequest().getAllowableResponses();
124: assertNotNull(allowableResponses);
125: assertTrue(allowableResponses.size() > 0);
126: String path = allowableResponses.get(0).getPath();
127: manager
128: .respondToTask(task.getId(), path, "blah",
129: "bob");
130: }
131: }
132:
133: List<ITask> closedTasks = manager.getTasks(Query.ALL)
134: .getResults();
135: for (ITask task : closedTasks) {
136: System.out.println(task.getId() + ": " + task.getState());
137: }
138:
139: }
140:
141: protected AbstractXmlApplicationContext createBeanFactory() {
142: return new ClassPathXmlApplicationContext("/manager/spring.xml");
143: }
144:
145: }
|