SWS-351 - Arbitrary parameter injection for @Endpoints

This commit is contained in:
Arjen Poutsma
2010-04-28 09:18:08 +00:00
parent 51bd828dc2
commit bd4ef351b0
4 changed files with 179 additions and 1 deletions

View File

@@ -16,12 +16,16 @@
package org.springframework.ws.server.endpoint.adapter.method;
import javax.xml.transform.Source;
import org.springframework.core.MethodParameter;
import org.springframework.ws.context.MessageContext;
import org.springframework.xml.transform.StringResult;
import org.junit.Before;
import org.junit.Test;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -128,6 +132,10 @@ public abstract class AbstractPayloadMethodProcessorTest extends AbstractMethodA
Object returnValue = getReturnValue(supportedReturnType);
processor.handleReturnValue(messageContext, supportedReturnType, returnValue);
assertTrue("No response created", messageContext.hasResponse());
Source responsePayload = messageContext.getResponse().getPayloadSource();
StringResult result = new StringResult();
transform(responsePayload, result);
assertXMLEqual(XML, result.toString());
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.server.endpoint.adapter.method;
import org.springframework.core.MethodParameter;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import nu.xom.Element;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class XomPayloadMethodProcessorTest extends AbstractPayloadMethodProcessorTest {
@Override
protected AbstractPayloadMethodProcessor createProcessor() {
return new XomPayloadMethodProcessor();
}
@Override
protected MethodParameter[] createSupportedParameters() throws NoSuchMethodException {
return new MethodParameter[]{new MethodParameter(getClass().getMethod("element", Element.class), 0)};
}
@Override
protected MethodParameter[] createSupportedReturnTypes() throws NoSuchMethodException {
return new MethodParameter[]{new MethodParameter(getClass().getMethod("element", Element.class), -1)};
}
@Override
protected void testArgument(Object argument, MethodParameter parameter) {
assertTrue("argument not a element", argument instanceof Element);
Element node = (Element) argument;
assertEquals("Invalid namespace", NAMESPACE_URI, node.getNamespaceURI());
assertEquals("Invalid local name", LOCAL_NAME, node.getLocalName());
}
@Override
protected Element getReturnValue(MethodParameter returnType) {
return new Element(LOCAL_NAME, NAMESPACE_URI);
}
@ResponsePayload
public Element element(@RequestPayload Element element) {
return element;
}
}