我想为AbstractSoapInterceptor
创建一个小的单元测试,如下所示:
public class SimpleInterceptorTest {
private SimpleInterceptor simpleInterceptor;
@BeforeMethod
public void setUp() {
simpleInterceptor = new SimpleInterceptor();
}
@Test
public void testHandleMessage() throws Exception {
SoapMessage soapMessage = createSoapMessage("requests/sampleRequest.xml");
simpleInterceptor.handleMessage(soapMessage);
// Assertions
}
}
requests/sampleRequest.xml
是一个Soap-Request,例如:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soap:Header>
<wsse:Security>
<wsc:SecurityContextToken xmlns:wsc="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="sct">
<wsc:Identifier>abcd</wsc:Identifier>
</wsc:SecurityContextToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<wst:RequestSecurityToken xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" >
<wst:TokenType>http://schemas.xmlsoap.org/ws/2005/02/sc/sct</wst:TokenType>
<wst:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Validate</wst:RequestType>
<wst:ValidateTarget>
<wsse:SecurityTokenReference>
<wsse:Reference URI="#sct"/>
</wsse:SecurityTokenReference>
</wst:ValidateTarget>
</wst:RequestSecurityToken>
</soap:Body>
</soap:Envelope>
现在我有以下问题:
这是测试拦截器的正确方法吗?
如果是,如何实施
方法createSoapMessage
?
答案 0 :(得分:1)
以下是Apache拦截器的单元测试的示例:
因此,可以实现createSoapMessage
方法,但是并没有所希望的那么简单。
非常感谢您提供更简单的解决方案。
现在,我用SoapUI测试拦截器。