singhpk234 commented on code in PR #13400: URL: https://github.com/apache/iceberg/pull/13400#discussion_r2583334337
########## core/src/test/java/org/apache/iceberg/rest/RESTCatalogTestInfrastructure.java: ########## @@ -0,0 +1,225 @@ +/* + * 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 static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import java.io.File; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.file.Path; +import java.util.Map; +import java.util.UUID; +import java.util.function.Consumer; +import org.apache.hadoop.conf.Configuration; +import org.apache.iceberg.CatalogProperties; +import org.apache.iceberg.catalog.SessionCatalog; +import org.apache.iceberg.inmemory.InMemoryCatalog; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.apache.iceberg.rest.responses.ErrorResponse; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.gzip.GzipHandler; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.mockito.Mockito; + +public class RESTCatalogTestInfrastructure { + protected static final ObjectMapper MAPPER = RESTObjectMapper.mapper(); + + protected RESTCatalog restCatalog; + protected InMemoryCatalog backendCatalog; + protected Server httpServer; + protected RESTCatalogAdapter adapterForRESTServer; + protected ParserContext parserContext; + + public void before(Path temp) throws Exception { + File warehouse = temp.toFile(); + + this.backendCatalog = new InMemoryCatalog(); + this.backendCatalog.initialize( + "in-memory", + ImmutableMap.of(CatalogProperties.WAREHOUSE_LOCATION, warehouse.getAbsolutePath())); + + HTTPHeaders catalogHeaders = + HTTPHeaders.of( + Map.of( + "Authorization", + "Bearer client-credentials-token:sub=catalog", + "test-header", + "test-value")); + HTTPHeaders contextHeaders = + HTTPHeaders.of( + Map.of( + "Authorization", + "Bearer client-credentials-token:sub=user", + "test-header", + "test-value")); + + adapterForRESTServer = + Mockito.spy( + new RESTCatalogAdapter(backendCatalog) { + @Override + public <T extends RESTResponse> T execute( + HTTPRequest request, + Class<T> responseType, + Consumer<ErrorResponse> errorHandler, + Consumer<Map<String, String>> responseHeaders) { + // this doesn't use a Mockito spy because this is used for catalog tests, which have + // different method calls + if (!ResourcePaths.tokens().equals(request.path())) { Review Comment: I see ~100 lines of code getting duplicate hence wanted to move them to a common class that both can use, i removed the infra class, please let me know what you think now. -- 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]
