2012-12-18 101 views
3

我試圖寫簡單Enpoint Web服務的JUnit測試:春WS + JAXB測試

@Endpoint 
public class TestWS { 

    @PayloadRoot(localPart = "GetAllPlayersRequest", namespace = NAMESPACE_URI) 
    public @ResponsePayload GetAllPlayersResponse handleGetAllPlayersRequest() { 
     ... 
    } 
} 

我的測試看起來像:

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = { "classpath:**/tb-ws-servlet.xml" }) 
public class TeambridgeWSTest extends AbstractWebServiceServerTest { 

    private MockWebServiceClient client; 

    @Autowired 
    public void setApplicationContex(ApplicationContext applicationContext) { 
     client = createClient(applicationContext); 
    } 

    @Test 
    public void shouldReturnAllPlayers() throws Exception { 
     ParametrizableRequestCreator message = withMessage("GetAllPlayersRequest.xml"); 
     client.sendRequest(message).andExpect(message("messages="GetAllPlayersResponse.xml")); 
    } 

} 

和GetAllPlayersRequest.xml:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://ws.tb.company.com/schemas"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <sch:GetAllPlayersRequest/> 
    </soapenv:Body> 
</soapenv:Envelope> 

我不知道爲什麼我得到

No endpoint mapping found for [SaajSoapMessage http://ws.tb.company.com/schemas}GetAllPlayersRequest] 

我在Spring中有經驗,但在Spring WS中仍然是新的。你對我的問題有什麼建議嗎?

回答

0

NAMESPACE_URI的價值是什麼?我想這是:

private static final String NAMESPACE_URI = "http://ws.tb.company.com/schemas"; 

您還使用註解驅動配置了您的Spring Web服務XML文件,不是嗎?

<context:component-scan base-package="your.package.here"/> 

<sws:annotation-driven/> 
+0

對於這兩個問題的答案是肯定的 – user1912592