kaushik dey
05/08/2024, 3:27 PMFailed to instantiate [com.github.tomakehurst.wiremock.WireMockServer]: Factory method 'wireMockServerConfig' threw exception with message: STRIP_TRAILING_BIGDECIMAL_ZEROES
Code Snippet:
@SpringBootApplication
@ConfigurationPropertiesScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public WireMockServer wireMockServerConfig() {
return new WireMockServer(WireMockConfiguration.wireMockConfig().notifier(new ConsoleNotifier(true))
.port(8082));
}
}
Can you please help me to solve this?Lee Turner
05/08/2024, 4:49 PMkaushik dey
05/09/2024, 8:40 AM'springBootVersion', '3.1.8'
implementation 'org.wiremock:wiremock:3.5.4'
So, I'm trying to create an Spring Boot application, where the stubs which are written as Java code gets reflected in GET /__admin/mappings
on application boot up in similar manner like the JSON stubs which are kept in the this path src/test/resources/mappings
kaushik dey
05/09/2024, 9:47 AM@SpringBootApplication
@ConfigurationPropertiesScan
public class Application {
public static void main(String[] args) {
System.setProperty("spring.cloud.compatibility-verifier.enabled", "false");
SpringApplication.run(Application.class, args);
}
@Bean
public WireMockServer wireMockServerConfig() {
return new WireMockServer(WireMockConfiguration.wireMockConfig().notifier(new ConsoleNotifier(true))
.port(8082));
}
}
Stubbing:
@Component
public class Stubbings {
@Autowired
public WireMockServer wireMockServer;
public StubMapping stubTest () {
return wireMockServer.stubFor(post(urlPathEqualTo("/test/call")) // Define a POST request stub
.willReturn(ok()) // Return a 200 OK response
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json") // Set response headers
.withBody("{ \"message\": \"Success\", \"transactionId\": \"12345\" }"))
.withServeEventListener(
"webhook",
webhook()
.withMethod(POST)
.withUrl("<http://localhost:8080>")
.withHeader("Content-Type", "application/json")
.withBody("{ \"message\": \"success\", \"transactionId\": \"{{jsonPath originalRequest.body '$.transactionId'}}\" }") // Webhook body with JSON path
));
}
}
And other than this there are couple of json mocks in this path src/test/resources/mappings
Lee Turner
05/09/2024, 2:07 PMLee Turner
05/09/2024, 2:09 PMkaushik dey
05/09/2024, 2:56 PM@SpringBootApplication
@ConfigurationPropertiesScan
@ComponentScan({"packageName"})
public class Application {
private final List<StubInterface> stubs;
public Application(List<StubInterface> stubs) {
this.stubs = stubs;
}
public static void main(String[] args) {
System.setProperty("spring.cloud.compatibility-verifier.enabled", "false");
SpringApplication.run(Application.class, args);
}
@EventListener(ApplicationReadyEvent.class)
public void mockServer(){
var wm = new WireMockServer(WireMockConfiguration.wireMockConfig().port(8082));
wm.start();
stubs.forEach(stub -> stub.stubTest(wm));
}
}