Gena L
Gena L

Reputation: 420

Spring Cloud Contracts use of Provider State

I'm using Spring Cloud Contracts version 2.1.1, and I want to use provider state. I understand I can use scenarios as described here and here. For example, I can use POST method contract to add some state to a DB, and then use GET /calculate method contract which performs some logic based on that data in the DB (provider state).

But, what if the service consists only of GET /calculate method (it relies on external process to load data directly into the DB)? How do I create provider state in the absence of an API method? Is it possible with Spring Cloud Contracts?

My understanding is that with Pact, you can use any Java code to initialize provider state, and make that state part of the contract with given and @State. With Spring Contracts, I seem to be restricted to use only API requests (to create a contract and use it in scenarios). Can someone please clarify how I can use some plain Java code to load state directly to DB, and make it part of the contract?

Upvotes: 2

Views: 136

Answers (1)

Marcin Grzejszczak
Marcin Grzejszczak

Reputation: 11149

In spring cloud contract we don't think you should set the provider state - that means that you should not rely on your database. You should mock out services. If you really must do it then in the base class in the before method you can set the database state as you need to.

Upvotes: 1

Related Questions