Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenApiClientAction should not require optional fields #1190

Open
novarx opened this issue Jul 15, 2024 · 1 comment
Open

OpenApiClientAction should not require optional fields #1190

novarx opened this issue Jul 15, 2024 · 1 comment

Comments

@novarx
Copy link

novarx commented Jul 15, 2024

Citrus Version
4.2.1

Expected behavior
Given an openapi endpoint
And the response of the endpoint has the required fields: "category", "name", "status"
And the response of the endpoint has the optional fields: "id", "photoUrls", "tags"

When a valid request is executed
And the following json body is returned:
{
"category": {},
"name": "",
"status": "sold"
}

Then the test should pass green

Actual behavior
The Test always fails with Number of entries is not equal in element: '$', expected '[photoUrls, name, id, category, tags, status]' but was '[name, category, status]'

Test case sample

@Test
public class OpenApiClientIT extends TestNGCitrusSpringSupport {

    private final int port = SocketUtils.findAvailableTcpPort(8080);

    @BindToRegistry
    private final HttpServer httpServer = new HttpServerBuilder()
            .port(port)
            .timeout(5000L)
            .autoStart(true)
            .defaultStatus(HttpStatus.NO_CONTENT)
            .build();

    @BindToRegistry
    private final HttpClient httpClient = new HttpClientBuilder()
            .requestUrl("http://localhost:%d".formatted(port))
            .build();

    private final OpenApiSpecification petstoreSpec = OpenApiSpecification.from(
            Resources.create("classpath:org/citrusframework/openapi/petstore/petstore-v3.json"));

    @CitrusTest
    public void BUG_should_only_validate_the_presence_of_required_properties() {
        variable("petId", "1001");

        when(openapi(petstoreSpec)
                .client(httpClient)
                .send("getPetById")
                .message()
                .accept("application/json")
                .fork(true));

        then(http().server(httpServer)
                .receive()
                .get("/pet/${petId}")
                .message()
                .accept("@contains('application/json')@"));

        then(http().server(httpServer)
                .send()
                .response(HttpStatus.OK)
                .message()
                // TODO BUG this should be valid, according to the spec-file
                .body("""
                        {
                        "category": {},
                        "name": "",
                        "status": "sold"
                        }
                        """)
                .contentType("application/json"));

        then(openapi(petstoreSpec)
                .client(httpClient)
                .receive("getPetById", HttpStatus.OK)
                .message()
        );
    }
}
@novarx
Copy link
Author

novarx commented Jul 15, 2024

The validation expressions are built in org.citrusframework.openapi.OpenApiTestDataGenerator#createValidationExpression(...)

novarx pushed a commit to postfinance/citrus that referenced this issue Jul 17, 2024
novarx pushed a commit to postfinance/citrus that referenced this issue Jul 17, 2024
novarx pushed a commit to postfinance/citrus that referenced this issue Jul 18, 2024
cleanup

remove bug related todos

created issues for that:
- citrusframework#1190
- citrusframework#1189

update TODOs

refactor

disable deprecated tests

feature: put new openapi actions to mustache (WIP)

feature: improve receive action

feature: cleanup OpenApiClientRequestActionBuilder

feature: send typed fluent openapi builder works

feature: first fluent java implementation (wip)

chore: add todo-readme

chore: improve OpenApi example

chore: cleanup generator tests

chore: add license to new files

chore: remove author annotations

feat(citrusframework#1156): provide test api generator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants