添加基本http认证到MockWebServiceClient

问题描述:

我有som旧测试调用一些web服务。之前在web服务上没有任何安全性。现在已经添加了基本的HTTP身份验证,因此测试失败。测试使用org.springframework.ws.test.server.MockWebServiceClient测试添加基本http认证到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但为此我还没有找到任何方法。

+0

之外什么问题出在哪里?你有测试使用它,然后看看这些测试 –

+0

你应该改变你的问题。正如它被问到的那样,要了解你所问的内容并不容易。 – Nathan

好,这个问题实际上是一个坏女人,MockWebserviceClient不以http处理所有,你需要设置你的HTTP请求需要这个客户