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.dom;
18  
19  import org.springframework.core.MethodParameter;
20  import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadMethodProcessorTestCase;
21  import org.springframework.ws.server.endpoint.adapter.method.AbstractPayloadSourceMethodProcessor;
22  import org.springframework.ws.server.endpoint.annotation.RequestPayload;
23  import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
24  
25  import nu.xom.Element;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.assertTrue;
29  
30  public class XomPayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTestCase {
31  
32      @Override
33      protected AbstractPayloadSourceMethodProcessor createProcessor() {
34          return new XomPayloadMethodProcessor();
35      }
36  
37      @Override
38      protected MethodParameter[] createSupportedParameters() throws NoSuchMethodException {
39          return new MethodParameter[]{new MethodParameter(getClass().getMethod("element", Element.class), 0)};
40      }
41  
42      @Override
43      protected MethodParameter[] createSupportedReturnTypes() throws NoSuchMethodException {
44          return new MethodParameter[]{new MethodParameter(getClass().getMethod("element", Element.class), -1)};
45      }
46  
47      @Override
48      protected void testArgument(Object argument, MethodParameter parameter) {
49          assertTrue("argument not a element", argument instanceof Element);
50          Element node = (Element) argument;
51          assertEquals("Invalid namespace", NAMESPACE_URI, node.getNamespaceURI());
52          assertEquals("Invalid local name", LOCAL_NAME, node.getLocalName());
53      }
54  
55      @Override
56      protected Element getReturnValue(MethodParameter returnType) {
57          return new Element(LOCAL_NAME, NAMESPACE_URI);
58      }
59  
60      @ResponsePayload
61      public Element element(@RequestPayload Element element) {
62          return element;
63      }
64  }