001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.transport.http.util;
021:
022: import junit.framework.TestCase;
023: import org.apache.axiom.om.OMAbstractFactory;
024: import org.apache.axiom.om.OMElement;
025: import org.apache.axiom.soap.SOAPEnvelope;
026: import org.apache.axiom.soap.SOAPFactory;
027: import org.apache.axis2.AxisFault;
028: import org.apache.axis2.context.MessageContext;
029: import org.apache.axis2.description.WSDL2Constants;
030:
031: import java.net.MalformedURLException;
032: import java.net.URL;
033:
034: public class URLTemplatingUtilTest extends TestCase {
035:
036: private MessageContext messageContext;
037:
038: protected void setUp() throws Exception {
039: messageContext = new MessageContext();
040:
041: SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();
042: SOAPEnvelope defaultEnvelope = soapFactory.getDefaultEnvelope();
043:
044: messageContext.setEnvelope(defaultEnvelope);
045:
046: OMElement bodyFirstElement = soapFactory.createOMElement(
047: "TestOperation", null);
048: defaultEnvelope.getBody().addChild(bodyFirstElement);
049:
050: soapFactory
051: .createOMElement("FirstName", null, bodyFirstElement)
052: .setText("Foo");
053: soapFactory.createOMElement("LastName", null, bodyFirstElement)
054: .setText("Bar");
055:
056: }
057:
058: public void testGetTemplatedURL() throws AxisFault,
059: MalformedURLException {
060: URL testURL = new URL("http://locahost:8080/paramOne");
061: messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION,
062: "{FirstName}?test=1&lastName={LastName}");
063: URL modifiedURL = URLTemplatingUtil.getTemplatedURL(testURL,
064: messageContext, true);
065:
066: System.out.println("original = " + testURL);
067: System.out.println("modifiedURL = " + modifiedURL);
068:
069: String expectedURL = "http://locahost:8080/paramOne/Foo?test=1&lastName=Bar";
070: assertEquals(modifiedURL.toString(), expectedURL);
071:
072: }
073:
074: public void testAppendParametersToURL()
075: throws MalformedURLException, AxisFault {
076: URL testURL = new URL("http://locahost:8080/paramOne");
077: messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION,
078: null);
079: URL modifiedURL = URLTemplatingUtil.appendQueryParameters(
080: messageContext, testURL);
081:
082: System.out.println("original = " + testURL);
083: System.out.println("modifiedURL = " + modifiedURL);
084:
085: String expectedURL = "http://locahost:8080/paramOne?FirstName=Foo&LastName=Bar";
086: assertEquals(modifiedURL.toString(), expectedURL);
087: }
088:
089: public void testQueryParameterSeperator()
090: throws MalformedURLException, AxisFault {
091: URL testURL = new URL("http://locahost:8080/paramOne");
092: messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION,
093: null);
094: messageContext.setProperty(
095: WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,
096: ";");
097: URL modifiedURL = URLTemplatingUtil.appendQueryParameters(
098: messageContext, testURL);
099:
100: System.out.println("original = " + testURL);
101: System.out.println("modifiedURL = " + modifiedURL);
102:
103: String expectedURL = "http://locahost:8080/paramOne?FirstName=Foo;LastName=Bar";
104: assertEquals(modifiedURL.toString(), expectedURL);
105: }
106:
107: public void testIgnoreUncitedFalse() throws MalformedURLException,
108: AxisFault {
109:
110: URL testURL = new URL(
111: "http://locahost:8080/paramOne/Foo?test=1");
112: messageContext.setProperty(
113: WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED, "false");
114: messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION,
115: null);
116: URL modifiedURL = URLTemplatingUtil.appendQueryParameters(
117: messageContext, testURL);
118:
119: System.out.println("original = " + testURL);
120: System.out.println("modifiedURL = " + modifiedURL);
121:
122: String expectedURL = "http://locahost:8080/paramOne/Foo?test=1&FirstName=Foo&LastName=Bar";
123: assertEquals(modifiedURL.toString(), expectedURL);
124:
125: }
126:
127: }
|