com.github.dreamhead.moco.resource.reader.TemplateRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moco-core Show documentation
Show all versions of moco-core Show documentation
Moco is an easy setup stub framework, mainly focusing on testing and integration.
package com.github.dreamhead.moco.resource.reader;
import com.github.dreamhead.moco.HttpProtocolVersion;
import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.Request;
import com.github.dreamhead.moco.model.DefaultHttpRequest;
import com.github.dreamhead.moco.model.MessageContent;
import com.google.common.collect.ImmutableMap;
public class TemplateRequest {
private Request request;
public TemplateRequest(final Request request) {
this.request = request;
}
public MessageContent getContent() {
return this.request.getContent();
}
public HttpProtocolVersion getVersion() {
if (this.request instanceof HttpRequest) {
return ((HttpRequest) this.request).getVersion();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
public ImmutableMap getHeaders() {
if (this.request instanceof HttpRequest) {
return ((HttpRequest) this.request).getHeaders();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
public String getUri() {
if (this.request instanceof HttpRequest) {
return ((HttpRequest) this.request).getUri();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
public String getMethod() {
if (this.request instanceof HttpRequest) {
return ((HttpRequest) this.request).getMethod();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
public ImmutableMap getQueries() {
if (this.request instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) this.request;
ImmutableMap.Builder builder = ImmutableMap.builder();
ImmutableMap queries = httpRequest.getQueries();
for (String key : queries.keySet()) {
builder.put(key, queries.get(key)[0]);
}
return builder.build();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
public ImmutableMap getForms() {
if (this.request instanceof DefaultHttpRequest) {
return ((DefaultHttpRequest) this.request).getForms();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
public ImmutableMap getCookies() {
if (this.request instanceof DefaultHttpRequest) {
return ((DefaultHttpRequest) this.request).getCookies();
}
throw new IllegalArgumentException("Request is not HTTP request");
}
}