by.stub.yaml.StubRequestBuilder Maven / Gradle / Ivy
package by.stub.yaml;
import by.stub.utils.ReflectionUtils;
import by.stub.yaml.stubs.StubRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author Alexander Zagniotov
* @since 4/14/13, 4:54 PM
*/
final class StubRequestBuilder implements StubBuilder {
private final Map fieldNameAndValues;
private String url;
private List method;
private String post;
private Map headers;
private Map query;
private File file;
StubRequestBuilder() {
this.url = null;
this.method = new ArrayList();
this.post = null;
this.file = null;
this.headers = new LinkedHashMap();
this.query = new LinkedHashMap();
this.fieldNameAndValues = new HashMap();
}
@Override
public void store(final String fieldName, final Object fieldValue) {
fieldNameAndValues.put(fieldName.toLowerCase(), fieldValue);
}
@Override
public StubRequest build() throws Exception {
ReflectionUtils.injectObjectFields(this, fieldNameAndValues);
return new StubRequest(url, post, file, method, headers, query);
}
}