I have seen this issue mentioned in Stack overflow but no final response....
I am trying Wiremock running it as a standalone Server but I am having issues with the verification bit.
Here is a copy of my test.
package uk.gov.hmcts.futurehearings.hmi.integration.hearing;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
import static net.serenitybdd.rest.SerenityRest.expect;
import static org.junit.Assert.assertEquals;
import static uk.gov.hmcts.futurehearings.hmi.integration.common.TestingUtils.readFileContents;
import uk.gov.hmcts.futurehearings.hmi.Application;
import java.io.IOException;
import java.util.Map;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import lombok.extern.slf4j.Slf4j;
import net.serenitybdd.junit.spring.integration.SpringIntegrationSerenityRunner;
import net.serenitybdd.rest.SerenityRest;
import net.thucydides.core.annotations.Narrative;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@slf4j
@RunWith(SpringIntegrationSerenityRunner.class)
@Narrative(text={"In order to test that the Hearing Service is working properly",
"As a tester",
"I want to be able to execute the tests for various endpoints"})
@SpringBootTest(classes = {Application.class})
@activeprofiles("integration")
public class API_WiremockStandaloneTest {
/* @after
public void reset() {
WireMock.reset();
}*/
}
My Mock End point.
http://localhost:9050/product/p0001
{
id: "1",
currentDateTime: "2019-03-12T10:54+01:00",
utcOffset: "01:00:00",
isDayLightSavingsTime: false,
dayOfTheWeek: "Tuesday",
timeZoneName: "Central Europe Standard Time FROM HMCTS",
currentFileTime: "131968616698822965",
ordinalDate: "2019-71",
serviceResponse: null
}
Am getting the error....
Expected at least one request matching: {
"url" : "/product/p0001",
"method" : "GET"
}
Requests received: [ ]
com.github.tomakehurst.wiremock.client.VerificationException: Expected at least one request matching: {
"url" : "/product/p0001",
"method" : "GET"
}
Requests received: [ ]
at com.github.tomakehurst.wiremock.client.WireMock.verificationExceptionForNearMisses(WireMock.java:551)
at com.github.tomakehurst.wiremock.client.WireMock.verifyThat(WireMock.java:538)
at com.github.tomakehurst.wiremock.client.WireMock.verifyThat(WireMock.java:521)
at com.github.tomakehurst.wiremock.WireMockServer.verify(WireMockServer.java:271)
at uk.gov.hmcts.futurehearings.hmi.integration.hearing.HearingAPI_WiremockStandaloneTest.should_work_from_standalone_mock(HearingAPI_WiremockStandaloneTest.java:92)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at net.serenitybdd.junit.runners.SerenityStatement.evaluate(SerenityStatement.java:33)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at net.serenitybdd.junit.runners.SerenityRunner.performRunChild(SerenityRunner.java:464)
Without the verification step the test passes.....
Any idea how I can make this work please?????