01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.scripting;
20:
21: import java.util.Iterator;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.axiom.om.OMElement;
26: import org.apache.axis2.AxisFault;
27: import org.apache.axis2.context.MessageContext;
28: import org.apache.axis2.description.AxisService;
29: import org.apache.axis2.description.Parameter;
30:
31: public class ScriptReceiverTest extends TestCase {
32:
33: public void testInvokeBusinessLogic() throws AxisFault {
34: ScriptReceiver scriptReceiver = new ScriptReceiver();
35: MessageContext inMC = TestUtils
36: .createMockMessageContext("<a>petra</a>");
37: AxisService axisService = inMC.getAxisService();
38: axisService.addParameter(new Parameter(
39: ScriptReceiver.SCRIPT_ATTR, "foo.js"));
40: axisService.addParameter(new Parameter(
41: ScriptReceiver.SCRIPT_SRC_PROP,
42: "function invoke(inMC,outMC) "
43: + "{outMC.setPayloadXML(<a>petra</a>) }"));
44: inMC.setAxisService(axisService);
45: scriptReceiver.invokeBusinessLogic(inMC, inMC);
46: Iterator iterator = inMC.getEnvelope().getChildElements();
47: iterator.next();
48: assertEquals("<a>petra</a>", ((OMElement) iterator.next())
49: .getFirstElement().toString());
50: }
51:
52: public void testAxisService() throws AxisFault {
53: ScriptReceiver scriptReceiver = new ScriptReceiver();
54: MessageContext inMC = TestUtils
55: .createMockMessageContext("<a>petra</a>");
56: AxisService axisService = inMC.getAxisService();
57: axisService.addParameter(new Parameter(
58: ScriptReceiver.SCRIPT_ATTR, "foo.js"));
59: axisService.addParameter(ScriptReceiver.SCRIPT_SRC_PROP,
60: "var scope = _AxisService.getScope();function invoke(inMC,outMC) "
61: + "{outMC.setPayloadXML(<a>{scope}</a>) }");
62: scriptReceiver.invokeBusinessLogic(inMC, inMC);
63: Iterator iterator = inMC.getEnvelope().getChildElements();
64: iterator.next();
65: assertEquals("<a>request</a>", ((OMElement) iterator.next())
66: .getFirstElement().toString());
67: }
68:
69: }
|