向MockWebServiceClient添加基本的HTTP身份验证 [英] Add basic http authentication to MockWebServiceClient

查看:69
本文介绍了向MockWebServiceClient添加基本的HTTP身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧测试,正在调用某些Web服务.以前,Web服务上没有安全性.现在已向其添加了基本的HTTP身份验证,因此测试失败.测试使用的是org.springframework.ws.test.server.MockWebServiceClient

I have som old test that are calling some web services. There was no security on the webservice before. Now basic http authentication has been added to it and test are therefore failing. Test are using org.springframework.ws.test.server.MockWebServiceClient

测试示例:

@Autowired
MockWebServiceClient mockClient

def "import valid entity"() {

    setup:
    def request = loadEntitesToRequest(validEntityFile)
    Source requestPayload = createStringSourceFromObject(request)

    when: 'Endpoint is requested to import valid entity'
    mockClient.sendRequest(withPayload(requestPayload)).andExpect(new ResponseMatcher() {
        void match(WebServiceMessage req, WebServiceMessage resp) {
            EntityImportResponse response = marshaller.unmarshal(resp.payloadSource)
            assert response.errorMessage.isEmpty()
            assert response.isSuccess()
        }
    })

    then: 'Entity is successfully imported'
    noExceptionThrown()
}

是否可以将基本的HTTP身份验证添加到此客户端?我知道如何将其添加到WebServiceTemplate中,但是为此我没有找到任何方法.

Is there any way to add basic http auth to this client? I know how to add it to WebServiceTemplate but for this i have not found any way.

推荐答案

好吧,这个问题实际上是一个不好的问题,MockWebserviceClient根本不处理http,您需要在此之外设置http请求中的内容客户

well, this question is actually a bad one, MockWebserviceClient doesn't deal with http at all, you need to set what you need in http requests outside of this client

这篇关于向MockWebServiceClient添加基本的HTTP身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆