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:
20: package org.apache.axis2.scripting.convertors;
21:
22: import java.util.Iterator;
23:
24: import junit.framework.TestCase;
25:
26: import org.apache.axiom.om.OMElement;
27: import org.apache.axis2.context.MessageContext;
28: import org.apache.axis2.description.AxisService;
29: import org.apache.axis2.description.AxisServiceGroup;
30: import org.apache.axis2.description.Parameter;
31: import org.apache.axis2.engine.AxisConfiguration;
32: import org.apache.axis2.scripting.ScriptReceiver;
33: import org.apache.axis2.scripting.TestUtils;
34:
35: public class JSOMElementConvertorTest extends TestCase {
36:
37: public static final String XML = "<a><b>petra</b></a>";
38:
39: public void testToAndFromScript() {
40: JSOMElementConvertor convertor = new JSOMElementConvertor();
41: Object o = convertor.toScript(TestUtils.createOMElement(XML));
42: OMElement om = convertor.fromScript(o);
43: assertEquals(XML, om.toString());
44: }
45:
46: public void testFromScript() throws Exception {
47: ScriptReceiver mediator = new ScriptReceiver();
48: MessageContext inMC = TestUtils.createMockMessageContext(XML);
49: AxisService axisServce = new AxisService();
50: axisServce.setParent(new AxisServiceGroup(
51: new AxisConfiguration()));
52: axisServce.addParameter(new Parameter(
53: ScriptReceiver.SCRIPT_ATTR, "foo.js"));
54: axisServce
55: .addParameter(new Parameter(
56: ScriptReceiver.SCRIPT_SRC_PROP,
57: "function invoke(inMC,outMC) { outMC.setPayloadXML(<a><b>petra</b></a>) }"));
58: inMC.setAxisService(axisServce);
59: mediator.invokeBusinessLogic(inMC, inMC);
60: Iterator iterator = inMC.getEnvelope().getChildElements();
61: iterator.next();
62: assertEquals(XML, ((OMElement) iterator.next())
63: .getFirstElement().toString());
64: }
65:
66: }
|