javascript
java服务器端测试_java-在服务器端测试Spring Web Services端点?
我正在使用Spring WS 2.0.我已經看到了端點和測試用例以測試端點.
@Endpoint
public class CustomerEndpoint {
@ResponsePayload
public CustomerCountResponse getCustomerCount(
@RequestPayload CustomerCountRequest request) {
CustomerCountResponse response = new CustomerCountResponse();
response.setCustomerCount(10);
return response;
}
}
import javax.xml.transform.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.xml.transform.StringSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.ws.test.server.MockWebServiceClient;
import static org.springframework.ws.test.server.RequestCreators.*;
import static org.springframework.ws.test.server.ResponseMatchers.*;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("spring-ws-servlet.xml")
public class CustomerEndpointIntegrationTest {
@Autowired
private ApplicationContext applicationContext;
private MockWebServiceClient mockClient;
@Before
public void createClient() {
mockClient = MockWebServiceClient.createClient(applicationContext);
}
@Test
public void customerEndpoint() throws Exception {
Source requestPayload = new StringSource(
"" +
"John Doe" +
"");
Source responsePayload = new StringSource(
"" +
"10" +
"");
mockClient.sendRequest(withPayload(requestPayload)).
andExpect(payload(responsePayload));
}
}
在這里,我有關于測試用例的查詢.在這里,我們將XML字符串作為請求有效負載傳遞.但就我而言,我有一個非常大的XML文件,它將有100行.在那種情況下,我覺得可以傳遞JAXB生成的對象(CustomerCountRequest)本身作為requestPayload,而不是傳遞XML字符串?如何進行集成測試到終點?
解決方法:
是的你可以.
照常實例化CustomerCountRequest對象,并使用JAXBContext將其包裝在JAXBSource中:
CustomerCountRequest request = new CustomerCountRequest();
// add setters on the request object if needed
JAXBContext jc = JAXBContext.newInstance(CustomerCountRequest.class);
JAXBSource source = new JAXBSource(jc, request);
標簽:spring-ws,jaxb,web-services,spring,java
來源: https://codeday.me/bug/20191122/2060195.html
總結
以上是生活随笔為你收集整理的java服务器端测试_java-在服务器端测试Spring Web Services端点?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java程序员的典型工作过程有哪些_Ja
- 下一篇: 海信vidda售后标准