1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.server.endpoint.adapter.method;
18  
19  import javax.xml.transform.Source;
20  import javax.xml.transform.dom.DOMSource;
21  import javax.xml.transform.sax.SAXSource;
22  import javax.xml.transform.stax.StAXSource;
23  import javax.xml.transform.stream.StreamSource;
24  
25  import org.springframework.core.MethodParameter;
26  import org.springframework.ws.server.endpoint.annotation.RequestPayload;
27  import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
28  import org.springframework.xml.transform.StringSource;
29  
30  /** @author Arjen Poutsma */
31  public class SourcePayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTestCase {
32  
33      @Override
34      protected AbstractPayloadSourceMethodProcessor createProcessor() {
35          return new SourcePayloadMethodProcessor();
36      }
37  
38      @Override
39      protected MethodParameter[] createSupportedParameters() throws NoSuchMethodException {
40          return new MethodParameter[]{new MethodParameter(getClass().getMethod("source", Source.class), 0),
41                  new MethodParameter(getClass().getMethod("dom", DOMSource.class), 0),
42                  new MethodParameter(getClass().getMethod("sax", SAXSource.class), 0),
43                  new MethodParameter(getClass().getMethod("stream", StreamSource.class), 0),
44                  new MethodParameter(getClass().getMethod("stax", StAXSource.class), 0)};
45      }
46  
47      @Override
48      protected MethodParameter[] createSupportedReturnTypes() throws NoSuchMethodException {
49          return new MethodParameter[]{new MethodParameter(getClass().getMethod("source", Source.class), -1),
50                  new MethodParameter(getClass().getMethod("dom", DOMSource.class), -1),
51                  new MethodParameter(getClass().getMethod("sax", SAXSource.class), -1),
52                  new MethodParameter(getClass().getMethod("stream", StreamSource.class), -1),
53          new MethodParameter(getClass().getMethod("stax", StAXSource.class), -1)};
54      }
55  
56      @Override
57      protected Object getReturnValue(MethodParameter returnType) throws Exception {
58          return new StringSource(XML);
59      }
60  
61      @ResponsePayload
62      public Source source(@RequestPayload Source source) {
63          return source;
64      }
65  
66      @ResponsePayload
67      public DOMSource dom(@RequestPayload DOMSource source) {
68          return source;
69      }
70  
71      @ResponsePayload
72      public SAXSource sax(@RequestPayload SAXSource source) {
73          return source;
74      }
75  
76      @ResponsePayload
77      public StreamSource stream(@RequestPayload StreamSource source) {
78          return source;
79      }
80  
81      @ResponsePayload
82      public StAXSource stax(@RequestPayload StAXSource source) {
83          return source;
84      }
85  }