com.stehno.ersatz.impl.ErsatzRequestWithContent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ersatz Show documentation
Show all versions of ersatz Show documentation
Mock server library for testing HTTP clients.
The newest version!
/*
* Copyright (C) 2019 Christopher J. Stehno
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.stehno.ersatz.impl;
import com.stehno.ersatz.cfg.HttpMethod;
import com.stehno.ersatz.cfg.RequestWithContent;
import com.stehno.ersatz.encdec.DecodingContext;
import com.stehno.ersatz.encdec.RequestDecoders;
import com.stehno.ersatz.encdec.ResponseEncoders;
import com.stehno.ersatz.encdec.DecoderChain;
import org.hamcrest.Matcher;
import org.hamcrest.core.IsIterableContaining;
import java.util.LinkedList;
import java.util.function.BiFunction;
import static com.stehno.ersatz.match.ErsatzMatchers.stringIterableMatcher;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
/**
* Ersatz implementation of a Request
with request body content.
*/
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
public class ErsatzRequestWithContent extends ErsatzRequest implements RequestWithContent {
private final RequestDecoders localDecoders = new RequestDecoders();
private final DecoderChain decoderChain = new DecoderChain(localDecoders);
/**
* Creates a request with the specified method and path.
*
* @param method the request method
* @param pathMatcher the request path matcher
* @param globalDecoders the shared global decoders
* @param globalEncoders the shared global encoders
*/
public ErsatzRequestWithContent(final HttpMethod method, final Matcher pathMatcher, final RequestDecoders globalDecoders, final ResponseEncoders globalEncoders) {
super(method, pathMatcher, globalEncoders);
if (globalDecoders != null) {
decoderChain.last(globalDecoders);
}
}
public ErsatzRequestWithContent(final HttpMethod method, final Matcher pathMatcher) {
this(method, pathMatcher, null, null);
}
@Override
public RequestWithContent body(final Matcher
© 2015 - 2025 Weber Informatics LLC | Privacy Policy