net.gcolin.httpquery.mock.MockHttpHandler Maven / Gradle / Ivy
/**
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
* ====================================================================
*
* @author Gael COLIN
*/
package net.gcolin.httpquery.mock;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import net.gcolin.httpquery.Http;
import net.gcolin.httpquery.HttpHandler;
import net.gcolin.httpquery.Request;
import net.gcolin.httpquery.RequestWithPayload;
public class MockHttpHandler implements HttpHandler {
private Map gets = new HashMap();
private Map deletes = new HashMap();
private Map traces = new HashMap();
private Map heads = new HashMap();
private Map options = new HashMap();
private Map- , RequestWithPayload> putsObject = new HashMap
- , RequestWithPayload>();
private Map
- , Request> putsByte = new HashMap
- , Request>();
private Map
- , Request> putsString = new HashMap
- , Request>();
private Map
- , Request> putsInputStream = new HashMap
- , Request>();
private Map
- , RequestWithPayload> postsObject = new HashMap
- , RequestWithPayload>();
private Map
- , Request> postsByte = new HashMap
- , Request>();
private Map
- , Request> postsString = new HashMap
- , Request>();
private Map
- , Request> postsInputStream = new HashMap
- , Request>();
private static MockHttpHandler instance;
public static void bind(boolean b) {
if (b) {
instance = new MockHttpHandler();
Http.setHandler(instance);
} else {
Http.initHandler();
}
}
public static MockHttpHandler getInstance() {
return instance;
}
public Map
getGets() {
return gets;
}
public Map getDeletes() {
return deletes;
}
public Map getTraces() {
return traces;
}
public Map getHeads() {
return heads;
}
public Map getOptions() {
return options;
}
public Map- , RequestWithPayload> getPutsObject() {
return putsObject;
}
public Map
- , Request> getPutsByte() {
return putsByte;
}
public Map
- , Request> getPutsString() {
return putsString;
}
public Map
- , Request> getPutsInputStream() {
return putsInputStream;
}
public Map
- , RequestWithPayload> getPostsObject() {
return postsObject;
}
public Map
- , Request> getPostsByte() {
return postsByte;
}
public Map
- , Request> getPostsString() {
return postsString;
}
public Map
- , Request> getPostsInputStream() {
return postsInputStream;
}
@Override
public Request get(String uri) {
return gets.get(uri);
}
@Override
public Request delete(String uri) {
return deletes.get(uri);
}
@Override
public RequestWithPayload put(String uri, Object obj) {
return putsObject.get(new Item
(uri, obj));
}
@Override
public Request put(String uri, byte[] data) {
return putsByte.get(new Item(uri, data));
}
@Override
public Request put(String uri, String str) {
return putsString.get(new Item(uri, str));
}
@Override
public Request put(String uri, InputStream inStream) {
return putsInputStream
.get(new Item(uri, inStream));
}
@Override
public RequestWithPayload post(String uri, Object obj) {
return postsObject.get(new Item(uri, obj));
}
@Override
public Request post(String uri, byte[] data) {
return postsByte.get(new Item(uri, data));
}
@Override
public Request post(String uri, InputStream inStream) {
return postsInputStream
.get(new Item(uri, inStream));
}
@Override
public Request post(String uri, String str) {
return postsString.get(new Item(uri, str));
}
@Override
public Request trace(String uri) {
return traces.get(uri);
}
@Override
public Request head(String uri) {
return heads.get(uri);
}
@Override
public Request options(String uri) {
return options.get(uri);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy