citrusframework / citrus-simulator

Standalone simulator for different messaging transports such as Http REST, SOAP WebService, JMS, RMI, mail messaging and more
Apache License 2.0
44 stars 41 forks source link

citrus actions for REST api #200

Open bbortt opened 8 months ago

bbortt commented 8 months ago

as a user of both citrusframework/citrus and citrusframework/citrus-simulator I want to have standard "actions" that call a citrus API with the right arguments.

a good way of doing this is by extracting the OpenAPI specification from the simulator, then add a new module (name to be thought of) with generated clients. I would use some java-generator for this, preferably one without spring so the end user is not dependent upon citrus-spring.

the specifications should be stored in one file per resource. they belong into the simulator-starter (soon to be citrus-spring-boot-simulator, see #193) module, because it is the root of the API. multiple files are better maintainable than one large file.

the server implementation should be based on the OpenAPI as well (interfaces only, the already present resources should then implement these. that ensures compatibility of both client and server at all times. use the OpenAPI Spring generator.

it can be split into the following tasks whereas the first task must be done before all others:

christophd commented 8 months ago

I do not know if this is really related but maybe worth having a look. YAKS is having OpenAPI support where the client is able to run operations based on a OpenAPI specification. Test data is generated and the schema rules in the OpenAPI specification are also used for the response validation.

https://github.com/citrusframework/yaks/tree/main/java/steps/yaks-openapi/src/main/java/org/citrusframework/yaks/openapi

My plan is to backport these YAKS features to Citrus someday

bbortt commented 8 months ago

not exactly, although that's a cool feature.

assuming I have the endpoint /api/test-results and I expect one simulation to be executed. this is a real endpoint, not a REST (or whatever) simulator endpoint. I would love to do something like this in the citrus test:

        // Trigger a simulation
        $(http().client(simulatorClient)
                .send()
                .whatever());

        // Very simple access to endpoint
        $(getTestResults()
                .validate("$.length", 1));

       // Instead of
        $(http().client(simulatorClient)
                .send()
                .get("/api/test-results"));
        $(http().client(simulatorClient)
                .receive()
                .response(HttpStatus.OK)
                .message()
                .validate("$.length", 1));