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

net.javacrumbs.jsonunit.spring.WebTestClientJsonMatcher Maven / Gradle / Ivy

The newest version!
package net.javacrumbs.jsonunit.spring;

import static net.javacrumbs.jsonunit.spring.Utils.getContentAsString;

import java.util.function.Consumer;
import java.util.function.Function;
import net.javacrumbs.jsonunit.core.Configuration;
import net.javacrumbs.jsonunit.core.internal.matchers.InternalMatcher;
import org.jetbrains.annotations.NotNull;
import org.springframework.test.web.reactive.server.EntityExchangeResult;

/**
 * Matcher compatible with Spring TestWebClient.
 * 

* Sample usage: *

* * client.get().uri(path).accept(MediaType.APPLICATION_JSON).exchange().expectBody() * .consumeWith(json().isEqualTo(CORRECT_JSON)); * */ public class WebTestClientJsonMatcher extends AbstractSpringMatchers>> { private WebTestClientJsonMatcher(Configuration configuration, Function jsonTransformer) { super(configuration, jsonTransformer); } public static WebTestClientJsonMatcher json() { return new WebTestClientJsonMatcher(Configuration.empty(), Function.identity()); } @Override @NotNull Consumer> matcher(@NotNull Consumer matcher) { return new JsonUnitWebTestClientMatcher(configuration, matcher, jsonTransformer); } @Override @NotNull WebTestClientJsonMatcher matchers( @NotNull Configuration configuration, @NotNull Function jsonTransformer) { return new WebTestClientJsonMatcher(configuration, jsonTransformer); } private static class JsonUnitWebTestClientMatcher extends AbstractSpringMatcher implements Consumer> { private JsonUnitWebTestClientMatcher( @NotNull Configuration configuration, @NotNull Consumer matcher, @NotNull Function jsonTransformer) { super(configuration, matcher, jsonTransformer); } @Override public void accept(EntityExchangeResult result) { doMatch(getContentAsString(result)); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy