mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +02:00
Add tests for web whois protocols module
The web whois protocols are basically HTTP(S) server protocols. Reuse the same test structure for HTTP client protocols. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=207106520
This commit is contained in:
parent
628aacd754
commit
b8bd230061
3 changed files with 133 additions and 3 deletions
|
@ -30,7 +30,9 @@ import io.netty.handler.codec.http.FullHttpRequest;
|
|||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||
import io.netty.handler.codec.http.HttpMessage;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.handler.codec.http.cookie.ClientCookieEncoder;
|
||||
|
@ -66,6 +68,12 @@ public class TestUtils {
|
|||
return response;
|
||||
}
|
||||
|
||||
public static FullHttpResponse makeHttpResponse(HttpResponseStatus status) {
|
||||
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status);
|
||||
response.headers().setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
|
||||
return response;
|
||||
}
|
||||
|
||||
public static FullHttpRequest makeWhoisHttpRequest(
|
||||
String content, String host, String path, String accessToken) {
|
||||
FullHttpRequest request = makeHttpPostRequest(content, host, path);
|
||||
|
@ -129,10 +137,12 @@ public class TestUtils {
|
|||
* <p>This method is not type-safe, msg1 & msg2 can be a request and a response, respectively. Do
|
||||
* not use this method directly.
|
||||
*/
|
||||
private static void assertHttpMessageEquivalent(FullHttpMessage msg1, FullHttpMessage msg2) {
|
||||
private static void assertHttpMessageEquivalent(HttpMessage msg1, HttpMessage msg2) {
|
||||
assertThat(msg1.protocolVersion()).isEqualTo(msg2.protocolVersion());
|
||||
assertThat(msg1.content()).isEqualTo(msg2.content());
|
||||
assertThat(msg1.headers()).isEqualTo(msg2.headers());
|
||||
if (msg1 instanceof FullHttpRequest && msg2 instanceof FullHttpRequest) {
|
||||
assertThat(((FullHttpRequest) msg1).content()).isEqualTo(((FullHttpRequest) msg2).content());
|
||||
}
|
||||
}
|
||||
|
||||
public static void assertHttpResponseEquivalent(FullHttpResponse res1, FullHttpResponse res2) {
|
||||
|
@ -140,7 +150,7 @@ public class TestUtils {
|
|||
assertHttpMessageEquivalent(res1, res2);
|
||||
}
|
||||
|
||||
public static void assertHttpRequestEquivalent(FullHttpRequest req1, FullHttpRequest req2) {
|
||||
public static void assertHttpRequestEquivalent(HttpRequest req1, HttpRequest req2) {
|
||||
assertHttpMessageEquivalent(req1, req2);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue