/*
 * Licensed 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 io.trino.plugin.iceberg;

import io.trino.spi.connector.ConnectorFactory;
import io.trino.testing.TestingConnectorContext;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;

import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static java.nio.file.Files.createTempDirectory;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class TestIcebergPlugin
{
    private Path tempDirectory;

    @BeforeClass
    public void setup()
            throws IOException
    {
        tempDirectory = createTempDirectory(getClass().getSimpleName());
    }

    @AfterClass(alwaysRun = true)
    public void tearDown()
            throws IOException
    {
        deleteRecursively(tempDirectory, ALLOW_INSECURE);
    }

    @Test
    public void testCreateConnector()
    {
        ConnectorFactory factory = getConnectorFactory();
        // simplest possible configuration
        factory.create("test", Map.of("hive.metastore.uri", "thrift://foo:1234"), new TestingConnectorContext()).shutdown();
    }

    @Test
    public void testThriftMetastore()
    {
        ConnectorFactory factory = getConnectorFactory();

        factory.create(
                "test",
                Map.of(
                        "hive.metastore", "thrift",
                        "hive.metastore.uri", "thrift://foo:1234"),
                new TestingConnectorContext())
                .shutdown();
    }

    @Test
    public void testGlueMetastore()
    {
        ConnectorFactory factory = getConnectorFactory();

        factory.create(
                "test",
                Map.of(
                        "hive.metastore", "glue",
                        "hive.metastore.glue.region", "us-east-2"),
                new TestingConnectorContext())
                .shutdown();

        assertThatThrownBy(() -> factory.create(
                "test",
                Map.of(
                        "hive.metastore", "glue",
                        "hive.metastore.uri", "thrift://foo:1234"),
                new TestingConnectorContext()))
                .hasMessageContaining("Error: Configuration property 'hive.metastore.uri' was not used");
    }

    @Test
    public void testRecordingMetastore()
    {
        ConnectorFactory factory = getConnectorFactory();

        // recording with thrift
        factory.create(
                "test",
                Map.of(
                        "hive.metastore", "thrift",
                        "hive.metastore.uri", "thrift://foo:1234",
                        "hive.metastore-recording-path", "/tmp"),
                new TestingConnectorContext())
                .shutdown();

        // recording with glue
        factory.create(
                "test",
                Map.of(
                        "hive.metastore", "glue",
                        "hive.metastore.glue.region", "us-east-2",
                        "hive.metastore-recording-path", "/tmp"),
                new TestingConnectorContext())
                .shutdown();
    }

    private static ConnectorFactory getConnectorFactory()
    {
        return getOnlyElement(new IcebergPlugin().getConnectorFactories());
    }
}

@@ -720,889 +720,203 @@
 ons.
-AfterClass;%0Aimport org.testng.annotations.BeforeClass;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.io.IOException;%0Aimport java.nio.file.Path;%0Aimport java.util.Map;%0A%0Aimport static com.google.common.collect.Iterables.getOnlyElement;%0Aimport static com.google.common.io.MoreFiles.deleteRecursively;%0Aimport static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;%0Aimport static java.nio.file.Files.createTempDirectory;%0Aimport static org.assertj.core.api.Assertions.assertThatThrownBy;%0A%0Apublic class TestIcebergPlugin%0A%7B%0A    private Path tempDirectory;%0A%0A    @BeforeClass%0A    public void setup()%0A            throws IOException%0A    %7B%0A        tempDirectory = createTempDirectory(getClass().getSimpleName());%0A    %7D%0A%0A    @AfterClass(alwaysRun = true)%0A    public void tearDown()%0A            throws IOException%0A    %7B%0A        deleteRecursively(tempDirectory, ALLOW_INSECURE);%0A    %7D%0A
+Test;%0A%0Aimport java.util.Map;%0A%0Aimport static com.google.common.collect.Iterables.getOnlyElement;%0Aimport static org.assertj.core.api.Assertions.assertThatThrownBy;%0A%0Apublic class TestIcebergPlugin%0A%7B
 %0A   

Remove redundant test resource from TestIcebergPlugin