-1

How can I simulate transactions in REST?

I have just developed the back-end with Jersey, Spring, Spring Data for data access, which connects to a MySQL DB. My goal is to show(like a test) that it can handle database transactions, but can't imagine how to do it.

Nicolae Focsa
  • 55
  • 1
  • 1
  • 5

1 Answers1

0

You would test a RESTful endpoint that does a transaction the same way you would test an endpoint that does not do a transaction - by calling it.

Write an integration test (probably Junit, and make sure it uses the @WebAppConfiguration annotation) that calls your RESTful endpoint(s). In your test, inject (@Autowire or @Resource) your service that contains your endpoint. Call the methods on that service (i.e. the endpoint), passing in fake or generated parameters. In your test, look for the expected behavior. For example, if you accessed a PUT endpoint that was supposed to create a book, using the DAO or access object, try to retrieve it from the database. If the DAO can retrieve it, then the endpoint successfully negotiated the transaction. Similarly, set up a test where the transaction should not go through, and therefore be rolled back, and use the DAO to make sure it did not get in the database.

Pickled Brain
  • 313
  • 1
  • 6