-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Description
Sometimes when you are writing tests for an API (with Rest-Assured in my case) you can not use the fluent API to build request, because you want to create an alternative request (malformed, corner case...)
You can use rest-assured RequestSpecBuilder for that. You then write code like this:
final String updateBody = "{"
+ "\"id\": \"" + req.getId() + "\", "
+ "\"version\": \"" + req.getVersion() + "\", "
+ "\"name\": \"" + req.getName() + "\", "
+ "\"billingAddressId\": null, "
+ "\"contactAddressId\": null, "
+ "\"metadata\": null}";
final Account account = createSuperAdminApi().accountsUpdate().simulateQuery(true)
.reqSpec(b -> b.setBody(updateBody))
.executeAs(r -> r.thenReturn());
I would be great instead of hard-coding the json member like this, to be able to reference constants:
final String updateBody = "{"
+ "\""+ Acount.SERIALIZED_NAME_Id +"\": \"" + req.getId() + "\", "
+ "\""+ Acount.SERIALIZED_NAME_Version +"\": \"" + req.getVersion() + "\", "
+ "\""+ Acount.SERIALIZED_NAME_Name +"\": \"" + req.getName() + "\", "
+ "\""+ Acount.SERIALIZED_NAME_BillingAddressId +"\": null, "
+ "\""+ Acount.SERIALIZED_NAME_ContactAddressId +"\": null, "
+ "\"metadata\": null}";
This way, when the API evolves, the Java compiler indicates that something needs to be changed in the test case (the same way that the fluent api is also changed).
Reactions are currently unavailable