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.apache.servicemix.expression;
18:
19: import org.apache.servicemix.client.DefaultNamespaceContext;
20: import org.apache.xalan.extensions.XPathFunctionResolverImpl;
21:
22: /**
23: * @version $Revision: 564607 $
24: */
25: public class JAXPXPathExpressionTest extends XPathExpressionTest {
26:
27: /**
28: * Note that this test only works on Java 5
29: *
30: * @throws Exception
31: */
32: public void testXPathUsingJAXP() throws Exception {
33: boolean test = false;
34:
35: try {
36: Class
37: .forName("java.lang.annotation.AnnotationTypeMismatchException");
38: test = true;
39: } catch (ClassNotFoundException doNothing) {
40: // Expected if not java 5
41: }
42:
43: if (test) {
44: assertExpression(new JAXPStringXPathExpression(
45: "/foo/bar/@xyz"), "cheese",
46: "<foo><bar xyz='cheese'/></foo>");
47: assertExpression(new JAXPStringXPathExpression("$name"),
48: "James", "<foo><bar xyz='cheese'/></foo>");
49: }
50: }
51:
52: public void testUsingJavaExtensions() throws Exception {
53: JAXPStringXPathExpression exp = new JAXPStringXPathExpression();
54: exp
55: .setXPath("java:org.apache.servicemix.expression.JAXPXPathExpressionTest.func(string(/header/value))");
56: DefaultNamespaceContext namespaceContext = new DefaultNamespaceContext();
57: namespaceContext
58: .add("java", "http://xml.apache.org/xalan/java");
59: exp.setNamespaceContext(namespaceContext);
60: exp.setFunctionResolver(new XPathFunctionResolverImpl());
61: assertExpression(exp, "modified12",
62: "<header><value>12</value></header>");
63: }
64:
65: public static String func(String s) {
66: return "modified" + s;
67: }
68:
69: }
|