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 org.dom4j.Document;
26  import org.dom4j.DocumentHelper;
27  import org.dom4j.Element;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertTrue;
31  
32  public class Dom4jPayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTestCase {
33  
34     @Override
35      protected AbstractPayloadSourceMethodProcessor createProcessor() {
36          return new Dom4jPayloadMethodProcessor();
37      }
38  
39      @Override
40      protected MethodParameter[] createSupportedParameters() throws NoSuchMethodException {
41          return new MethodParameter[]{
42                  new MethodParameter(getClass().getMethod("element", Element.class), 0)};
43      }
44  
45      @Override
46      protected MethodParameter[] createSupportedReturnTypes() throws NoSuchMethodException {
47          return new MethodParameter[]{new MethodParameter(getClass().getMethod("element", Element.class), -1)};
48      }
49  
50      @Override
51      protected void testArgument(Object argument, MethodParameter parameter) {
52          assertTrue("argument not a element", argument instanceof Element);
53          Element element = (Element) argument;
54          assertEquals("Invalid namespace", NAMESPACE_URI, element.getNamespaceURI());
55          assertEquals("Invalid local name", LOCAL_NAME, element.getName());
56      }
57  
58      @Override
59      protected Element getReturnValue(MethodParameter returnType) {
60          Document document = DocumentHelper.createDocument();
61          return document.addElement(LOCAL_NAME, NAMESPACE_URI);
62      }
63  
64      @ResponsePayload
65      public Element element(@RequestPayload Element element) {
66          return element;
67      }
68  
69  }