001: /*
002: * Copyright 2007 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.adapter;
018:
019: import javax.xml.transform.Source;
020:
021: import junit.framework.TestCase;
022: import org.springframework.ws.MockWebServiceMessage;
023: import org.springframework.ws.MockWebServiceMessageFactory;
024: import org.springframework.ws.WebServiceMessage;
025: import org.springframework.ws.context.DefaultMessageContext;
026: import org.springframework.ws.context.MessageContext;
027: import org.springframework.ws.server.endpoint.MethodEndpoint;
028:
029: public class PayloadMethodEndpointAdapterTest extends TestCase {
030:
031: private PayloadMethodEndpointAdapter adapter;
032:
033: private boolean noResponseInvoked;
034:
035: private boolean responseInvoked;
036:
037: private MessageContext messageContext;
038:
039: protected void setUp() throws Exception {
040: adapter = new PayloadMethodEndpointAdapter();
041: messageContext = new DefaultMessageContext(
042: new MockWebServiceMessageFactory());
043: }
044:
045: public void testSupportedNoResponse() throws NoSuchMethodException {
046: MethodEndpoint methodEndpoint = new MethodEndpoint(this ,
047: "noResponse", new Class[] { Source.class });
048: assertTrue("Method unsupported", adapter
049: .supportsInternal(methodEndpoint));
050: }
051:
052: public void testSupportedResponse() throws NoSuchMethodException {
053: MethodEndpoint methodEndpoint = new MethodEndpoint(this ,
054: "response", new Class[] { Source.class });
055: assertTrue("Method unsupported", adapter
056: .supportsInternal(methodEndpoint));
057: }
058:
059: public void testUnsupportedMethodMultipleParams()
060: throws NoSuchMethodException {
061: assertFalse("Method supported", adapter
062: .supportsInternal(new MethodEndpoint(this ,
063: "unsupportedMultipleParams", new Class[] {
064: Source.class, Source.class })));
065: }
066:
067: public void testUnsupportedMethodWrongReturnType()
068: throws NoSuchMethodException {
069: assertFalse("Method supported", adapter
070: .supportsInternal(new MethodEndpoint(this ,
071: "unsupportedWrongReturnType",
072: new Class[] { Source.class })));
073: }
074:
075: public void testUnsupportedMethodWrongParam()
076: throws NoSuchMethodException {
077: assertFalse("Method supported", adapter
078: .supportsInternal(new MethodEndpoint(this ,
079: "unsupportedWrongParam",
080: new Class[] { String.class })));
081: }
082:
083: public void testNoResponse() throws Exception {
084: MethodEndpoint methodEndpoint = new MethodEndpoint(this ,
085: "noResponse", new Class[] { Source.class });
086: assertFalse("Method invoked", noResponseInvoked);
087: adapter.invoke(messageContext, methodEndpoint);
088: assertTrue("Method not invoked", noResponseInvoked);
089: }
090:
091: public void testResponse() throws Exception {
092: WebServiceMessage request = new MockWebServiceMessage(
093: "<request/>");
094: messageContext = new DefaultMessageContext(request,
095: new MockWebServiceMessageFactory());
096: MethodEndpoint methodEndpoint = new MethodEndpoint(this ,
097: "response", new Class[] { Source.class });
098: assertFalse("Method invoked", responseInvoked);
099: adapter.invoke(messageContext, methodEndpoint);
100: assertTrue("Method not invoked", responseInvoked);
101: }
102:
103: public void noResponse(Source request) {
104: noResponseInvoked = true;
105: }
106:
107: public Source response(Source request) {
108: responseInvoked = true;
109: return request;
110: }
111:
112: public void unsupportedMultipleParams(Source s1, Source s2) {
113: }
114:
115: public Source unsupportedWrongParam(String request) {
116: return null;
117: }
118:
119: public String unsupportedWrongReturnType(Source request) {
120: return null;
121: }
122:
123: }
|