Posts

Showing posts with the label mocking

How to mock java.util.base64 methods using mockito

How to mock java.util.base64 methods using mockito I have REST API which returns json response i am writing test case for the REST api method using mockito There is a xml response in the json so i am trying to encode the xml string in the json using Base64 My test case throws null pointer exception while executing the Base64.encode line in the REST api method I cant use powermockito , its not used in the organisation how can i fix this issue using mockito itself below is the line of code which throws error Base64.getEncoder().encodeToString((message)).getBytes(StandardCharsets.UTF_8); Here message is the xml string . 1 Answer 1 Are you sure you have to embed your XML in your JSON? Perhaps it would make for an easier API if you could transform your XML to JSON and not encode anything? But, If you're sure you have to have XML nested in JSON, then you should pass Base64.getEncoder() result as you...

How to get response based on the request body matching using wiremock and JSON

How to get response based on the request body matching using wiremock and JSON How to verify if my Soap request consists of an particular element in header and body using JSON and standalone WireMock. I should get response1 if my request contain <a:Id>1876</a:Id> in the header else i should get response2 <a:Id>1876</a:Id> similarly i need to check in body also. Below is my request XML <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://abc.example.com/a" xmlns:b="http://abc.example.com/b" xmlns:c="http://abc.example.com/c" <soapenv:Header> <a:abcHeaders> <a:Id>1876</a:Id> <a:Xid>12</a:Xid> </a:abcHeaders> </soapenv:Header> <soapenv:Body> <b:abcOpern> <b:xyz> <c:pqr>12</c:pqr> </b:xyz> </b:abcOpern> </soap...