Skip to content

Add response body matchers - #37

Merged
Piiit merged 6 commits into
mainfrom
pm-add-response-body-matchers
Jul 20, 2026
Merged

Add response body matchers#37
Piiit merged 6 commits into
mainfrom
pm-add-response-body-matchers

Conversation

@Piiit

@PiiitPiiit commented Jul 15, 2026

Copy link
Copy Markdown
Member

I know that we return the response object and test against that directly with normal assert methods in newer projects, but in older ones we use this body matcher instead. I found a bug in EMVA and instead of fixing it also in Aichner, it would be better to move it to the lib and deprecate both copy/paste implementations in each project

@PiiitPiiit self-assigned this Jul 15, 2026
return this;
}

public ResponseBodyMatchers ignoringAudition() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignoringAudition()/ignoreAudition look like a typo — the fields being excluded (createdAt, createdBy, updatedAt, updatedBy) are audit fields, not "audition" fields. Worth renaming to ignoringAuditFields()/ignoreAuditFields.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

try {
var json = mvcResult.getResponse().getContentAsString();
var extractedValue = JsonPath.read(json, jsonPath);
T actualObject = JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(extractedValue), targetClass);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to AI you could use JSON_MAPPER.convertValue(extractedValue, targetClass) instead of serializing to a string and re-parsing — same result, avoids a redundant JSON round-trip. Can you check that proposal?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it in Aichner and EMVA and it works. So I will change it as suggested

}

public ResponseBodyMatchers ignoringAuditFields() {
this.ignoreAudition = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.ignoreAudition = true;
this.ignoringAuditFields = true;

@Piiit
Piiit merged commit b6a9b5a into mainJul 20, 2026
1 check passed
@Piiit
Piiit deleted the pm-add-response-body-matchers branch July 20, 2026 06:53
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Piiit@mmalfertheiner