Hi, I have this pact java file import static com....
# pact-jvm
f
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 { MapString, 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?
b
Without seeing the outputs, it'll be hard to know :) but a few things: • What are you using to serialise your objects to JSON? (Maybe it's configurable) • Using floating point values for money with maths is error-prone. • I always use something like BigDecimal (or cents rather than dollars) to avoid floating point errors, and Jackson (for example) has good support for serialisation options 😇
☝️ 1
m
logs would help, the
500
usually means it got a request it didn’t expect, and the test output should say why
💯 1
also, welcome back - haven’t seen you around for a wihel!
f
@Boris I’m using Jackson. Yes, I changed it later to BigDecimal, but I was just curious about how the library works with double vs Double.
🤔 1
@Matt (pactflow.io / pact-js / pact-go) haha, thank you. I changed companies, and my current employer does not use pact, so currently I’m just using it for personal project.
b
Yarr, wb, hope you can get traction easily enough 🙏
🦜 1
f
Yes, it would be nice to have pact here too, but sometimes introducing new ideas and tools is not as straightforward.
😭 1
Maybe someday..
fingerscrossed 2