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.ws.policy;
019:
020: import java.util.logging.Logger;
021:
022: import javax.xml.ws.Endpoint;
023:
024: import org.apache.cxf.Bus;
025: import org.apache.cxf.BusFactory;
026: import org.apache.cxf.bus.spring.SpringBusFactory;
027: import org.apache.cxf.greeter_control.BasicGreeterService;
028: import org.apache.cxf.greeter_control.Greeter;
029: import org.apache.cxf.greeter_control.PingMeFault;
030: import org.apache.cxf.interceptor.LoggingInInterceptor;
031: import org.apache.cxf.interceptor.LoggingOutInterceptor;
032: import org.apache.cxf.systest.ws.util.ConnectionHelper;
033: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
034: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
035: import org.junit.BeforeClass;
036: import org.junit.Test;
037:
038: /**
039: * Tests the use of the WS-Policy Framework to automatically engage WS-Addressing and
040: * WS-RM in response to Policies defined for the endpoint via an external policy attachment.
041: */
042: public class AddressingPolicyTest extends
043: AbstractBusClientServerTestBase {
044:
045: private static final Logger LOG = Logger
046: .getLogger(AddressingPolicyTest.class.getName());
047:
048: public static class Server extends AbstractBusTestServerBase {
049:
050: protected void run() {
051: SpringBusFactory bf = new SpringBusFactory();
052: Bus bus = bf
053: .createBus("org/apache/cxf/systest/ws/policy/addr.xml");
054: BusFactory.setDefaultBus(bus);
055: LoggingInInterceptor in = new LoggingInInterceptor();
056: bus.getInInterceptors().add(in);
057: bus.getInFaultInterceptors().add(in);
058: LoggingOutInterceptor out = new LoggingOutInterceptor();
059: bus.getOutInterceptors().add(out);
060: bus.getOutFaultInterceptors().add(out);
061:
062: GreeterImpl implementor = new GreeterImpl();
063: String address = "http://localhost:9020/SoapContext/GreeterPort";
064: Endpoint.publish(address, implementor);
065: LOG.info("Published greeter endpoint.");
066: }
067:
068: public static void main(String[] args) {
069: try {
070: Server s = new Server();
071: s.start();
072: } catch (Exception ex) {
073: ex.printStackTrace();
074: System.exit(-1);
075: } finally {
076: System.out.println("done!");
077: }
078: }
079: }
080:
081: @BeforeClass
082: public static void startServers() throws Exception {
083: assertTrue("server did not launch correctly",
084: launchServer(Server.class));
085: }
086:
087: @Test
088: public void testUsingAddressing() throws Exception {
089: SpringBusFactory bf = new SpringBusFactory();
090: bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr.xml");
091: BusFactory.setDefaultBus(bus);
092: LoggingInInterceptor in = new LoggingInInterceptor();
093: bus.getInInterceptors().add(in);
094: bus.getInFaultInterceptors().add(in);
095: LoggingOutInterceptor out = new LoggingOutInterceptor();
096: bus.getOutInterceptors().add(out);
097: bus.getOutFaultInterceptors().add(out);
098:
099: BasicGreeterService gs = new BasicGreeterService();
100: final Greeter greeter = gs.getGreeterPort();
101: LOG.fine("Created greeter client.");
102: ConnectionHelper.setKeepAliveConnection(greeter, true);
103:
104: // oneway
105:
106: greeter.greetMeOneWay("CXF");
107:
108: // two-way
109:
110: assertEquals("CXF", greeter.greetMe("cxf"));
111:
112: // exception
113:
114: try {
115: greeter.pingMe();
116: } catch (PingMeFault ex) {
117: fail("First invocation should have succeeded.");
118: }
119:
120: try {
121: greeter.pingMe();
122: fail("Expected PingMeFault not thrown.");
123: } catch (PingMeFault ex) {
124: assertEquals(2, (int) ex.getFaultInfo().getMajor());
125: assertEquals(1, (int) ex.getFaultInfo().getMinor());
126: }
127: }
128: }
|