Hi, I have this pact java file
import static com.example.desafiostone.constants.Constants.*;
import static com.example.desafiostone.utils.Util._getMockRequest_;
import static org.junit.jupiter.api.Assertions._assertEquals_;
import static org.springframework.http.HttpMethod._POST_;
@ExtendWith(PactConsumerTestExt.class)
class CreateProductIT {
Map
String, String headers = new HashMap<>();
String path = “/starstore/product/“;
@Pact(provider = _PACT_PROVIDER_, consumer = _PACT_CONSUMER_)
public RequestResponsePact createPact(PactDslWithProvider builder) {
headers.put(“Content-Type”, “application/json”);
headers.put(“Accept”, “application/json”);
DslPart bodyReceived = new PactDslJsonBody()
.numberType(“price”, 7990)
.close();
return builder
.given(“A request to create a product”)
.uponReceiving(“A request to create a product”)
.body(bodyReceived)
.path(path)
.method(String._valueOf_(
POST))
.headers(headers)
.willRespondWith()
.status(201)
.toPact();
}
@Test
@PactTestFor(providerName = _PACT_PROVIDER_, port = _MOCK_PACT_PORT_, pactVersion = PactSpecVersion.
V3)
void runTest() {
Response response = _getMockRequest_(headers).body(new Product()).post(path);
_assertEquals_(201, response.getStatusCode());
}
}
It passes when my product class has the price variable as the primitive double
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Product {
private double price;
}
However, it fails with a 500 when it uses a Double (object) instead. I’m wondering why that is?