All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.hippoom.wiremock.contract.verifier.mockmvc.ResultMatcherMapper Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package com.github.hippoom.wiremock.contract.verifier.mockmvc;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import java.util.ArrayList;
import java.util.List;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.util.StringUtils;

public class ResultMatcherMapper {

    public ResultMatcher from(StubMapping stubMapping) {
        List delegates = new ArrayList<>();

        ResponseDefinition responseDefinition = stubMapping.getResponse();

        delegates.add(status().is(responseDefinition.getStatus()));

        if (!StringUtils.isEmpty(responseDefinition.getBody())) {
            delegates.add(content().json(responseDefinition.getBody()));
        }
        return new MultiResultMatcher(delegates);
    }

    public static class MultiResultMatcher implements ResultMatcher {

        private List delegates;

        public MultiResultMatcher(
            List delegates) {
            this.delegates = delegates;
        }

        @Override
        public void match(MvcResult result) throws Exception {
            for (ResultMatcher current : this.delegates) {
                current.match(result);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy