1 package org.weda.test;
2
3 import java.util.List;
4 import java.util.Map;
5 import org.apache.hivemind.Registry;
6 import org.apache.hivemind.impl.RegistryBuilder;
7 import org.weda.action.ActionContainer;
8 import org.weda.action.ActionDescriptor;
9 import org.weda.action.ActionRegistry;
10 import org.weda.action.ActionState;
11 import org.weda.action.impl.ActionExecutionContextImpl;
12 import tim.test.LogableTestCase;
13
14 /**
15 *
16 * @author Mikhail Titov
17 */
18 public class WedaTestCase extends LogableTestCase{
19 protected static final Registry registry =
20 RegistryBuilder.constructDefaultRegistry();
21
22 public WedaTestCase(String name) throws Exception {
23 super(name);
24 }
25
26 protected Object executeAction(
27 String actionName
28 , ActionContainer actionContainer
29 , Map<String, String> actionParameters)
30 throws Exception
31 {
32 ActionRegistry actionReg =
33 (ActionRegistry)registry.getService(ActionRegistry.class);
34 List<ActionState> states =
35 actionReg.getActionsStates(
36 actionContainer, actionContainer.getClass());
37 ActionDescriptor desc = getDescriptorByName(actionName, states);
38 ActionExecutionContextImpl ctx =
39 new ActionExecutionContextImpl();
40 ctx.setTargetObject(actionContainer);
41 ctx.setActionDescriptor(desc);
42 return actionReg.executeAction(ctx).getActionResult();
43 }
44
45 protected ActionDescriptor getDescriptorByName(
46 String descriptorName, List<ActionState> states)
47 {
48 for (ActionState state: states)
49 if (descriptorName.equals(state.getActionDescriptor().getName()))
50 return state.getActionDescriptor();
51 return null;
52 }
53
54
55 }