This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 d695ed5 Issue10973 (#11842)
d695ed5 is described below
commit d695ed5e6dec4aa4382230c948f392f5db409e65
Author: fwhdzh <[email protected]>
AuthorDate: Tue Aug 17 18:32:57 2021 +0800
Issue10973 (#11842)
* Migrate YAML Configuration change history from
4.1.2.Configuration Manual->YAML Configuration->Change History to
7.2.API Change History->7.2.1.ShardingSphere-JDBC->YAML Configuration;
* Add content of change history
* add unit test for DataSourceNameAwareFactory.
* add unit test for DataSourceNameAwareFactory.(modify code style)
* modify code style.
* remove useless empty line.
* Add unit test to DataSourceValidator, CreateUserStatementEventMapper and
GrantStatementEventMapper.
* Use Collection<String> to instead of Set to save a test variable.
* remove useless import
* add unit test of SQLStatementEventMapperFactory, ShardingSphereUsers and
TransactionHolder.
* modify code style
* modify code style
---
.../mapper/SQLStatementEventMapperFactoryTest.java | 43 +++++++++++++++++++++
.../metadata/user/ShardingSphereUsersTest.java | 45 ++++++++++++++++++++++
.../infra/transaction/TransactionHolderTest.java | 41 ++++++++++++++++++++
3 files changed, 129 insertions(+)
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/mapper/SQLStatementEventMapperFactoryTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/mapper/SQLStatementEventMapperFactoryTest.java
new file mode 100644
index 0000000..e3eaeba
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/mapper/SQLStatementEventMapperFactoryTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.infra.metadata.mapper;
+
+import
org.apache.shardingsphere.infra.metadata.mapper.type.CreateUserStatementEventMapper;
+import
org.apache.shardingsphere.infra.metadata.mapper.type.DropUserStatementEventMapper;
+import
org.apache.shardingsphere.infra.metadata.mapper.type.GrantStatementEventMapper;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.CreateUserStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DropUserStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.GrantStatement;
+import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterFunctionStatement;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class SQLStatementEventMapperFactoryTest {
+
+ @Test
+ public void assertNewInstance() {
+
assertThat(SQLStatementEventMapperFactory.newInstance(mock(GrantStatement.class)).get(),
instanceOf(GrantStatementEventMapper.class));
+
assertThat(SQLStatementEventMapperFactory.newInstance(mock(CreateUserStatement.class)).get(),
instanceOf(CreateUserStatementEventMapper.class));
+
assertThat(SQLStatementEventMapperFactory.newInstance(mock(DropUserStatement.class)).get(),
instanceOf(DropUserStatementEventMapper.class));
+
assertFalse(SQLStatementEventMapperFactory.newInstance(mock(AlterFunctionStatement.class)).isPresent());
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
new file mode 100644
index 0000000..e83f39e
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/user/ShardingSphereUsersTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.infra.metadata.user;
+
+import org.junit.Test;
+
+import java.util.LinkedList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShardingSphereUsersTest {
+
+ @Test
+ public void assertFindUser() {
+ Collection<ShardingSphereUser> shardingSphereUserCollection = new
LinkedList<>();
+ ShardingSphereUser shardingSphereUser = mock(ShardingSphereUser.class);
+ Grantee testGrantee = mock(Grantee.class);
+ when(shardingSphereUser.getGrantee()).thenReturn(testGrantee);
+ shardingSphereUserCollection.add(shardingSphereUser);
+ ShardingSphereUsers shardingSphereUsers = new
ShardingSphereUsers(shardingSphereUserCollection);
+ assertThat(shardingSphereUsers.findUser(testGrantee).get(),
is(shardingSphereUser));
+ Grantee notExistGrantee = mock(Grantee.class);
+ assertFalse(shardingSphereUsers.findUser(notExistGrantee).isPresent());
+ }
+}
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/transaction/TransactionHolderTest.java
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/transaction/TransactionHolderTest.java
new file mode 100644
index 0000000..da02a31
--- /dev/null
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/transaction/TransactionHolderTest.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.infra.transaction;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public final class TransactionHolderTest {
+
+ @Before
+ public void assertSetInTransaction() {
+ assertFalse(TransactionHolder.isTransaction());
+ TransactionHolder.setInTransaction();
+ assertTrue(TransactionHolder.isTransaction());
+ }
+
+ @Test
+ public void assertClear() {
+ assertTrue(TransactionHolder.isTransaction());
+ TransactionHolder.clear();
+ assertFalse(TransactionHolder.isTransaction());
+ }
+}