001: package org.apache.axis2.jaxws.description;
002:
003: import java.net.URL;
004: import java.util.HashMap;
005: import java.util.List;
006:
007: import junit.framework.TestCase;
008:
009: import javax.jws.WebService;
010: import javax.wsdl.Definition;
011:
012: import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
013: import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
014: import org.apache.axis2.jaxws.description.builder.ParameterDescriptionComposite;
015: import org.apache.axis2.jaxws.description.builder.WebServiceAnnot;
016:
017: /**
018: * These tests are intended to test various aspects of the OperationDescription.
019: */
020:
021: public class OperationDescriptionTests extends TestCase {
022:
023: /**
024: * This test will confirm that the getBindingInputNamespace and getBindingOutputNamespace
025: * methods of the OperationDescription function correctly.
026: *
027: */
028:
029: public void testBindingNamespace() {
030: String wsdlRelativeLocation = "test-resources/wsdl/";
031: String wsdlFileName = "BindingNamespace.wsdl";
032: String targetNamespace = "http://nonanonymous.complextype.test.org";
033: String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
034:
035: // Build up a DBC, including the WSDL Definition and the annotation information for
036: // the impl class.
037: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
038:
039: URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
040: Definition wsdlDefn = DescriptionTestUtils
041: .createWSDLDefinition(wsdlURL);
042: assertNotNull(wsdlDefn);
043:
044: WebServiceAnnot webServiceAnnot = WebServiceAnnot
045: .createWebServiceAnnotImpl();
046: assertNotNull(webServiceAnnot);
047: webServiceAnnot.setWsdlLocation(wsdlLocation);
048: webServiceAnnot.setTargetNamespace(targetNamespace);
049: webServiceAnnot.setServiceName("EchoMessageService");
050: webServiceAnnot.setPortName("EchoMessagePort");
051:
052: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
053: mdc.setMethodName("echoMessage");
054: mdc.setReturnType("java.lang.String");
055:
056: ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
057: pdc1.setParameterType("java.lang.String");
058:
059: mdc.addParameterDescriptionComposite(pdc1);
060:
061: dbc.addMethodDescriptionComposite(mdc);
062: dbc.setWebServiceAnnot(webServiceAnnot);
063: dbc.setClassName(BindingNSImpl.class.getName());
064: dbc.setWsdlDefinition(wsdlDefn);
065: dbc.setwsdlURL(wsdlURL);
066:
067: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
068: dbcMap.put(dbc.getClassName(), dbc);
069: List<ServiceDescription> serviceDescList = DescriptionFactory
070: .createServiceDescriptionFromDBCMap(dbcMap);
071: assertEquals(1, serviceDescList.size());
072: ServiceDescription sd = serviceDescList.get(0);
073: assertNotNull(sd);
074:
075: EndpointDescription[] edArray = sd.getEndpointDescriptions();
076: assertNotNull(edArray);
077: assertEquals(1, edArray.length);
078: EndpointDescription ed = edArray[0];
079: assertNotNull(ed);
080:
081: EndpointInterfaceDescription eid = ed
082: .getEndpointInterfaceDescription();
083: assertNotNull(eid);
084:
085: OperationDescription[] odArray = eid.getOperations();
086: assertNotNull(odArray);
087: assertEquals(1, odArray.length);
088: OperationDescription od = odArray[0];
089: assertNotNull(od);
090: assertEquals("http://org.apache.binding.ns", od
091: .getBindingInputNamespace());
092: assertEquals("http://org.apache.binding.ns", od
093: .getBindingOutputNamespace());
094:
095: }
096:
097: public void testBindingNamespaceDefaults() {
098: String wsdlRelativeLocation = "test-resources/wsdl/";
099: String wsdlFileName = "BindingNamespaceDefaults.wsdl";
100: String targetNamespace = "http://nonanonymous.complextype.test.org";
101: String wsdlLocation = wsdlRelativeLocation + wsdlFileName;
102:
103: // Build up a DBC, including the WSDL Definition and the annotation information for
104: // the impl class.
105: DescriptionBuilderComposite dbc = new DescriptionBuilderComposite();
106:
107: URL wsdlURL = DescriptionTestUtils.getWSDLURL(wsdlFileName);
108: Definition wsdlDefn = DescriptionTestUtils
109: .createWSDLDefinition(wsdlURL);
110: assertNotNull(wsdlDefn);
111:
112: WebServiceAnnot webServiceAnnot = WebServiceAnnot
113: .createWebServiceAnnotImpl();
114: assertNotNull(webServiceAnnot);
115: webServiceAnnot.setWsdlLocation(wsdlLocation);
116: webServiceAnnot.setTargetNamespace(targetNamespace);
117: webServiceAnnot.setServiceName("EchoMessageService");
118: webServiceAnnot.setPortName("EchoMessagePort");
119:
120: MethodDescriptionComposite mdc = new MethodDescriptionComposite();
121: mdc.setMethodName("echoMessage");
122: mdc.setReturnType("java.lang.String");
123:
124: ParameterDescriptionComposite pdc1 = new ParameterDescriptionComposite();
125: pdc1.setParameterType("java.lang.String");
126:
127: mdc.addParameterDescriptionComposite(pdc1);
128:
129: dbc.addMethodDescriptionComposite(mdc);
130: dbc.setWebServiceAnnot(webServiceAnnot);
131: dbc.setClassName(BindingNSImpl.class.getName());
132: dbc.setWsdlDefinition(wsdlDefn);
133: dbc.setwsdlURL(wsdlURL);
134: HashMap<String, DescriptionBuilderComposite> dbcMap = new HashMap<String, DescriptionBuilderComposite>();
135: dbcMap.put(dbc.getClassName(), dbc);
136: List<ServiceDescription> serviceDescList = DescriptionFactory
137: .createServiceDescriptionFromDBCMap(dbcMap);
138: assertEquals(1, serviceDescList.size());
139: ServiceDescription sd = serviceDescList.get(0);
140: assertNotNull(sd);
141:
142: EndpointDescription[] edArray = sd.getEndpointDescriptions();
143: assertNotNull(edArray);
144: assertEquals(1, edArray.length);
145: EndpointDescription ed = edArray[0];
146: assertNotNull(ed);
147:
148: EndpointInterfaceDescription eid = ed
149: .getEndpointInterfaceDescription();
150: assertNotNull(eid);
151:
152: OperationDescription[] odArray = eid.getOperations();
153: assertNotNull(odArray);
154: assertEquals(1, odArray.length);
155: OperationDescription od = odArray[0];
156: assertNotNull(od);
157: assertEquals("http://nonanonymous.complextype.test.org", od
158: .getBindingInputNamespace());
159: assertEquals("http://nonanonymous.complextype.test.org", od
160: .getBindingOutputNamespace());
161:
162: }
163:
164: @WebService(serviceName="EchoMessageService",portName="EchoMessagePort",targetNamespace="http://nonanonymous.complextype.test.org",wsdlLocation="test-resources/wsdl/BindingNamespace.wsdl")
165: public class BindingNSImpl {
166: public String echoMessage(String arg) {
167: return arg;
168: }
169: }
170:
171: @WebService(serviceName="EchoMessageService",portName="EchoMessagePort",targetNamespace="http://nonanonymous.complextype.test.org",wsdlLocation="test-resources/wsdl/BindingNamespaceDefaults.wsdl")
172: public class BindingNSDefaultsImpl {
173: public String echoMessage(String arg) {
174: return arg;
175: }
176: }
177:
178: }
|