001: /*
002: * Copyright 2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.server.endpoint.mapping;
018:
019: import junit.framework.TestCase;
020: import org.easymock.MockControl;
021: import org.springframework.context.support.StaticApplicationContext;
022: import org.springframework.ws.context.MessageContext;
023: import org.springframework.ws.server.EndpointInterceptor;
024: import org.springframework.ws.server.EndpointInvocationChain;
025: import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter;
026:
027: public class EndpointMappingTest extends TestCase {
028:
029: private MessageContext mockContext;
030:
031: private MockControl contextControl;
032:
033: protected void setUp() throws Exception {
034: contextControl = MockControl
035: .createControl(MessageContext.class);
036: mockContext = (MessageContext) contextControl.getMock();
037: }
038:
039: public void testDefaultEndpoint() throws Exception {
040: Object defaultEndpoint = new Object();
041: AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
042: protected Object getEndpointInternal(
043: MessageContext givenRequest) throws Exception {
044: assertEquals("Invalid request passed", mockContext,
045: givenRequest);
046: return null;
047: }
048: };
049: mapping.setDefaultEndpoint(defaultEndpoint);
050: contextControl.replay();
051:
052: EndpointInvocationChain result = mapping
053: .getEndpoint(mockContext);
054: assertNotNull("No EndpointInvocatioChain returned", result);
055: assertEquals("Default Endpoint not returned", defaultEndpoint,
056: result.getEndpoint());
057: contextControl.verify();
058: }
059:
060: public void testEndpoint() throws Exception {
061: final Object endpoint = new Object();
062: AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
063: protected Object getEndpointInternal(
064: MessageContext givenRequest) throws Exception {
065: assertEquals("Invalid request passed", mockContext,
066: givenRequest);
067: return endpoint;
068: }
069: };
070: contextControl.replay();
071:
072: EndpointInvocationChain result = mapping
073: .getEndpoint(mockContext);
074: assertNotNull("No EndpointInvocatioChain returned", result);
075: assertEquals("Unexpected Endpoint returned", endpoint, result
076: .getEndpoint());
077: contextControl.verify();
078: }
079:
080: public void testEndpointInterceptors() throws Exception {
081: final Object endpoint = new Object();
082: EndpointInterceptor interceptor = new EndpointInterceptorAdapter();
083: AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
084: protected Object getEndpointInternal(
085: MessageContext givenRequest) throws Exception {
086: assertEquals("Invalid request passed", mockContext,
087: givenRequest);
088: return endpoint;
089: }
090: };
091: contextControl.replay();
092: mapping
093: .setInterceptors(new EndpointInterceptor[] { interceptor });
094: EndpointInvocationChain result = mapping
095: .getEndpoint(mockContext);
096: assertEquals(
097: "Unexpected amount of EndpointInterceptors returned",
098: 1, result.getInterceptors().length);
099: assertEquals("Unexpected EndpointInterceptor returned",
100: interceptor, result.getInterceptors()[0]);
101: contextControl.verify();
102: }
103:
104: public void testEndpointBeanName() throws Exception {
105: StaticApplicationContext applicationContext = new StaticApplicationContext();
106: applicationContext.registerSingleton("endpoint", Object.class);
107:
108: AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
109:
110: protected Object getEndpointInternal(MessageContext message)
111: throws Exception {
112: assertEquals("Invalid request", mockContext, message);
113: return "endpoint";
114: }
115: };
116: mapping.setApplicationContext(applicationContext);
117: contextControl.replay();
118:
119: EndpointInvocationChain result = mapping
120: .getEndpoint(mockContext);
121: assertNotNull("No endpoint returned", result);
122: contextControl.verify();
123: }
124:
125: public void testEndpointInvalidBeanName() throws Exception {
126: StaticApplicationContext applicationContext = new StaticApplicationContext();
127: applicationContext.registerSingleton("endpoint", Object.class);
128:
129: AbstractEndpointMapping mapping = new AbstractEndpointMapping() {
130:
131: protected Object getEndpointInternal(MessageContext message)
132: throws Exception {
133: assertEquals("Invalid request", mockContext, message);
134: return "noSuchBean";
135: }
136: };
137: mapping.setApplicationContext(applicationContext);
138: contextControl.replay();
139:
140: EndpointInvocationChain result = mapping
141: .getEndpoint(mockContext);
142:
143: assertNull("No endpoint returned", result);
144: contextControl.verify();
145: }
146:
147: }
|