300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > java服务器端测试_java-在服务器端测试Spring Web Services端点?

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

时间:2021-11-09 16:39:31

相关推荐

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/1122/2060195.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。