com.lyncode.testy.http.matchers.HttpResponseMatcherBuilder Maven / Gradle / Ivy
package com.lyncode.testy.http.matchers;
import com.lyncode.testy.http.TestyHttpResponse;
import com.lyncode.testy.matchers.AbstractMatcherBuilder;
import org.apache.http.Header;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import static org.hamcrest.core.IsCollectionContaining.hasItem;
import static org.hamcrest.core.IsEqual.equalTo;
public class HttpResponseMatcherBuilder extends AbstractMatcherBuilder {
public HttpResponseMatcherBuilder withContent(Matcher matcher) {
return with(new FeatureMatcher(matcher, "body", "HTTP Body") {
@Override
protected String featureValueOf(TestyHttpResponse testyHttpResponse) {
return testyHttpResponse.content();
}
});
}
public HttpResponseMatcherBuilder withStatusCode(Matcher statusCodeMatcher) {
return with(new FeatureMatcher(statusCodeMatcher, "status code", "HTTP status") {
@Override
protected Integer featureValueOf(TestyHttpResponse testyHttpResponse) {
return testyHttpResponse.statusCode();
}
});
}
public HttpResponseMatcherBuilder whereHeaders(Matcher> matcher) {
return with(new FeatureMatcher>(matcher, "headers", "HTTP Headers") {
@Override
protected Iterable featureValueOf(TestyHttpResponse testyHttpResponse) {
return testyHttpResponse.headers();
}
});
}
public HttpResponseMatcherBuilder withHeader(String name, Matcher matcher) {
return whereHeaders(hasItem(new HttpHeaderMatcherBuilder().withName(equalTo(name)).withValue(matcher)));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy