From 50896d15c092490fed3fafa623cdcd910634f759 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sun, 29 Sep 2024 00:01:34 +0800 Subject: [PATCH] Add test cases on TimestampLoadingSQLProvider (#33042) * Add test cases on TimestampLoadingSQLProvider * Add test cases on TimestampLoadingSQLProvider --- .../MySQLTimestampLoadingSQLProviderTest.java | 42 +++++++++++++++++++ ...OracleTimestampLoadingSQLProviderTest.java | 42 +++++++++++++++++++ ...greSQLTimestampLoadingSQLProviderTest.java | 42 +++++++++++++++++++ ...ServerTimestampLoadingSQLProviderTest.java | 42 +++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/MySQLTimestampLoadingSQLProviderTest.java create mode 100644 kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/OracleTimestampLoadingSQLProviderTest.java create mode 100644 kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/PostgreSQLTimestampLoadingSQLProviderTest.java create mode 100644 kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/SQLServerTimestampLoadingSQLProviderTest.java diff --git a/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/MySQLTimestampLoadingSQLProviderTest.java b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/MySQLTimestampLoadingSQLProviderTest.java new file mode 100644 index 0000000000000..2d99170db746c --- /dev/null +++ b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/MySQLTimestampLoadingSQLProviderTest.java @@ -0,0 +1,42 @@ +/* + * 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.shardingsphere.timeservice.type.database.provider.dialect; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.timeservice.type.database.provider.TimestampLoadingSQLProvider; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class MySQLTimestampLoadingSQLProviderTest { + + private TimestampLoadingSQLProvider provider; + + @BeforeEach + void setUp() { + provider = TypedSPILoader.getService(TimestampLoadingSQLProvider.class, TypedSPILoader.getService(DatabaseType.class, "MySQL")); + } + + @Test + void assertGetTimestampLoadingSQL() { + assertThat(provider.getTimestampLoadingSQL(), is("SELECT NOW()")); + } +} diff --git a/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/OracleTimestampLoadingSQLProviderTest.java b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/OracleTimestampLoadingSQLProviderTest.java new file mode 100644 index 0000000000000..8bbd575938914 --- /dev/null +++ b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/OracleTimestampLoadingSQLProviderTest.java @@ -0,0 +1,42 @@ +/* + * 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.shardingsphere.timeservice.type.database.provider.dialect; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.timeservice.type.database.provider.TimestampLoadingSQLProvider; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class OracleTimestampLoadingSQLProviderTest { + + private TimestampLoadingSQLProvider provider; + + @BeforeEach + void setUp() { + provider = TypedSPILoader.getService(TimestampLoadingSQLProvider.class, TypedSPILoader.getService(DatabaseType.class, "Oracle")); + } + + @Test + void assertGetTimestampLoadingSQL() { + assertThat(provider.getTimestampLoadingSQL(), is("SELECT sysdate FROM DUAL")); + } +} diff --git a/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/PostgreSQLTimestampLoadingSQLProviderTest.java b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/PostgreSQLTimestampLoadingSQLProviderTest.java new file mode 100644 index 0000000000000..2754d0c255f17 --- /dev/null +++ b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/PostgreSQLTimestampLoadingSQLProviderTest.java @@ -0,0 +1,42 @@ +/* + * 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.shardingsphere.timeservice.type.database.provider.dialect; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.timeservice.type.database.provider.TimestampLoadingSQLProvider; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class PostgreSQLTimestampLoadingSQLProviderTest { + + private TimestampLoadingSQLProvider provider; + + @BeforeEach + void setUp() { + provider = TypedSPILoader.getService(TimestampLoadingSQLProvider.class, TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); + } + + @Test + void assertGetTimestampLoadingSQL() { + assertThat(provider.getTimestampLoadingSQL(), is("SELECT NOW()")); + } +} diff --git a/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/SQLServerTimestampLoadingSQLProviderTest.java b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/SQLServerTimestampLoadingSQLProviderTest.java new file mode 100644 index 0000000000000..cb928d2e73f69 --- /dev/null +++ b/kernel/time-service/type/database/src/test/java/org/apache/shardingsphere/timeservice/type/database/provider/dialect/SQLServerTimestampLoadingSQLProviderTest.java @@ -0,0 +1,42 @@ +/* + * 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.shardingsphere.timeservice.type.database.provider.dialect; + +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.timeservice.type.database.provider.TimestampLoadingSQLProvider; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +class SQLServerTimestampLoadingSQLProviderTest { + + private TimestampLoadingSQLProvider provider; + + @BeforeEach + void setUp() { + provider = TypedSPILoader.getService(TimestampLoadingSQLProvider.class, TypedSPILoader.getService(DatabaseType.class, "SQLServer")); + } + + @Test + void assertGetTimestampLoadingSQL() { + assertThat(provider.getTimestampLoadingSQL(), is("SELECT GETDATE()")); + } +}