From 22340f0244fa7066cd918e0a71c36352713746d5 Mon Sep 17 00:00:00 2001 From: wenshao Date: Wed, 17 Apr 2013 21:48:28 +0800 Subject: [PATCH] add testcase --- .../sql/postgresql/PGCreateTableTest_0.java | 57 +++++++++++++++++++ .../sql/postgresql/PGCreateTableTest_1.java | 57 +++++++++++++++++++ .../sql/postgresql/PGCreateTableTest_2.java | 57 +++++++++++++++++++ .../sql/postgresql/PGCreateTableTest_3.java | 57 +++++++++++++++++++ .../sql/postgresql/PGCreateTableTest_4.java | 57 +++++++++++++++++++ 5 files changed, 285 insertions(+) create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_0.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_1.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_2.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_3.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_4.java diff --git a/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_0.java b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_0.java new file mode 100644 index 0000000000..9c13cb75b5 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_0.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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 com.alibaba.druid.bvt.sql.postgresql; + +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.druid.sql.PGTest; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser; +import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor; +import com.alibaba.druid.stat.TableStat; + +public class PGCreateTableTest_0 extends PGTest { + + public void test_0() throws Exception { + String sql = "CREATE TABLE my_first_table (" + // + " first_column text," + // + " second_column integer" + // + ");"; + + PGSQLStatementParser parser = new PGSQLStatementParser(sql); + List statementList = parser.parseStatementList(); + SQLStatement statemen = statementList.get(0); + print(statementList); + + Assert.assertEquals(1, statementList.size()); + + PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); + statemen.accept(visitor); + + System.out.println("Tables : " + visitor.getTables()); + System.out.println("fields : " + visitor.getColumns()); + + Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("my_first_table"))); + + Assert.assertTrue(visitor.getTables().get(new TableStat.Name("my_first_table")).getCreateCount() == 1); + + Assert.assertTrue(visitor.getColumns().size() == 2); + } + + +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_1.java b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_1.java new file mode 100644 index 0000000000..aa55e107ff --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_1.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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 com.alibaba.druid.bvt.sql.postgresql; + +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.druid.sql.PGTest; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser; +import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor; +import com.alibaba.druid.stat.TableStat; + +public class PGCreateTableTest_1 extends PGTest { + + public void test_0() throws Exception { + String sql = "CREATE TABLE products (" + // + " product_no integer," + // + " name text," + // + " price numeric" + // + ");"; + + PGSQLStatementParser parser = new PGSQLStatementParser(sql); + List statementList = parser.parseStatementList(); + SQLStatement statemen = statementList.get(0); + print(statementList); + + Assert.assertEquals(1, statementList.size()); + + PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); + statemen.accept(visitor); + + System.out.println("Tables : " + visitor.getTables()); + System.out.println("fields : " + visitor.getColumns()); + + Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products"))); + + Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getCreateCount() == 1); + + Assert.assertTrue(visitor.getColumns().size() == 3); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_2.java b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_2.java new file mode 100644 index 0000000000..61655cb2df --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_2.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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 com.alibaba.druid.bvt.sql.postgresql; + +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.druid.sql.PGTest; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser; +import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor; +import com.alibaba.druid.stat.TableStat; + +public class PGCreateTableTest_2 extends PGTest { + + public void test_0() throws Exception { + String sql = "CREATE TABLE products (" + // + " product_no integer," + // + " name text," + // + " price numeric DEFAULT 9.99" + // + ");"; + + PGSQLStatementParser parser = new PGSQLStatementParser(sql); + List statementList = parser.parseStatementList(); + SQLStatement statemen = statementList.get(0); + print(statementList); + + Assert.assertEquals(1, statementList.size()); + + PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); + statemen.accept(visitor); + + System.out.println("Tables : " + visitor.getTables()); + System.out.println("fields : " + visitor.getColumns()); + + Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products"))); + + Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getCreateCount() == 1); + + Assert.assertTrue(visitor.getColumns().size() == 3); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_3.java b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_3.java new file mode 100644 index 0000000000..e53dc21244 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_3.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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 com.alibaba.druid.bvt.sql.postgresql; + +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.druid.sql.PGTest; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser; +import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor; +import com.alibaba.druid.stat.TableStat; + +public class PGCreateTableTest_3 extends PGTest { + + public void test_0() throws Exception { + String sql = "CREATE TABLE products (" + // + " product_no integer," + // + " name text," + // + " price numeric DEFAULT nextval('products_product_no_seq')" + // + ");"; + + PGSQLStatementParser parser = new PGSQLStatementParser(sql); + List statementList = parser.parseStatementList(); + SQLStatement statemen = statementList.get(0); + print(statementList); + + Assert.assertEquals(1, statementList.size()); + + PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); + statemen.accept(visitor); + + System.out.println("Tables : " + visitor.getTables()); + System.out.println("fields : " + visitor.getColumns()); + + Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products"))); + + Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getCreateCount() == 1); + + Assert.assertTrue(visitor.getColumns().size() == 3); + } + +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_4.java b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_4.java new file mode 100644 index 0000000000..b7d2adeb24 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/postgresql/PGCreateTableTest_4.java @@ -0,0 +1,57 @@ +/* + * Copyright 1999-2011 Alibaba Group Holding Ltd. + * + * 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 com.alibaba.druid.bvt.sql.postgresql; + +import java.util.List; + +import org.junit.Assert; + +import com.alibaba.druid.sql.PGTest; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.dialect.postgresql.parser.PGSQLStatementParser; +import com.alibaba.druid.sql.dialect.postgresql.visitor.PGSchemaStatVisitor; +import com.alibaba.druid.stat.TableStat; + +public class PGCreateTableTest_4 extends PGTest { + + public void test_0() throws Exception { + String sql = "CREATE TABLE products (" + // + " product_no integer," + // + " name text," + // + " price numeric CHECK (price > 0)" + // + ");"; + + PGSQLStatementParser parser = new PGSQLStatementParser(sql); + List statementList = parser.parseStatementList(); + SQLStatement statemen = statementList.get(0); + print(statementList); + + Assert.assertEquals(1, statementList.size()); + + PGSchemaStatVisitor visitor = new PGSchemaStatVisitor(); + statemen.accept(visitor); + + System.out.println("Tables : " + visitor.getTables()); + System.out.println("fields : " + visitor.getColumns()); + + Assert.assertTrue(visitor.getTables().containsKey(new TableStat.Name("products"))); + + Assert.assertTrue(visitor.getTables().get(new TableStat.Name("products")).getCreateCount() == 1); + + Assert.assertTrue(visitor.getColumns().size() == 3); + } + +}