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.synapse.mediators.transform;
21:
22: import junit.framework.TestCase;
23: import org.apache.synapse.MessageContext;
24: import org.apache.synapse.SynapseConstants;
25: import org.apache.synapse.mediators.TestUtils;
26: import org.apache.synapse.util.xpath.SynapseXPath;
27:
28: import javax.xml.namespace.QName;
29:
30: public class HeaderMediatorTest extends TestCase {
31:
32: private static final String TEST_HEADER = "http://server/path";
33:
34: public void testSimpleHeaderSetAndRemove() throws Exception {
35:
36: HeaderMediator headerMediator = new HeaderMediator();
37: headerMediator.setQName(new QName(SynapseConstants.HEADER_TO));
38: headerMediator.setValue(TEST_HEADER);
39:
40: // invoke transformation, with static enveope
41: MessageContext synCtx = TestUtils.getTestContext("<empty/>");
42: headerMediator.mediate(synCtx);
43:
44: assertTrue(TEST_HEADER.equals(synCtx.getTo().getAddress()));
45:
46: // set the header mediator as a remove-header
47: headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
48: headerMediator.mediate(synCtx);
49:
50: assertTrue(synCtx.getTo() == null);
51: }
52:
53: public void testSimpleHeaderXPathSetAndRemove() throws Exception {
54:
55: HeaderMediator headerMediator = new HeaderMediator();
56: headerMediator.setQName(new QName(SynapseConstants.HEADER_TO));
57: headerMediator.setExpression(new SynapseXPath(
58: "concat('http://','server','/path')"));
59:
60: // invoke transformation, with static enveope
61: MessageContext synCtx = TestUtils.getTestContext("<empty/>");
62: headerMediator.mediate(synCtx);
63:
64: assertTrue(TEST_HEADER.equals(synCtx.getTo().getAddress()));
65:
66: // set the header mediator as a remove-header
67: headerMediator.setAction(HeaderMediator.ACTION_REMOVE);
68: headerMediator.mediate(synCtx);
69:
70: assertTrue(synCtx.getTo() == null);
71: }
72:
73: }
|