将基本http身份验证添加到MockWebServiceClient

时间:2017-08-04 09:02:22

标签: java spring groovy spring-ws http-authentication

我有一个老测试,正在调用一些Web服务。之前Web服务没有安全性。现在已经添加了基本的http身份验证,因此测试失败。测试使用的是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 auth添加到此客户端?我知道如何将它添加到WebServiceTemplate但是为此我没有找到任何办法。

1 个答案:

答案 0 :(得分:0)

好吧,这个问题其实很糟糕,MockWebserviceClient根本不处理http,你需要在这个客户端之外的http请求中设置你需要的东西