0

{ "userId": "dummy1", "userRole": "s", "integrationId": "null", "integrationType": "dummy", "externalUserId": "dummy2" }

2
  • do you have your trials or can you demonstrate you did some investigation of your issue on your own?
    – Alexey R.
    Commented Feb 12, 2021 at 13:23
  • I tried with Json array but didn't worked I might missed something there, I have removed those currently I'm validating with one by one object for now-String body = res.getBody().asString(); JSONObject jsonObject = new JSONObject(body); Log.assertThat((jsonObject.isNull("Key")) && jsonObject.isNull("Key") && jsonObject.isNull("Key"),
    – Arun
    Commented Feb 12, 2021 at 14:10

1 Answer 1

1

You can use Hamcrest matchers to verify that:

package click.webelement.api.restassured;

import io.restassured.RestAssured;
import java.net.MalformedURLException;
import java.net.URL;
import static org.hamcrest.Matchers.*;

public class ValueValidation {

    public static void main(String[] args) throws MalformedURLException {
        RestAssured
                .when()
                .get(new URL("https://60269516186b4a0017780505.mockapi.io/wec"))
                .then()
                .body("$", not(hasValue(nullValue())));
    }

}

P.S. - https://60269516186b4a0017780505.mockapi.io/wec is a mock that I have created for the test. Not sure for how log it is going to exist. It returns:

{
  "userId": "dummy1",
  "userRole": "s",
  "integrationId": null,
  "integrationType": "dummy",
  "externalUserId": "dummy2"
}

P.P.S. - this "integrationId": "null" does not mean the field has null value. This is a string. Null value in JSON is set like this: "integrationId": null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.