You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
|
2 weeks ago
|
package common.ecommerce.shared.testkit;
|
||
|
3 weeks ago
|
|
||
|
|
import common.ecommerce.http.HttpResponse;
|
||
|
|
|
||
|
|
import java.util.Collections;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 测试用的快捷响应构造。
|
||
|
|
*
|
||
|
|
* <p>注意与 {@code common.ecommerce.http.Responses} 区分:那个是「状态码 → 异常」的映射,
|
||
|
|
* 这个是「直接造一个响应对象」。</p>
|
||
|
|
*/
|
||
|
|
public final class Responses {
|
||
|
|
|
||
|
|
private Responses() {
|
||
|
|
}
|
||
|
|
|
||
|
|
public static HttpResponse ok(String body) {
|
||
|
|
return HttpResponse.of(200, Collections.<String, String>emptyMap(), body, 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static HttpResponse status(int code, String body) {
|
||
|
|
return HttpResponse.of(code, Collections.<String, String>emptyMap(), body, 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static HttpResponse withHeaders(int code, java.util.Map<String, String> headers, String body) {
|
||
|
|
return HttpResponse.of(code, headers, body, 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static HttpResponse rateLimited(String retryAfterSeconds) {
|
||
|
|
return HttpResponse.of(429,
|
||
|
|
Collections.singletonMap("Retry-After", retryAfterSeconds), "", 1);
|
||
|
|
}
|
||
|
|
}
|