on ‎2018 Apr 16 6:01 PM
We are writing unit test for commerce webservices (OCC) controllers, for example CartsControllers, UsersController etc. Almost all the methods within these controllers return web service DTO i.e the ones that ends with *WsDTO. This object conversion is done by dataMapper which is part of spring web application context. The challenge we are facing is unit test or integration tests cannot access web application context and fetch the bean from there. 90% of commerce webservices (OCC) controller methods are not testable without this since they all return DTOs. Mocking dataMapper itself will not achieve anything since that will defeat the purpose of writing test.
Please help!!
Request clarification before answering.
MockMvc - normal controllers
Rest Assured - Rest Controllers
As a side point anyone managed to configure spring security with MockMvc and a "standaloneSetup"
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could use http://rest-assured.io/ it's pretty cool.
Example
@Test
public void
lotto_resource_returns_200_with_expected_id_and_winners() {
when().
get("/lotto/{id}", 5).
then().
statusCode(200).
body("lotto.lottoId", equalTo(5),
"lotto.winners.winnerId", containsOnly(23, 54));
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit,
I think this article might contain some useful information: https://dzone.com/articles/testing-data-transfer-object-and-rest-controllers
Hope this helps,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.