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.factory_pattern;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import javax.xml.ws.Endpoint;
024:
025: import org.apache.cxf.factory_pattern.Number;
026: import org.apache.cxf.factory_pattern.NumberFactory;
027: import org.apache.cxf.factory_pattern.NumberFactoryService;
028: import org.apache.cxf.factory_pattern.NumberService;
029: import org.apache.cxf.jaxws.ServiceImpl;
030: import org.apache.cxf.jaxws.support.ServiceDelegateAccessor;
031: import org.apache.cxf.systest.jms.EmbeddedJMSBrokerLauncher;
032: import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
033: import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
034: import org.apache.cxf.ws.addressing.EndpointReferenceType;
035: import org.junit.BeforeClass;
036: import org.junit.Test;
037:
038: public class MultiplexClientServerTest extends
039: AbstractBusClientServerTestBase {
040:
041: public static class Server extends AbstractBusTestServerBase {
042:
043: protected void run() {
044: Object implementor = new NumberFactoryImpl();
045: Endpoint.publish(NumberFactoryImpl.FACTORY_ADDRESS,
046: implementor);
047: }
048:
049: public static void main(String[] args) {
050: try {
051: Server s = new Server();
052: s.start();
053: } catch (Exception ex) {
054: ex.printStackTrace();
055: System.exit(-1);
056: } finally {
057: System.out.println("done!");
058: }
059: }
060: }
061:
062: @BeforeClass
063: public static void startServers() throws Exception {
064: // requires ws-a support to propagate reference parameters
065: createStaticBus("org/apache/cxf/systest/ws/addressing/cxf.xml");
066: Map<String, String> props = new HashMap<String, String>();
067: if (System.getProperty("activemq.store.dir") != null) {
068: props.put("activemq.store.dir", System
069: .getProperty("activemq.store.dir"));
070: }
071: props.put("java.util.logging.config.file", System
072: .getProperty("java.util.logging.config.file"));
073: assertTrue("server did not launch correctly", launchServer(
074: EmbeddedJMSBrokerLauncher.class, props, null));
075:
076: props.put("cxf.config.file", defaultConfigFileName);
077: assertTrue("server did not launch correctly", launchServer(
078: Server.class, props, null));
079: }
080:
081: @Test
082: public void testWithGetPortExtensionHttp() throws Exception {
083:
084: NumberFactoryService service = new NumberFactoryService();
085: NumberFactory factory = service.getNumberFactoryPort();
086:
087: NumberService numService = new NumberService();
088: ServiceImpl serviceImpl = ServiceDelegateAccessor
089: .get(numService);
090:
091: EndpointReferenceType numberTwoRef = factory.create("20");
092: assertNotNull("reference", numberTwoRef);
093:
094: Number num = (Number) serviceImpl.getPort(numberTwoRef,
095: Number.class);
096: assertTrue("20 is even", num.isEven().isEven());
097:
098: EndpointReferenceType numberTwentyThreeRef = factory
099: .create("23");
100: num = (Number) serviceImpl.getPort(numberTwentyThreeRef,
101: Number.class);
102: assertTrue("23 is not even", !num.isEven().isEven());
103: }
104:
105: @Test
106: public void testWithGetPortExtensionOverJMS() throws Exception {
107:
108: NumberFactoryService service = new NumberFactoryService();
109: NumberFactory factory = service.getNumberFactoryPort();
110:
111: NumberService numService = new NumberService();
112:
113: // use values >= 30 to create JMS eprs - see NumberFactoryImpl.create
114:
115: // verify it is JMS, 999 for JMS will throw a fault
116: EndpointReferenceType ref = factory.create("999");
117: assertNotNull("reference", ref);
118: ServiceImpl serviceImpl = ServiceDelegateAccessor
119: .get(numService);
120: Number num = (Number) serviceImpl.getPort(ref, Number.class);
121: try {
122: num.isEven().isEven();
123: fail("there should be a fault on val 999");
124: } catch (Exception expected) {
125: assertTrue("match on exception message", expected
126: .getMessage().indexOf("999") != -1);
127: }
128:
129: ref = factory.create("37");
130: assertNotNull("reference", ref);
131: num = (Number) serviceImpl.getPort(ref, Number.class);
132: assertTrue("37 is not even", !num.isEven().isEven());
133: }
134: }
|