Vishal Kukreja
08/01/2022, 3:07 PM@HiltAndroidTest
@Config(sdk = [Build.VERSION_CODES.Q])
@PactTestFor(
providerName = "our_provider"
)
@PactDirectory("presentation/target/pacts")
@ExtendWith(
PactConsumerTestExt::class
)
class VerificationEstimationPactTest {
private var HEADERS: MutableMap<String, String> = HashMap()
private var JSON: String? = null
@get:Rule
var rule: TestRule = InstantTaskExecutorRule()
@get:Rule
var hiltRule = HiltAndroidRule(this)
lateinit var viewModel: InvestorsProfileViewModel
init {
HEADERS["Content-Type"] = "application/json"
JSON="{\n" +
" \"score\":45,\n"
" \"profile\": \"RISK_AVERSE\"\n" +
"}"
}
@Before
fun setUp() {
hiltRule.inject()
}
@Throws(
UnsupportedEncodingException::class
)
@Pact(provider = "our_provider", consumer = "our_consumer")
fun createFragment(builder: PactDslWithProvider): RequestResponsePact {
return builder
.given("data count is > 0")
.uponReceiving("a request for json data")
.path("/provider.json")
.method("GET")
.willRespondWith()
.status(200)
.headers(HEADERS)
.body(JSON)
.toPact()
}
@Test
@PactTestFor(pactMethod = "createFragment")
fun should_process_the_json_payload_from_provider() {
val observer: TestObserver<InvestorProfile> = viewModel.getInvestorProfileUseCase.buildUseCaseObservable(
GetInvestorProfileUseCase.Params.GetInvestorProfileUseCase()).test()
observer.assertNoErrors()
observer.assertValue(
InvestorProfile(
45,"RISK_AVERSE"
)
)
}
}
GitHub
08/02/2022, 7:45 AMYousaf Nabi (pactflow.io)
Alan Still
07/29/2022, 1:15 PMAli Ustek
08/02/2022, 12:19 PMAlexandru Mihai
08/04/2022, 10:31 AMvoid setup {
mockClient instantiation
}
public void pactTest(){
pact for a POST to the client
}
This worked fine untill we implemented service descovery, and due to that, in setup is now an extra GET call to the mock server which generates Unexpected Request error.
Debugging this, I discovered that the pactTest runs just fine, the post request is made after the get one and even if asserts are run and everything is ok, in the end it fails due to that unexpected request error.
My question would be, is there any method to ignore the unexpected request, or to tell mock server how to respond to it, without adding it into the pact file ?
Thanks in advanceShan
08/04/2022, 7:40 PM@consumerVersionSelectors
in my provider's tests from this doc but it seems consumerVersionSelectors
method is deprecated.
/** @deprecated */
@Deprecated
VersionSelector[] consumerVersionSelectors() default {@VersionSelector(
tag = "${pactbroker.consumerversionselectors.tags:}",
latest = "${pactbroker.consumerversionselectors.latest:}",
consumer = "${pactbroker.consumers:}"
)};
For maven provider version 4.3.12.
What is the alternative for this annotation?Gaurav
08/04/2022, 8:46 PMGaurav
08/08/2022, 3:23 PMbuilder
.given('the instruction is accepted')
.uponReceiving('a request to create instruction')
.path("$BASE_URL/instruction")
.method('POST')
.headers('Content-Type', 'application/json',
'Accept', 'application/json')
.body(buildPactDslJsonBody())
.willRespondWith()
.status(201)
.body("1234")
.headers(Map.of('Content-Type', 'application/json'))
.toPact()
but when the pact is produced, it looks like this
{
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"body": 1234
}
instead of string its converting the response body to a number, is the string response not supported by pact libs?
Manu Mahendran
08/08/2022, 4:16 PMManu Mahendran
08/08/2022, 4:21 PMCristian Deac
08/09/2022, 9:16 AMvalueFromProviderState
syntax in a test and i was wondering if there is any trick to apply a function on the value return by the state provider
i.e the state populates the map with userId
in the test to use something like
newJsonBody((payload) ->
payload.valueFromProviderState("id", () -> Base64.encode("${userId}"), "MTIzCg=="))
.build()
Daniel Tischner
08/11/2022, 8:39 AMheaders(...)
and matchHeader(...)
, if not using REGEX in the first place, identical? I.e. do the following behave the same?
builder
.given(...)
.uponReceiving(...)
...
.headers("foo", "bar")
// vs
.matchHeader("foo", "bar")
(same goes for other similar methods that have a matchXXX
equivalent)Daniel Tischner
08/11/2022, 8:50 AMuponReceiving ... willRespondWith ...
part?
I noticed that some examples in the docs indent the parts to visually separate the request and the response:
builder
.given("foo")
.uponReceiving("something")
.path("ping/pong")
.method("POST")
.body("Hello")
.willRespondWith()
.successStatus()
.body("World")
.build()
But with most auto-formatting tools (IDE, Spotless, ...) this might not always be possible to achieve and it will just collapse back to:
builder
.given("foo")
.uponReceiving("something")
.path("ping/pong")
.method("POST")
.body("Hello")
.willRespondWith()
.successStatus()
.body("World")
.build()
Now, it is fairly simple to add a Lambda DSL to achieve this indents:
builder
.given("foo")
.uponReceiving("something")
.path("ping/pong") {
method("POST")
body("Hello")
}.willRespondWith()
successStatus()
body("World")
}.build()
Should I invest time into creating a PR, or am I overlooking something here?
(I noticed one issue between uponReceiving
and path
though, since they are changing types from ...WithoutPath
to ...WithPath
, so I only managed to make the DSL cut at the path
method)Daniel Tischner
08/12/2022, 1:15 PMbody(newJsonObject {
newArray("value_added_taxes") {
eachLike {
integerType("id")
newArray("values") {
decimalType("rate")
datetime("valid_since") // "2020-04-15T17:30:00Z"
datetime("valid_until") // "2020-06-15T17:30:00Z"
}
}
}
})
https://i.imgur.com/mLhIT5Y.png▾
https://i.imgur.com/yNrfnCS.png▾
{
"value_added_taxes": [
{
"id": 0,
"values": [
"rate": 0.12,
"valid_since": "2020-04-15T17:30:00Z",
"valid_until": "2020-06-15T17:30:00Z"
]
}
]
}
Daniel Tischner
08/22/2022, 10:03 AM0.12
, 0.35
or 0.5
etc. Essentially, it is "percentage" with maximal 2 digits after the separator.
How would I add this to my contract?
decimalType
allows all kinds of decimals, such as -1234.23456
stringMatcher
will make it a string type instead of decimal
Is there maybe some more general matches(...)
which I could then tell the type + a custom regex matching?
If not, how could I implement what I need as extension? Any hints?
While at it, what about other similar stuff, such as "any positive number"?Thai Le
08/22/2022, 9:04 PMThai Le
08/23/2022, 4:10 PMAbdurahman Hijazi
08/25/2022, 10:59 AM@Provider("provider")
@PactFolder("pacts")
@ExtendWith(VertxExtension.class)
public class PactContractTest {
final static AuthSessionRepository authSessionRepositoryMock = mock(AuthSessionRepository.class);
final static AuthCodeRepository authCodeRepositoryMock = mock(AuthCodeRepository.class);
final static DateUtils dateUtilsMock = mock(DateUtils.class);
final static WebClient webClientMock = mock(WebClient.class, RETURNS_DEEP_STUBS);
static WebClient webTestClient;
@BeforeAll
static void init(Vertx vertx, VertxTestContext testContext) {
var options = new WebClientOptions().setDefaultPort(8888);
webTestClient = WebClient.create(vertx, options);
TestSetupHelper.setupAndDeployVerticleForTests(vertx, testContext, authSessionRepositoryMock, authCodeRepositoryMock, dateUtilsMock, webClientMock);
}
@BeforeEach
void set_context(PactVerificationContext context) {
context.setTarget(new HttpTestTarget("localhost", 8888, "/"));
}
@TestTemplate
@ExtendWith(PactVerificationInvocationContextProvider.class)
void pactVerificationTestTemplate(VertxTestContext testContext, PactVerificationContext context) throws MalformedURLException {
context.verifyInteraction();
testContext.completeNow();
}
@State("returns id token as jwt")
void create_id_token_as_jwt(){
}
@State("token error")
void assert_correct_error_is_thrown_for_bad_token_request(PactVerificationContext context) {
// Assert that a certain exception is thrown
}
}
in one of my tests I am expecting a custom error to be thrown, can I catch it in my pact test or is that out of the scope of pact?Thai Le
08/25/2022, 8:08 PMHari Ravi
08/29/2022, 4:18 PMSravan
08/30/2022, 4:29 PMPublishing 'ppe-service-bus-issue-compilation-ppe-service-ent-issue-compilation.json' ... FAILED! 409 Conflict - {"error":"Cannot change the content of the pact for ppe-service-bus-issue-compilation version 1.0.0 and provider ppe-service-ent-issue-compilation, as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. For more information see <https://docs.pact.io/go/versioning>"}
I'm not sure why it is failing and the same json file is getting verified when the run the provider from my local machine pointing to the json file. Any idea?Sravan
08/30/2022, 5:04 PM{
"pacticipantName": "Foo",
"pacticipantVersionNumber": "dc5eb529230038a4673b8c971395bd2922d8b240",
"branch": "main",
"tags": [
"main"
],
"buildUrl": "<https://ci/builds/1234>",
"contracts": [
{
"consumerName": "Foo",
"providerName": "Bar",
"specification": "pact",
"contentType": "application/json",
"content": "<base64 encoded JSON pact>"
}
]
}
Response:
{
"notices": [
{
"type": "error",
"text": "Cannot change the content of the pact for ppe-service-ent-issue-compilation version 1.0.0 and provider ppe-service-ent-issue-compilation, as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. For more information see <https://docs.pact.io/go/versioning>"
},
{
"type": "info",
"text": ""
}
],
"errors": {
"contracts": [
"Cannot change the content of the pact for ppe-service-ent-issue-compilation version 1.0.0 and provider ppe-service-ent-issue-compilation, as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. For more information see <https://docs.pact.io/go/versioning>"
]
}
}
I dont see any difference in the content that is causing this issueÉdouard Lopez
09/02/2022, 10:04 AM{
"_embedded": {
"pacts": []
},
"_links": {
"self": {
"href": "<http://broker.org/pacts/provider/ms.advice-conversation/for-verification>",
"title": "Pacts to be verified"
}
}
}
Yet I do have contracts in /pacts/provider/ms.advice-conversation/
.
What am I missing here?Édouard Lopez
09/05/2022, 3:14 PMlatest version
on the consumer.
That could explains NoPactsFoundException
, but I don't understand how this happens? It was working before and my upgrade to 2.102.1
was a more than a month ago.
au.com.dius.pact.provider.junitsupport.loader.NoPactsFoundException: No Pact files were found to verify
Pablo Cabo
09/06/2022, 12:38 PMÉdouard Lopez
09/06/2022, 3:52 PMconsumerVersionSelectors
in @PactBroker
annotation? I get this IDE message?
JavaDoc says to use the same method (apologies I'm not familiar with Java)
Use consumerVersionSelectors method or pactbroker.consumerversionselectors property instead
pocomon
09/06/2022, 8:18 PMpocomon
09/06/2022, 8:40 PMJames Weng
09/07/2022, 3:22 AM@PactBrokerConsumerVersionSelectors
fun consumerVersionSelectors(): SelectorBuilder = SelectorBuilder()
.branch("main")
.environment("prod")
.environment("qa")
.environment("int")