This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 1c15289459c Add parser test for `drop mask rule` (#23467)
1c15289459c is described below
commit 1c15289459c56b61ab364caa86e73bfd3ddb87d7
Author: Zichao <[email protected]>
AuthorDate: Tue Jan 10 21:21:53 2023 +1300
Add parser test for `drop mask rule` (#23467)
* Add parser test for `drop mask rule`
* Add parser test for `drop mask rule`
---
.../rdl/drop/DropRuleStatementAssert.java | 5 +++
.../rdl/drop/impl/DropMaskRuleStatementAssert.java | 52 ++++++++++++++++++++++
.../cases/parser/jaxb/RootSQLParserTestCases.java | 4 ++
.../rule/mask/DropMaskRuleStatementTestCase.java | 41 +++++++++++++++++
.../it/parser/src/main/resources/case/rdl/drop.xml | 10 +++++
.../src/main/resources/sql/supported/rdl/drop.xml | 2 +
6 files changed, 114 insertions(+)
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/DropRuleStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/DropRuleStatementAssert.java
index 477c5f2def3..4e655960977 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/DropRuleStatementAssert.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/DropRuleStatementAssert.java
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDataba
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.DropDatabaseDiscoveryTypeStatement;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropRuleStatement;
import
org.apache.shardingsphere.encrypt.distsql.parser.statement.DropEncryptRuleStatement;
+import
org.apache.shardingsphere.mask.distsql.parser.statement.DropMaskRuleStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.DropReadwriteSplittingRuleStatement;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowAlgorithmStatement;
import
org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowRuleStatement;
@@ -41,6 +42,7 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.r
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropDatabaseDiscoveryTypeStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropDefaultShardingStrategyStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropEncryptRuleStatementAssert;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropMaskRuleStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropReadwriteSplittingRuleStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropShadowAlgorithmStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropShadowRuleStatementAssert;
@@ -50,6 +52,7 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.r
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropShardingTableReferenceRulesStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl.DropShardingTableRuleStatementAssert;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.mask.DropMaskRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.shadow.DropShadowAlgorithmStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.sharding.DropBroadcastTableRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.dbdiscovery.DropDatabaseDiscoveryHeartbeatStatementTestCase;
@@ -107,6 +110,8 @@ public final class DropRuleStatementAssert {
DropShardingKeyGeneratorStatementAssert.assertIs(assertContext,
(DropShardingKeyGeneratorStatement) actual,
(DropShardingKeyGeneratorStatementTestCase) expected);
} else if (actual instanceof DropShardingAuditorStatement) {
DropShardingAuditorStatementAssert.assertIs(assertContext,
(DropShardingAuditorStatement) actual, (DropShardingAuditorStatementTestCase)
expected);
+ } else if (actual instanceof DropMaskRuleStatement) {
+ DropMaskRuleStatementAssert.assertIs(assertContext,
(DropMaskRuleStatement) actual, (DropMaskRuleStatementTestCase) expected);
}
}
}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/impl/DropMaskRuleStatementAssert.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/impl/DropMaskRuleStatementAssert.java
new file mode 100644
index 00000000000..40a5441b76f
--- /dev/null
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/rdl/drop/impl/DropMaskRuleStatementAssert.java
@@ -0,0 +1,52 @@
+/*
+ * 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.test.it.sql.parser.internal.asserts.statement.rdl.drop.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.mask.distsql.parser.statement.DropMaskRuleStatement;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.mask.DropMaskRuleStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Drop mask rule statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DropMaskRuleStatementAssert {
+
+ /**
+ * Assert drop mask rule statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual drop mask rule statement
+ * @param expected expected drop mask rule statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final DropMaskRuleStatement actual, final DropMaskRuleStatementTestCase
expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not
exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should
exist."), actual);
+ assertThat(assertContext.getText("Mask rule assertion error: "),
actual.getTables(), is(expected.getRules()));
+ }
+ }
+}
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
index 083911ec267..6674cdd56ed 100644
---
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
@@ -353,6 +353,7 @@ import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.encrypt.DropEncryptRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.mask.AlterMaskRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.mask.CreateMaskRuleStatementTestCase;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.mask.DropMaskRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.readwritesplitting.AlterReadwriteSplittingRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.readwritesplitting.CreateReadwriteSplittingRuleStatementTestCase;
import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.readwritesplitting.DropReadwriteSplittingRuleStatementTestCase;
@@ -913,6 +914,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "alter-mask-rule")
private final List<AlterMaskRuleStatementTestCase> alterMaskRuleTestCases
= new LinkedList<>();
+ @XmlElement(name = "drop-mask-rule")
+ private final List<DropMaskRuleStatementTestCase> dropMaskRuleTestCases =
new LinkedList<>();
+
@XmlElement(name = "create-readwrite-splitting-rule")
private final List<CreateReadwriteSplittingRuleStatementTestCase>
createReadwriteSplittingRuleTestCases = new LinkedList<>();
diff --git
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/rdl/rule/mask/DropMaskRuleStatementTestCase.java
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/rdl/rule/mask/DropMaskRuleStatementTestCase.java
new file mode 100644
index 00000000000..f3038899caf
--- /dev/null
+++
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/rdl/rule/mask/DropMaskRuleStatementTestCase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.test.it.sql.parser.internal.cases.parser.jaxb.statement.rdl.rule.mask;
+
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Drop mask rule statement test case.
+ */
+@Getter
+@Setter
+public final class DropMaskRuleStatementTestCase extends SQLParserTestCase {
+
+ @XmlAttribute(name = "if-exists")
+ private boolean ifExists;
+
+ @XmlElement(name = "rule")
+ private final List<String> rules = new LinkedList<>();
+}
diff --git a/test/it/parser/src/main/resources/case/rdl/drop.xml
b/test/it/parser/src/main/resources/case/rdl/drop.xml
index d6b958f78ae..bf2a8bff781 100644
--- a/test/it/parser/src/main/resources/case/rdl/drop.xml
+++ b/test/it/parser/src/main/resources/case/rdl/drop.xml
@@ -161,4 +161,14 @@
<drop-sharding-algorithm sql-case-id="drop-sharding-algorithm"
if-exists="true">
<name>t_order_hash_mod</name>
</drop-sharding-algorithm>
+
+ <drop-mask-rule sql-case-id="drop-mask-rule" if-exists="false">
+ <rule>t_mask</rule>
+ <rule>t_order</rule>
+ </drop-mask-rule>
+
+ <drop-mask-rule sql-case-id="drop-mask-rule-if-exists" if-exists="true">
+ <rule>t_mask</rule>
+ <rule>t_order</rule>
+ </drop-mask-rule>
</sql-parser-test-cases>
diff --git a/test/it/parser/src/main/resources/sql/supported/rdl/drop.xml
b/test/it/parser/src/main/resources/sql/supported/rdl/drop.xml
index d1337fec0bb..3ae04170686 100644
--- a/test/it/parser/src/main/resources/sql/supported/rdl/drop.xml
+++ b/test/it/parser/src/main/resources/sql/supported/rdl/drop.xml
@@ -49,4 +49,6 @@
<sql-case id="drop-default-sharding-strategy" value="DROP DEFAULT SHARDING
TABLE STRATEGY" db-types="ShardingSphere" />
<sql-case id="drop-default-sharding-strategy-if-exists" value="DROP
DEFAULT SHARDING TABLE STRATEGY IF EXISTS" db-types="ShardingSphere" />
<sql-case id="drop-sharding-algorithm" value="DROP SHARDING ALGORITHM IF
EXISTS t_order_hash_mod" db-types="ShardingSphere" />
+ <sql-case id="drop-mask-rule" value="DROP MASK RULE t_mask, t_order"
db-types="ShardingSphere" />
+ <sql-case id="drop-mask-rule-if-exists" value="DROP MASK RULE IF EXISTS
t_mask, t_order" db-types="ShardingSphere" />
</sql-cases>