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.bus;
019:
020: import org.apache.cxf.Bus;
021: import org.apache.cxf.BusException;
022: import org.apache.cxf.binding.BindingFactoryManager;
023: import org.apache.cxf.bus.spring.SpringBusFactory;
024: import org.apache.cxf.buslifecycle.BusLifeCycleManager;
025: import org.apache.cxf.endpoint.ServerRegistry;
026: import org.apache.cxf.management.InstrumentationManager;
027: import org.apache.cxf.phase.PhaseManager;
028: import org.apache.cxf.transport.ConduitInitiatorManager;
029: import org.apache.cxf.transport.DestinationFactoryManager;
030: import org.apache.cxf.workqueue.WorkQueueManager;
031: import org.apache.cxf.wsdl.WSDLManager;
032: import org.junit.Assert;
033: import org.junit.Test;
034: import org.springframework.context.support.ClassPathXmlApplicationContext;
035:
036: public class SpringBusFactoryTest extends Assert {
037:
038: @Test
039: public void testKnownExtensions() throws BusException {
040: Bus bus = new SpringBusFactory().createBus();
041: assertNotNull(bus);
042:
043: checkBindingExtensions(bus);
044:
045: DestinationFactoryManager dfm = bus
046: .getExtension(DestinationFactoryManager.class);
047: assertNotNull("No destination factory manager", dfm);
048: ConduitInitiatorManager cim = bus
049: .getExtension(ConduitInitiatorManager.class);
050: assertNotNull("No conduit initiator manager", cim);
051:
052: checkTransportFactories(bus);
053: checkOtherCoreExtensions(bus);
054: //you should include instumentation extenstion to get the instrumentation manager
055: assertNotNull("No instrumentation manager", bus
056: .getExtension(InstrumentationManager.class));
057: }
058:
059: @Test
060: public void testLoadBusWithServletApplicationContext()
061: throws BusException {
062: ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
063: new String[] { "/org/apache/cxf/systest/bus/servlet.xml" });
064: Bus bus = new SpringBusFactory(ctx).createBus();
065: checkBindingExtensions(bus);
066: checkHTTPTransportFactories(bus);
067: checkOtherCoreExtensions(bus);
068: }
069:
070: private void checkBindingExtensions(Bus bus) throws BusException {
071: BindingFactoryManager bfm = bus
072: .getExtension(BindingFactoryManager.class);
073: assertNotNull("No binding factory manager", bfm);
074: assertNotNull(
075: "binding factory not available",
076: bfm
077: .getBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/"));
078: try {
079: bfm.getBindingFactory("http://cxf.apache.org/unknown");
080: } catch (BusException ex) {
081: // expected
082: }
083: }
084:
085: private void checkOtherCoreExtensions(Bus bus) throws BusException {
086: assertNotNull("No wsdl manager", bus
087: .getExtension(WSDLManager.class));
088: assertNotNull("No phase manager", bus
089: .getExtension(PhaseManager.class));
090: assertNotNull("No workqueue manager", bus
091: .getExtension(WorkQueueManager.class));
092: assertNotNull("No lifecycle manager", bus
093: .getExtension(BusLifeCycleManager.class));
094: assertNotNull("No service registry", bus
095: .getExtension(ServerRegistry.class));
096:
097: }
098:
099: private void checkHTTPTransportFactories(Bus bus)
100: throws BusException {
101: ConduitInitiatorManager cim = bus
102: .getExtension(ConduitInitiatorManager.class);
103: assertNotNull("No conduit initiator manager", cim);
104:
105: assertNotNull(
106: "conduit initiator not available",
107: cim
108: .getConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/http"));
109: assertNotNull(
110: "conduit initiator not available",
111: cim
112: .getConduitInitiator("http://schemas.xmlsoap.org/wsdl/http/"));
113: assertNotNull(
114: "conduit initiator not available",
115: cim
116: .getConduitInitiator("http://cxf.apache.org/transports/http/configuration"));
117:
118: DestinationFactoryManager dfm = bus
119: .getExtension(DestinationFactoryManager.class);
120: assertNotNull("No destination factory manager", dfm);
121:
122: assertNotNull(
123: "destination factory not available",
124: dfm
125: .getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/"));
126: assertNotNull(
127: "destination factory not available",
128: dfm
129: .getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/http"));
130: assertNotNull(
131: "destination factory not available",
132: dfm
133: .getDestinationFactory("http://schemas.xmlsoap.org/wsdl/http/"));
134: assertNotNull(
135: "destination factory not available",
136: dfm
137: .getDestinationFactory("http://cxf.apache.org/transports/http/configuration"));
138: }
139:
140: private void checkTransportFactories(Bus bus) throws BusException {
141: DestinationFactoryManager dfm = bus
142: .getExtension(DestinationFactoryManager.class);
143: assertNotNull("No destination factory manager", dfm);
144: ConduitInitiatorManager cim = bus
145: .getExtension(ConduitInitiatorManager.class);
146: assertNotNull("No conduit initiator manager", cim);
147:
148: try {
149: cim.getConduitInitiator("http://cxf.apache.org/unknown");
150: } catch (BusException ex) {
151: // expected
152: }
153:
154: try {
155: dfm.getDestinationFactory("http://cxf.apache.org/unknown");
156: } catch (BusException ex) {
157: // expected
158: }
159:
160: // not sure that we need this - Dan Diephouse
161: //assertNotNull("conduit initiator not available",
162: //cim.getConduitInitiator("http://schemas.xmlsoap.org/wsdl/soap/"));
163:
164: assertNotNull(
165: "conduit initiator not available",
166: cim
167: .getConduitInitiator("http://cxf.apache.org/bindings/xformat"));
168: assertNotNull(
169: "conduit initiator not available",
170: cim
171: .getConduitInitiator("http://cxf.apache.org/transports/jms"));
172: assertNotNull(
173: "conduit initiator not available",
174: cim
175: .getConduitInitiator("http://cxf.apache.org/transports/jms/configuration"));
176:
177: assertNotNull(
178: "destination factory not available",
179: dfm
180: .getDestinationFactory("http://cxf.apache.org/bindings/xformat"));
181: assertNotNull(
182: "destination factory not available",
183: dfm
184: .getDestinationFactory("http://cxf.apache.org/transports/jms"));
185: assertNotNull(
186: "destination factory not available",
187: dfm
188: .getDestinationFactory("http://cxf.apache.org/transports/jms/configuration"));
189:
190: }
191:
192: }
|