【问题标题】:Add basic http authentication to MockWebServiceClient向 MockWebServiceClient 添加基本的 http 身份验证
【发布时间】:2017-08-04 09:02:22
【问题描述】:

我有一些旧测试正在调用一些 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 但为此我还没有找到任何方法。

【问题讨论】:

  • 问题出在哪里?您有使用它的测试,然后查看这些测试
  • 您应该重新表述您的问题。正如它所问的那样,要理解你在问什么并不容易。

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


【解决方案1】:

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

【讨论】:

  • 嗨,我也面临着类似的情况。您能否分享一下您是如何进行测试的?是否可以使用spring-ws-test 来执行这种集成测试,还是应该寻找另一种方法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-21
  • 2011-11-12
  • 2011-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多