Skip to content

json patch output in tests still string#1630

Open
suarezrominajulieta wants to merge 3 commits into
masterfrom
feature/jsonpatch_noDtoOutputTest
Open

json patch output in tests still string#1630
suarezrominajulieta wants to merge 3 commits into
masterfrom
feature/jsonpatch_noDtoOutputTest

Conversation

@suarezrominajulieta

@suarezrominajulieta suarezrominajulieta commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

In base to Andrea's comment:

"fine for now. not in this PR, but make new branch PR in which you create the following E2E for an API that:

has a POST to create a resource
has a PATCH to manipulate such created resource (404 if no resource)
and then make sure using DTO (there is a EMConfig for it), so that, in same generates test, we have a DTO used for POST following a call on PATCH without DTO (ie Patch must use a string representation, at least for now). any case, test should not fail to compile"

i created this pr with a test that proves that. this is one of the success test generated:

/**
* Calls:
* 1 - (201) POST:/api/jsonpatchdto/resources
* 2 - (200) PATCH:/api/jsonpatchdto/resources/{id}
*/
@Test @Timeout(60)
public void test_4_patchOnResourcReturns200() throws Exception {
    
    BBJsonPatchResourceDto dto_BBJsonPatchResourceDto_1 = new BBJsonPatchResourceDto();
    dto_BBJsonPatchResourceDto_1.setName("1GmNB");
    dto_BBJsonPatchResourceDto_1.setAge(618);
    
    ValidatableResponse res_0 = given().accept("application/json")
            .contentType("application/json")
            .body(dto_BBJsonPatchResourceDto_1)
            .post(baseUrlOfSut + "/api/jsonpatchdto/resources")
            .then()
            .statusCode(201)
            .assertThat()
            .contentType("application/json");
    String location_resources__2 = "/api/jsonpatchdto/resources" + "/" + res_0.extract().body().path("id").toString();
    
    given().accept("text/plain")
            .contentType("application/json-patch+json")
            .body(" [ { " + 
                " \"op\" : \"test\", " + 
                " \"path\" : \"/c\", " + 
                " \"value\" : \"eDgXhicy5FjjbV7h\" " + 
                " }, { " + 
                " \"op\" : \"copy\", " + 
                " \"from\" : \"/b\", " + 
                " \"path\" : \"/a\" " + 
                " }, { " + 
                " \"op\" : \"replace\", " + 
                " \"path\" : \"/d\", " + 
                " \"value\" : -1207061644 " + 
                " } ] ")
            .patch(resolveLocation(location_resources__2, baseUrlOfSut + "/api/jsonpatchdto/resources/-2191309024963475557"))
            .then()
            .statusCode(200)
            .assertThat()
            .contentType("text/plain")
            .body(containsString("patched"));
}

@suarezrominajulieta suarezrominajulieta marked this pull request as ready for review July 7, 2026 16:40
}

@ParameterizedTest
@EnumSource(value = OutputFormat::class, names = ["JAVA_JUNIT_5", "KOTLIN_JUNIT_5"])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add a comment to specify why test is only run for those formats

assertPostThenPatchInSameTest(solution)
}

val generatedCode = readGeneratedCode(outputFormat, outputFolderName)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the inherited class EnterpriseTestBase already has methods such as assertTextInTests that should work here. use those instead of creating new one, unless those do not match your needs. also, as this would be a general function that could be re-used in different tests, shouldn't be here, but rather moved higher up in the hierarchy (eg under EnterpriseTestBase)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

or into SpringTestBase if specific to BB

* created resource. This is stronger than [assertHasAtLeastOne], which only checks each call exists somewhere
* in the solution independently and in any order.
*/
private fun assertPostThenPatchInSameTest(solution: Solution<RestIndividual>) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this could be generalized, with 2 input verbs, and moved up to RestTestBase

Sign up for free to 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