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.endpoint;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.apache.cxf.Bus;
023: import org.apache.cxf.ws.addressing.EndpointReferenceType;
024: import org.easymock.classextension.EasyMock;
025: import org.easymock.classextension.IMocksControl;
026:
027: import org.junit.After;
028: import org.junit.Assert;
029: import org.junit.Before;
030: import org.junit.Test;
031:
032: public class EndpointResolverRegistryImplTest extends Assert {
033:
034: private EndpointResolverRegistryImpl registry;
035: private EndpointResolver resolver1;
036: private EndpointResolver resolver2;
037: private EndpointReferenceType logical;
038: private EndpointReferenceType physical;
039: private EndpointReferenceType fresh;
040: private IMocksControl control;
041: private QName serviceName;
042:
043: @Before
044: public void setUp() {
045: registry = new EndpointResolverRegistryImpl();
046: control = EasyMock.createNiceControl();
047: resolver1 = control.createMock(EndpointResolver.class);
048: resolver2 = control.createMock(EndpointResolver.class);
049: logical = control.createMock(EndpointReferenceType.class);
050: physical = control.createMock(EndpointReferenceType.class);
051: fresh = control.createMock(EndpointReferenceType.class);
052: serviceName = new QName("namespace", "local");
053: }
054:
055: @After
056: public void tearDown() {
057: resolver1 = null;
058: resolver2 = null;
059: logical = null;
060: physical = null;
061: serviceName = null;
062: }
063:
064: @Test
065: public void testInit() {
066: assertNull("unexpected resolvers list", registry.getResolvers());
067: Bus bus = control.createMock(Bus.class);
068: registry.setBus(bus);
069: bus.setExtension(registry, EndpointResolverRegistry.class);
070: control.replay();
071:
072: registry.init();
073:
074: assertNotNull("expected resolvers list", registry
075: .getResolvers());
076: control.verify();
077: }
078:
079: @Test
080: public void testRegister() {
081: registry.init();
082: assertEquals("unexpected resolver count", 0, registry
083: .getResolvers().size());
084:
085: registry.register(resolver1);
086:
087: assertEquals("unexpected resolver count", 1, registry
088: .getResolvers().size());
089: assertTrue("expected resolver to be registered", registry
090: .getResolvers().contains(resolver1));
091:
092: registry.unregister(resolver1);
093:
094: assertEquals("unexpected resolver count", 0, registry
095: .getResolvers().size());
096: assertFalse("expected resolver to be registered", registry
097: .getResolvers().contains(resolver1));
098:
099: registry.register(resolver2);
100: registry.register(resolver1);
101:
102: assertEquals("unexpected resolver count", 2, registry
103: .getResolvers().size());
104: assertTrue("expected resolver to be registered", registry
105: .getResolvers().contains(resolver1));
106: assertTrue("expected resolver to be registered", registry
107: .getResolvers().contains(resolver2));
108:
109: registry.unregister(resolver2);
110:
111: assertEquals("unexpected resolver count", 1, registry
112: .getResolvers().size());
113: assertTrue("expected resolver to be registered", registry
114: .getResolvers().contains(resolver1));
115: assertFalse("expected resolver to be registered", registry
116: .getResolvers().contains(resolver2));
117: }
118:
119: @Test
120: public void testResolve() {
121: registry.init();
122: registry.register(resolver1);
123: registry.register(resolver2);
124: resolver1.resolve(logical);
125: EasyMock.expectLastCall().andReturn(physical);
126: control.replay();
127:
128: EndpointReferenceType resolved = registry.resolve(logical);
129:
130: control.verify();
131: assertSame("unexpected physical EPR", physical, resolved);
132:
133: control.reset();
134: resolver1.resolve(logical);
135: EasyMock.expectLastCall().andReturn(null);
136: resolver2.resolve(logical);
137: EasyMock.expectLastCall().andReturn(physical);
138: control.replay();
139:
140: resolved = registry.resolve(logical);
141:
142: control.verify();
143: assertSame("unexpected physical EPR", physical, resolved);
144:
145: control.reset();
146: resolver1.resolve(logical);
147: EasyMock.expectLastCall().andReturn(null);
148: resolver2.resolve(logical);
149: EasyMock.expectLastCall().andReturn(null);
150: control.replay();
151:
152: resolved = registry.resolve(logical);
153:
154: control.verify();
155: assertNull("unexpected physical EPR", resolved);
156: }
157:
158: @Test
159: public void testRenew() {
160: registry.init();
161: registry.register(resolver1);
162: registry.register(resolver2);
163: resolver1.renew(logical, physical);
164: EasyMock.expectLastCall().andReturn(fresh);
165: control.replay();
166:
167: EndpointReferenceType renewed = registry.renew(logical,
168: physical);
169:
170: control.verify();
171: assertSame("unexpected physical EPR", fresh, renewed);
172:
173: control.reset();
174: resolver1.renew(logical, physical);
175: EasyMock.expectLastCall().andReturn(null);
176: resolver2.renew(logical, physical);
177: EasyMock.expectLastCall().andReturn(physical);
178: control.replay();
179:
180: renewed = registry.renew(logical, physical);
181:
182: control.verify();
183: assertSame("unexpected physical EPR", physical, renewed);
184:
185: control.reset();
186: resolver1.renew(logical, physical);
187: EasyMock.expectLastCall().andReturn(null);
188: resolver2.renew(logical, physical);
189: EasyMock.expectLastCall().andReturn(null);
190: control.replay();
191:
192: renewed = registry.renew(logical, physical);
193:
194: control.verify();
195: assertNull("unexpected physical EPR", renewed);
196: }
197:
198: @Test
199: public void testMintFromServiceName() {
200: registry.init();
201: registry.register(resolver1);
202: registry.register(resolver2);
203: resolver1.mint(serviceName);
204: EasyMock.expectLastCall().andReturn(logical);
205: control.replay();
206:
207: EndpointReferenceType minted = registry.mint(serviceName);
208:
209: control.verify();
210: assertSame("unexpected minted EPR", logical, minted);
211:
212: control.reset();
213: resolver1.mint(serviceName);
214: EasyMock.expectLastCall().andReturn(null);
215: resolver2.mint(serviceName);
216: EasyMock.expectLastCall().andReturn(logical);
217: control.replay();
218:
219: minted = registry.mint(serviceName);
220:
221: control.verify();
222: assertSame("unexpected minted EPR", logical, minted);
223:
224: control.reset();
225: resolver1.mint(serviceName);
226: EasyMock.expectLastCall().andReturn(null);
227: resolver2.mint(serviceName);
228: EasyMock.expectLastCall().andReturn(null);
229: control.replay();
230:
231: minted = registry.mint(serviceName);
232:
233: control.verify();
234: assertNull("unexpected minted EPR", minted);
235: }
236:
237: @Test
238: public void testMintFromPhysical() {
239: registry.init();
240: registry.register(resolver1);
241: registry.register(resolver2);
242: resolver1.mint(physical);
243: EasyMock.expectLastCall().andReturn(logical);
244: control.replay();
245:
246: EndpointReferenceType minted = registry.mint(physical);
247:
248: control.verify();
249: assertSame("unexpected minted EPR", logical, minted);
250:
251: control.reset();
252: resolver1.mint(physical);
253: EasyMock.expectLastCall().andReturn(null);
254: resolver2.mint(physical);
255: EasyMock.expectLastCall().andReturn(logical);
256: control.replay();
257:
258: minted = registry.mint(physical);
259:
260: control.verify();
261: assertSame("unexpected minted EPR", logical, minted);
262:
263: control.reset();
264: resolver1.mint(physical);
265: EasyMock.expectLastCall().andReturn(null);
266: resolver2.mint(physical);
267: EasyMock.expectLastCall().andReturn(null);
268: control.replay();
269:
270: minted = registry.mint(physical);
271:
272: control.verify();
273: assertNull("unexpected minted EPR", minted);
274: }
275: }
|