Search in sources :

Example 1 with PostServeAction

use of com.github.tomakehurst.wiremock.extension.PostServeAction in project wiremock by wiremock.

the class StubRequestHandler method afterResponseSent.

@Override
protected void afterResponseSent(ServeEvent serveEvent, Response response) {
    for (PostServeAction postServeAction : postServeActions.values()) {
        postServeAction.doGlobalAction(serveEvent, admin);
    }
    List<PostServeActionDefinition> postServeActionDefs = serveEvent.getPostServeActions();
    for (PostServeActionDefinition postServeActionDef : postServeActionDefs) {
        PostServeAction action = postServeActions.get(postServeActionDef.getName());
        if (action != null) {
            Parameters parameters = postServeActionDef.getParameters();
            action.doAction(serveEvent, admin, parameters);
        } else {
            notifier().error("No extension was found named \"" + postServeActionDef.getName() + "\"");
        }
    }
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) PostServeAction(com.github.tomakehurst.wiremock.extension.PostServeAction) PostServeActionDefinition(com.github.tomakehurst.wiremock.extension.PostServeActionDefinition)

Example 2 with PostServeAction

use of com.github.tomakehurst.wiremock.extension.PostServeAction in project wiremock by wiremock.

the class JettyHttpServerTest method init.

@BeforeEach
public void init() {
    Admin admin = Mockito.mock(Admin.class);
    adminRequestHandler = new AdminRequestHandler(AdminRoutes.defaults(), admin, new BasicResponseRenderer(), new NoAuthenticator(), false, Collections.<RequestFilter>emptyList());
    stubRequestHandler = new StubRequestHandler(Mockito.mock(StubServer.class), Mockito.mock(ResponseRenderer.class), admin, Collections.<String, PostServeAction>emptyMap(), Mockito.mock(RequestJournal.class), Collections.<RequestFilter>emptyList(), false);
}
Also used : NoAuthenticator(com.github.tomakehurst.wiremock.security.NoAuthenticator) StubRequestHandler(com.github.tomakehurst.wiremock.http.StubRequestHandler) PostServeAction(com.github.tomakehurst.wiremock.extension.PostServeAction) AdminRequestHandler(com.github.tomakehurst.wiremock.http.AdminRequestHandler) BasicResponseRenderer(com.github.tomakehurst.wiremock.http.BasicResponseRenderer) Admin(com.github.tomakehurst.wiremock.core.Admin) RequestFilter(com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with PostServeAction

use of com.github.tomakehurst.wiremock.extension.PostServeAction in project wiremock by wiremock.

the class StubRequestHandlerTest method init.

@BeforeEach
public void init() {
    stubServer = mock(StubServer.class);
    responseRenderer = mock(ResponseRenderer.class);
    httpResponder = new MockHttpResponder();
    admin = mock(Admin.class);
    requestJournal = mock(RequestJournal.class);
    requestHandler = new StubRequestHandler(stubServer, responseRenderer, admin, Collections.<String, PostServeAction>emptyMap(), requestJournal, Collections.<RequestFilter>emptyList(), false);
}
Also used : RequestJournal(com.github.tomakehurst.wiremock.verification.RequestJournal) StubServer(com.github.tomakehurst.wiremock.core.StubServer) PostServeAction(com.github.tomakehurst.wiremock.extension.PostServeAction) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MockHttpResponder(com.github.tomakehurst.wiremock.testsupport.MockHttpResponder) Admin(com.github.tomakehurst.wiremock.core.Admin) RequestFilter(com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilter) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with PostServeAction

use of com.github.tomakehurst.wiremock.extension.PostServeAction in project wiremock by wiremock.

the class PostServeActionExtensionTest method providesServeEventWithResponseFieldPopulated.

@Test
public void providesServeEventWithResponseFieldPopulated() throws InterruptedException {
    final AtomicInteger finalStatus = new AtomicInteger();
    initWithOptions(options().dynamicPort().extensions(new PostServeAction() {

        @Override
        public String getName() {
            return "response-field-test";
        }

        @Override
        public void doGlobalAction(ServeEvent serveEvent, Admin admin) {
            if (serveEvent.getResponse() != null) {
                finalStatus.set(serveEvent.getResponse().getStatus());
            }
        }
    }));
    wm.stubFor(get(urlPathEqualTo("/response-status")).willReturn(aResponse().withStatus(418)));
    client.get("/response-status");
    await().atMost(5, SECONDS).until(getValue(finalStatus), is(418));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PostServeAction(com.github.tomakehurst.wiremock.extension.PostServeAction) ServeEvent(com.github.tomakehurst.wiremock.stubbing.ServeEvent) Admin(com.github.tomakehurst.wiremock.core.Admin) Test(org.junit.jupiter.api.Test)

Aggregations

PostServeAction (com.github.tomakehurst.wiremock.extension.PostServeAction)4 Admin (com.github.tomakehurst.wiremock.core.Admin)3 RequestFilter (com.github.tomakehurst.wiremock.extension.requestfilter.RequestFilter)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 StubServer (com.github.tomakehurst.wiremock.core.StubServer)1 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1 PostServeActionDefinition (com.github.tomakehurst.wiremock.extension.PostServeActionDefinition)1 AdminRequestHandler (com.github.tomakehurst.wiremock.http.AdminRequestHandler)1 BasicResponseRenderer (com.github.tomakehurst.wiremock.http.BasicResponseRenderer)1 StubRequestHandler (com.github.tomakehurst.wiremock.http.StubRequestHandler)1 NoAuthenticator (com.github.tomakehurst.wiremock.security.NoAuthenticator)1 ServeEvent (com.github.tomakehurst.wiremock.stubbing.ServeEvent)1 MockHttpResponder (com.github.tomakehurst.wiremock.testsupport.MockHttpResponder)1 RequestJournal (com.github.tomakehurst.wiremock.verification.RequestJournal)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.jupiter.api.Test)1