Search in sources :

Example 1 with PostServeActionDefinition

use of com.github.tomakehurst.wiremock.extension.PostServeActionDefinition in project spring-cloud-contract by spring-cloud.

the class DefaultWireMockStubPostProcessorTests method thenPostServerActionWasSet.

private void thenPostServerActionWasSet(StubMapping result) {
    then(result.getRequest().getMethod().getName()).isEqualTo("GET");
    then(result.getResponse().getStatus()).isEqualTo(200);
    then(result.getResponse().getBody()).isEqualTo("pong");
    then(result.getPostServeActions().stream().map(a -> a.getName()).collect(Collectors.toList())).contains("webhook");
    PostServeActionDefinition definition = result.getPostServeActions().stream().filter(a -> a.getName().equals("webhook")).findFirst().orElseThrow(() -> new AssertionError("No webhook action found"));
    then(definition.getParameters().getString("method")).isEqualTo("POST");
}
Also used : Test(org.junit.jupiter.api.Test) PostServeActionDefinition(com.github.tomakehurst.wiremock.extension.PostServeActionDefinition) Contract(org.springframework.cloud.contract.spec.Contract) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Collectors(java.util.stream.Collectors) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) PostServeActionDefinition(com.github.tomakehurst.wiremock.extension.PostServeActionDefinition)

Example 2 with PostServeActionDefinition

use of com.github.tomakehurst.wiremock.extension.PostServeActionDefinition 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 3 with PostServeActionDefinition

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

the class BasicMappingBuilder method withPostServeAction.

@Override
public <P> BasicMappingBuilder withPostServeAction(String extensionName, P parameters) {
    Parameters params = parameters instanceof Parameters ? (Parameters) parameters : Parameters.of(parameters);
    postServeActions.add(new PostServeActionDefinition(extensionName, params));
    return this;
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) PostServeActionDefinition(com.github.tomakehurst.wiremock.extension.PostServeActionDefinition)

Aggregations

PostServeActionDefinition (com.github.tomakehurst.wiremock.extension.PostServeActionDefinition)3 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 PostServeAction (com.github.tomakehurst.wiremock.extension.PostServeAction)1 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 BDDAssertions.then (org.assertj.core.api.BDDAssertions.then)1 Test (org.junit.jupiter.api.Test)1 Contract (org.springframework.cloud.contract.spec.Contract)1