[Java rest-assured] reqSpec is reused across multiple requests
Created by: jmini
Given this spec:
openapi: 3.0.1
info:
title: ping test
version: '1.0'
servers:
- url: 'http://localhost:8080/'
paths:
/ping:
get:
operationId: pingGet
tags:
- lorem
parameters:
- in: query
name: q
schema:
type: string
- in: query
name: r
schema:
type: string
responses:
'201':
description: Ok
Adjust the generated test src/test/java/org/openapitools/client/api/LoremApiTest.java
to:
@Test
public void shouldSee201AfterPingGet() {
String q1 = "param1";
api.pingGet().qQuery(q1).execute(r -> r.prettyPeek());
String q2 = "param2";
String r2 = "param2";
api.pingGet().qQuery(q2).rQuery(r2).execute(r -> r.prettyPeek());
}
(Do not forget to remove the generated @Ignore
annotation on top of the unit-test class)
Run the test against a server where you can have a look at the requests.
The server is receiving this logs:
First request:
[GET] /ping?q=param1
Second request:
[GET] /ping?q=param1&q=param2&r=param2
Having two q
params in the second request is wrong!
My analysis is that this is because reqSpec
is reused between calls and it should not be the case.