kbendick commented on a change in pull request #4245: URL: https://github.com/apache/iceberg/pull/4245#discussion_r835627956
########## File path: core/src/test/java/org/apache/iceberg/rest/TestHTTPClient.java ########## @@ -0,0 +1,250 @@ +/* + * 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. + */ + +package org.apache.iceberg.rest; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.Locale; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; +import org.apache.iceberg.rest.responses.ErrorResponse; +import org.apache.iceberg.rest.responses.ErrorResponseParser; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.mockserver.integration.ClientAndServer; +import org.mockserver.model.HttpRequest; +import org.mockserver.model.HttpResponse; + +import static org.mockserver.integration.ClientAndServer.startClientAndServer; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +/*** + * Exercises the RESTClient interface, specifically over a mocked-server using the actual HttpRESTClient code. + */ +public class TestHTTPClient { + + private static final int port = 1080; + private static final String uri = String.format("http://127.0.0.1:%d", port); + private static final JsonFactory FACTORY = new JsonFactory(); + private static final ObjectMapper MAPPER = new ObjectMapper(FACTORY); + + private static ClientAndServer mockServer; + private static RESTClient restClient; + + @BeforeClass + public static void beforeClass() { + MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); + mockServer = startClientAndServer(port); + restClient = HTTPClient + .builder() + .uri(uri) + .mapper(MAPPER) + .withBearerAuth("auth_token") Review comment: It is not checked. I will add it in now. Here's the output of how the test runs after adding it in: 1. Create the expectation / assertion 2. Send the actual request (which goes through the code route) 3. ``` [MockServer-EventLog0] INFO org.mockserver.log.MockServerEventLog - 1080 creating expectation: { "id" : "2c4d5c99-c624-43f0-bac6-08e93811020d", "priority" : 0, "httpRequest" : { "method" : "POST", "path" : "/POST_success", "headers" : { "Authorization" : [ "Bearer auth_token" ] }, "body" : "{\"id\":0,\"data\":\"hank\"}" }, "times" : { "unlimited" : true }, "timeToLive" : { "unlimited" : true }, "httpResponse" : { "statusCode" : 200, "body" : "{\"id\":0,\"data\":\"hank\"}" } } with id: 2c4d5c99-c624-43f0-bac6-08e93811020d [MockServer-EventLog0] INFO org.mockserver.log.MockServerEventLog - 1080 received request: { "method" : "POST", "path" : "/POST_success", "headers" : { "Accept" : [ "application/json" ], "Content-Type" : [ "application/json" ], "Authorization" : [ "Bearer auth_token" ], "Accept-Encoding" : [ "gzip, x-gzip, deflate" ], "Content-Length" : [ "22" ], "Host" : [ "127.0.0.1:1080" ], "Connection" : [ "keep-alive" ], "User-Agent" : [ "Apache-HttpClient/5.1 (Java/11.0.12)" ] }, "keepAlive" : true, "secure" : false, "body" : { "id" : 0, "data" : "hank" } } [MockServer-EventLog0] INFO org.mockserver.log.MockServerEventLog - 1080 request: { "method" : "POST", "path" : "/POST_success", "headers" : { "Accept" : [ "application/json" ], "Content-Type" : [ "application/json" ], "Authorization" : [ "Bearer auth_token" ], "Accept-Encoding" : [ "gzip, x-gzip, deflate" ], "Content-Length" : [ "22" ], "Host" : [ "127.0.0.1:1080" ], "Connection" : [ "keep-alive" ], "User-Agent" : [ "Apache-HttpClient/5.1 (Java/11.0.12)" ] }, "keepAlive" : true, "secure" : false, "body" : { "id" : 0, "data" : "hank" } } ``` When I changed the bearer auth token to something else, the success tests all failed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
