日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

java服务器端测试_java-在服务器端测试Spring Web Services端点?

發布時間:2023/12/1 javascript 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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端点?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。