| 21478 |
rajender |
1 |
/*
|
|
|
2 |
* Copyright (C) 2011 The Android Open Source Project
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
package com.android.volley.mock;
|
|
|
18 |
|
|
|
19 |
import com.android.volley.NetworkResponse;
|
|
|
20 |
import com.android.volley.Request;
|
|
|
21 |
import com.android.volley.Response;
|
|
|
22 |
import com.android.volley.Response.ErrorListener;
|
|
|
23 |
import com.android.volley.VolleyError;
|
|
|
24 |
import com.android.volley.utils.CacheTestUtils;
|
|
|
25 |
|
|
|
26 |
import java.util.HashMap;
|
|
|
27 |
import java.util.Map;
|
|
|
28 |
|
|
|
29 |
public class MockRequest extends Request<byte[]> {
|
|
|
30 |
public MockRequest() {
|
|
|
31 |
super(Request.Method.GET, "http://foo.com", null);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public MockRequest(String url, ErrorListener listener) {
|
|
|
35 |
super(Request.Method.GET, url, listener);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
private Map<String, String> mPostParams = new HashMap<String, String>();
|
|
|
39 |
|
|
|
40 |
public void setPostParams(Map<String, String> postParams) {
|
|
|
41 |
mPostParams = postParams;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
@Override
|
|
|
45 |
public Map<String, String> getPostParams() {
|
|
|
46 |
return mPostParams;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private String mCacheKey = super.getCacheKey();
|
|
|
50 |
|
|
|
51 |
public void setCacheKey(String cacheKey) {
|
|
|
52 |
mCacheKey = cacheKey;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@Override
|
|
|
56 |
public String getCacheKey() {
|
|
|
57 |
return mCacheKey;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public boolean deliverResponse_called = false;
|
|
|
61 |
public boolean parseResponse_called = false;
|
|
|
62 |
|
|
|
63 |
@Override
|
|
|
64 |
protected void deliverResponse(byte[] response) {
|
|
|
65 |
deliverResponse_called = true;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
public boolean deliverError_called = false;
|
|
|
69 |
|
|
|
70 |
@Override
|
|
|
71 |
public void deliverError(VolleyError error) {
|
|
|
72 |
super.deliverError(error);
|
|
|
73 |
deliverError_called = true;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public boolean cancel_called = false;
|
|
|
77 |
|
|
|
78 |
@Override
|
|
|
79 |
public void cancel() {
|
|
|
80 |
cancel_called = true;
|
|
|
81 |
super.cancel();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
private Priority mPriority = super.getPriority();
|
|
|
85 |
|
|
|
86 |
public void setPriority(Priority priority) {
|
|
|
87 |
mPriority = priority;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
@Override
|
|
|
91 |
public Priority getPriority() {
|
|
|
92 |
return mPriority;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
@Override
|
|
|
96 |
protected Response<byte[]> parseNetworkResponse(NetworkResponse response) {
|
|
|
97 |
parseResponse_called = true;
|
|
|
98 |
return Response.success(response.data, CacheTestUtils.makeRandomCacheEntry(response.data));
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
}
|