-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Improve Java-Client Tests and CI #689
Comments
Previously (a while ago) I suggested using our own server generator to generate a server stub that allows us to add new test cases easily. If time permits, I may try to do that with the Rails generator or one of the PHP server generators. |
@wing328: Thank you for this feedback, but I would like to have something 100% java. Each unit test for the java-client should looks like this:
In my opinion, something like will get way to complicated if you start to mix technologies. |
I think that
can be accomplished with a mock server. I haven't had any chance to use them with Java yet, but a simple Google Search brought me to http://wiremock.org/docs/junit-rule/ that may be easy enough to use (it allows stubbing via json files http://wiremock.org/docs/stubbing/ ) To accomplish also
requests can be verified ( http://wiremock.org/docs/verifying/ ) or the server may be strictly configured for the expected request payload, so that anything out of the ordinary is rejected/returns error to the caller. I think that
may be more difficult.
|
Thank you a lot for your inputs. Because I pointed to this issue, I did the same research yesterday evening ;-) I think I was first confused with http://wiremock.org and/or http://www.mock-server.com/ because I do not want to mock a server (mock like in Mockito or EasyMock), I want to have a real server so I can use the real Http-libs in the generated clients. Am understand you concern and your reason about generating code on the fly, but I will let it out of scope of my experiment. I think I will give the Wiremock or Mock-Server a try. |
With jmini/openapi-experiments@ccc9146 I have created a PoC of a test-suite for java clients. Code is located mainly in the Some points I wanted to highlight:
Usage of Mock-Server: I wanted to outline why the usage of this tool is interesting in the context of testing.
Other ways to run Mock-Server (I did not try this yet): In the Java world, having a JUnit Rule (or the equivalent with JUnit5) is interesting, because this way we have a way to express “before test-suite or after test-suite” and not at class level as it is implemented now. Example: Because the google-api-client version that we use is quite old (see #3625), there is a conflict with guava, solved in the pom of Out-of scope of this PoC:
Next steps: The test suite needs to be extended. My vision is that small test-cases representing construct that are used in real project could be contributed. I have proposed this to start a discussion. I think that one approach could be to setup this for real (with CI, with some automation to update OpenAPI generator, with some reporting) as separated project When the project is mature enough and has shown viability we could think about merging it here (replacing or augmenting the petstore generated samples) Feedback is welcomed. |
To put it in an other way: My goal with this OpenAPI-Generator test suite (that will probably be different from the proposed PoC focusing only on Java) is to test the complete cycle: an OpenAPI Spect as intput -> OpenAPI-Generator generates a client that compiles -> given some input parameters for one operation -> the request must arrive server side correctly -> and given a response from the server -> the client must interpreted this correctly The same OpenAPI spec (that should be as minimal as possible to test a specific feature) can be used for several test cases where just the the input parameters and the server response differ. |
I think this is a very good proposal. It seems to me that especially with larger changes like my PR to introduce explicitly nullable fields (#3474) which made some of the templates quite complex, it's going to get harder and harder to maintain the codebase without introducing regressions. Therefore I fully support this proposal - I think the idea of having generated clients send requests, verifying them on the server side and then sending back responses to be verified on the client side is sufficient enough to test the features that openapi-generator templates should be providing. This will come especially handy with features like the one mentioned above, where it's necessary to test pretty much all various combinations of the field being required/nullable/readonly, which can get time consuming and tricky. I don't have too much time to spare, but I'd be happy to do some code review/testing if that would help. I'm starting to rely on the Java clients to be generated in a stable way, so I'll support any effort that helps that. |
Input @MatanRubin on #513:
Well the more I am confronted with changes to java-client templates, the more I think we need to do a real setup.
I theory some of the Java-Client have some tests for clients implemented (replacement of the generated stup) that perform test against some server serving the "Petstore sample". During the creation of OpenAPI-Generator, some of them were removed => #247. This reminds me that I should finish restoring them.
But this is not enough... Have a look at the PR I have merge this morning: #646. It is about special chars being wrongly encoded in query-params.
A test case would be ideal for that.
We need a setup where we can control the server for each test.
Using the generated code (XxxxApi) we send a request and we create expectations on what should arrive to the server.
Or in the server we define what should be returned and we see if the client did interpret the answer correctly.
I am wondering which library can be used to do something like this. Easy embedding of a small HTTP-Server. I have started to have a look at https://github.com/arteam/embedded-http-server, I can't imagine that there is not something.
(it is not about mocking the server, but having a simple one where we can perform assertions on request that arrived and were we can control the answer).
Any suggestions?
Then I think that we should generate client for all libs we support. I started something in this direction: https://github.com/jmini/openapi-experiments/tree/master/openapi-generator-utils/icespellmint. The spec used to create the client will be updated to test a lot of cases we have (all HTTP verbs like "GET", "POST", "PUT"..., with or without parameters, with different supported content-type (json, text, xml)).
This way we can control if something is an improvement or creates some regressions.
There is an other interesting issue: #476, I have started to work on this, but again I want to have a great coverage to be sure that I am not breaking anything.
Feedback is welcomed.
The text was updated successfully, but these errors were encountered: