From 5b2dec57486fc754e3ed5c02b4d80ddd0660eba6 Mon Sep 17 00:00:00 2001 From: Anshul Bansal Date: Tue, 3 Sep 2019 13:12:17 +0300 Subject: [PATCH] BAEL-3190 - Working with web services in Groovy - basic authorization --- .../groovy/com/baeldung/webservice/WebserviceUnitTest.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy b/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy index edf2dca33f..0d4b5cd7ee 100644 --- a/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy +++ b/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy @@ -6,6 +6,7 @@ import wslite.rest.RESTClient import wslite.rest.RESTClientException import wslite.soap.SOAPClient import wslite.soap.SOAPMessageBuilder +import wslite.http.auth.HTTPBasicAuthorization class WebserviceUnitTest extends GroovyTestCase { @@ -120,10 +121,12 @@ class WebserviceUnitTest extends GroovyTestCase { def path = "/basic-auth" def response try { - response = client.get(path: path, headers: ["Authorization": "Basic cG9zdG1hbjpwYXNzd29yZA=="]) + client.authorization = new HTTPBasicAuthorization("postman", "password") + response = client.get(path: path) assert response.statusCode == 200 assert response.json?.authenticated == true } catch (RESTClientException e) { + e.printStackTrace() assert e?.response?.statusCode != 200 } }