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: */package org.apache.cxf.binding.http.bare;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22:
23: import javax.xml.namespace.QName;
24:
25: import org.apache.cxf.binding.BindingFactoryManager;
26: import org.apache.cxf.binding.http.AbstractRestTest;
27: import org.apache.cxf.binding.http.HttpBindingFactory;
28: import org.apache.cxf.customer.Customer;
29: import org.apache.cxf.customer.Customers;
30: import org.apache.cxf.customer.bare.CustomerService;
31: import org.apache.cxf.customer.bare.GetCustomer;
32: import org.apache.cxf.customer.bare.GetCustomers;
33: import org.apache.cxf.endpoint.ClientImpl;
34: import org.apache.cxf.endpoint.ServerImpl;
35: import org.apache.cxf.interceptor.LoggingOutInterceptor;
36: import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
37: import org.junit.Test;
38:
39: public class ClientTest extends AbstractRestTest {
40: @Test
41: public void testCreation() throws Exception {
42: BindingFactoryManager bfm = getBus().getExtension(
43: BindingFactoryManager.class);
44: bfm.registerBindingFactory(HttpBindingFactory.HTTP_BINDING_ID,
45: new HttpBindingFactory());
46:
47: JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
48: sf.setBus(getBus());
49: sf.setServiceClass(CustomerService.class);
50: sf.getServiceFactory().setWrapped(false);
51: sf.setAddress("http://localhost:9001/foo/");
52: sf.setServiceBean(new CustomerService());
53: //sf.setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
54:
55: Map<String, Object> props = new HashMap<String, Object>();
56: props.put("contextMatchStrategy", "stem");
57: sf.setProperties(props);
58:
59: ServerImpl svr = (ServerImpl) sf.create();
60:
61: svr.getEndpoint().getOutInterceptors().add(
62: new LoggingOutInterceptor());
63:
64: ClientImpl client = new ClientImpl(getBus(), svr.getEndpoint());
65:
66: Object[] objects = client.invoke(new QName(
67: "http://cxf.apache.org/jra", "getCustomers"),
68: new GetCustomers());
69: assertNotNull(objects);
70:
71: Customers c = (Customers) objects[0];
72: Customer customer = c.getCustomer().iterator().next();
73: assertEquals("Dan Diephouse", customer.getName());
74:
75: GetCustomer getCustomer = new GetCustomer();
76: getCustomer.setId(customer.getId());
77: objects = client.invoke(new QName("http://cxf.apache.org/jra",
78: "getCustomer"), getCustomer);
79:
80: customer = (Customer) objects[0];
81: assertEquals("Dan Diephouse", customer.getName());
82: //
83: // objects = client.invoke(new QName("http://cxf.apache.org/jra", "deleteCustomer"),
84: // customer.getId());
85: // assertTrue(objects == null || objects.length == 0);
86: //
87: svr.stop();
88: }
89:
90: }
|