Search code examples
javaspringgroovyspring-wshttp-authentication

Add basic http authentication to 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

example of test:

@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()
}

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.


Solution

  • 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