Skip to content

Commit

Permalink
Rename and refactor SQL server type mapping tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hovaesco authored and findepi committed Apr 16, 2021
1 parent c40fc7c commit f78b318
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
Expand Up @@ -13,48 +13,30 @@
*/
package io.trino.plugin.sqlserver;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.Session;
import io.trino.spi.type.TimeZoneKey;
import io.trino.testing.AbstractTestQueryFramework;
import io.trino.testing.QueryRunner;
import io.trino.testing.TestingSession;
import io.trino.testing.datatype.CreateAndInsertDataSetup;
import io.trino.testing.datatype.CreateAsSelectDataSetup;
import io.trino.testing.datatype.DataSetup;
import io.trino.testing.datatype.SqlDataTypeTest;
import io.trino.testing.sql.JdbcSqlExecutor;
import io.trino.testing.sql.SqlExecutor;
import io.trino.testing.sql.TrinoSqlExecutor;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.time.ZoneId;
import java.util.Properties;

import static io.trino.plugin.sqlserver.SqlServerQueryRunner.createSqlServerQueryRunner;
import static io.trino.spi.type.TimeType.createTimeType;
import static io.trino.spi.type.TimestampType.createTimestampType;
import static io.trino.spi.type.VarbinaryType.VARBINARY;
import static java.time.ZoneOffset.UTC;

public class TestBaseSqlServerTypeMapping
public abstract class BaseSqlServerTypeMapping
extends AbstractTestQueryFramework
{
private TestingSqlServer sqlServer;

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
sqlServer = closeAfterClass(new TestingSqlServer());
sqlServer.start();
return createSqlServerQueryRunner(
sqlServer,
ImmutableMap.of(),
ImmutableMap.of(),
ImmutableList.of());
}
protected abstract SqlExecutor onRemoteDatabase();

@Test
public void testVarbinary()
Expand Down Expand Up @@ -300,26 +282,23 @@ public Object[][] testTimestampDataProvider()
};
}

private DataSetup trinoCreateAsSelect(String tableNamePrefix)
protected DataSetup trinoCreateAsSelect(String tableNamePrefix)
{
return trinoCreateAsSelect(getSession(), tableNamePrefix);
}

private DataSetup trinoCreateAsSelect(Session session, String tableNamePrefix)
protected DataSetup trinoCreateAsSelect(Session session, String tableNamePrefix)
{
return new CreateAsSelectDataSetup(new TrinoSqlExecutor(getQueryRunner(), session), tableNamePrefix);
}

private DataSetup trinoCreateAndInsert(Session session, String tableNamePrefix)
protected DataSetup trinoCreateAndInsert(Session session, String tableNamePrefix)
{
return new CreateAndInsertDataSetup(new TrinoSqlExecutor(getQueryRunner(), session), tableNamePrefix);
}

private DataSetup sqlServerCreateAndInsert(String tableNamePrefix)
protected DataSetup sqlServerCreateAndInsert(String tableNamePrefix)
{
Properties properties = new Properties();
properties.setProperty("user", sqlServer.getUsername());
properties.setProperty("password", sqlServer.getPassword());
return new CreateAndInsertDataSetup(new JdbcSqlExecutor(sqlServer.getJdbcUrl(), properties), tableNamePrefix);
return new CreateAndInsertDataSetup(onRemoteDatabase(), tableNamePrefix);
}
}
@@ -0,0 +1,46 @@
/*
* 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.sqlserver;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.trino.testing.QueryRunner;
import io.trino.testing.sql.SqlExecutor;

import static io.trino.plugin.sqlserver.SqlServerQueryRunner.createSqlServerQueryRunner;

public class TestSqlServerTypeMapping
extends BaseSqlServerTypeMapping
{
protected TestingSqlServer sqlServer;

@Override
protected QueryRunner createQueryRunner()
throws Exception
{
sqlServer = closeAfterClass(new TestingSqlServer());
sqlServer.start();
return createSqlServerQueryRunner(
sqlServer,
ImmutableMap.of(),
ImmutableMap.of(),
ImmutableList.of());
}

@Override
protected SqlExecutor onRemoteDatabase()
{
return sqlServer::execute;
}
}

0 comments on commit f78b318

Please sign in to comment.