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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值