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: */package org.apache.cxf.systest.basicDOCBare;
019:
020: import java.lang.annotation.Annotation;
021: import java.lang.reflect.Method;
022: import java.net.URL;
023:
024: import javax.jws.WebMethod;
025: import javax.jws.WebParam;
026: import javax.xml.namespace.QName;
027: import javax.xml.ws.Holder;
028:
029: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
030: import org.apache.hello_world_doc_lit_bare.PutLastTradedPricePortType;
031: import org.apache.hello_world_doc_lit_bare.SOAPService;
032: import org.apache.hello_world_doc_lit_bare.types.TradePriceData;
033: import org.junit.BeforeClass;
034: import org.junit.Test;
035:
036: public class DOCBareClientServerTest extends
037: AbstractBusClientServerTestBase {
038:
039: private final QName serviceName = new QName(
040: "http://apache.org/hello_world_doc_lit_bare", "SOAPService");
041: private final QName portName = new QName(
042: "http://apache.org/hello_world_doc_lit_bare", "SoapPort");
043:
044: @BeforeClass
045: public static void startServers() throws Exception {
046: System.setProperty("org.apache.cxf.bus.factory",
047: "org.apache.cxf.bus.CXFBusFactory");
048: assertTrue("server did not launch correctly",
049: launchServer(Server.class));
050: }
051:
052: @Test
053: public void testBasicConnection() throws Exception {
054: URL wsdl = getClass().getResource("/wsdl/doc_lit_bare.wsdl");
055: assertNotNull("WSDL is null", wsdl);
056:
057: SOAPService service = new SOAPService(wsdl, serviceName);
058: assertNotNull("Service is null", service);
059:
060: PutLastTradedPricePortType putLastTradedPrice = service
061: .getPort(portName, PutLastTradedPricePortType.class);
062: String response = putLastTradedPrice.bareNoParam();
063: assertEquals("testResponse", response);
064:
065: TradePriceData priceData = new TradePriceData();
066: priceData.setTickerPrice(1.0f);
067: priceData.setTickerSymbol("CELTIX");
068:
069: Holder<TradePriceData> holder = new Holder<TradePriceData>(
070: priceData);
071:
072: for (int i = 0; i < 5; i++) {
073: putLastTradedPrice.sayHi(holder);
074: assertEquals(4.5f, holder.value.getTickerPrice());
075: assertEquals("APACHE", holder.value.getTickerSymbol());
076: putLastTradedPrice.putLastTradedPrice(priceData);
077: }
078:
079: }
080:
081: @Test
082: public void testAnnotation() throws Exception {
083: Class<PutLastTradedPricePortType> claz = PutLastTradedPricePortType.class;
084: TradePriceData priceData = new TradePriceData();
085: Holder<TradePriceData> holder = new Holder<TradePriceData>(
086: priceData);
087: Method method = claz.getMethod("sayHi", holder.getClass());
088: assertNotNull("Can not find SayHi method in generated class ",
089: method);
090: Annotation ann = method.getAnnotation(WebMethod.class);
091: WebMethod webMethod = (WebMethod) ann;
092: assertEquals(webMethod.operationName(), "SayHi");
093: Annotation[][] paraAnns = method.getParameterAnnotations();
094: for (Annotation[] paraType : paraAnns) {
095: for (Annotation an : paraType) {
096: if (an.annotationType() == WebParam.class) {
097: WebParam webParam = (WebParam) an;
098: assertNotSame("", webParam.targetNamespace());
099: }
100: }
101: }
102: }
103:
104: }
|