terrymanu commented on code in PR #17920:
URL: https://github.com/apache/shardingsphere/pull/17920#discussion_r900931965


##########
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/DataBaseTypeFixture.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.transaction.xa.fixture;
+
+import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+
+public final class DataBaseTypeFixture implements DatabaseType {

Review Comment:
   Database is one word, please do not use `DataBase`



##########
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/XAConnectionWrapperFixture.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.transaction.xa.fixture;
+
+import lombok.SneakyThrows;
+import 
org.apache.shardingsphere.transaction.xa.jta.connection.XAConnectionWrapper;
+
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+public final class XAConnectionWrapperFixture implements XAConnectionWrapper {

Review Comment:
   Is it necessary to impl such complex fixture?



##########
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/XAConnectionWrapperDataBaseTypeFixture.java:
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.transaction.xa.fixture;
+
+import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Optional;
+
+public final class XAConnectionWrapperDataBaseTypeFixture implements 
DatabaseType {

Review Comment:
   Database is one word, please do not use `DataBase`



##########
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/XAConnectionWrapperFactoryTest.java:
##########
@@ -17,17 +17,46 @@
 
 package org.apache.shardingsphere.transaction.xa.jta.connection;
 
+import com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection;
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
-import 
org.apache.shardingsphere.transaction.xa.jta.connection.dialect.H2XAConnectionWrapper;
+import org.apache.shardingsphere.transaction.xa.fixture.DataSourceUtils;
+import 
org.apache.shardingsphere.transaction.xa.fixture.XAConnectionWrapperFixture;
+import 
org.apache.shardingsphere.transaction.xa.fixture.XADataSourceDefinitionFixture;
+import 
org.apache.shardingsphere.transaction.xa.jta.datasource.swapper.DataSourceSwapper;
 import org.junit.Test;
 
+import javax.sql.DataSource;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public final class XAConnectionWrapperFactoryTest {
     
     @Test
-    public void assertGetInstance() {
-        
assertThat(XAConnectionWrapperFactory.getInstance(DatabaseTypeFactory.getInstance("H2")),
 instanceOf(H2XAConnectionWrapper.class));
+    public void assertGetInstance() throws SQLException {
+        XAConnectionWrapper xaConnectionWrapperFixTrue = new 
XAConnectionWrapperFixture();
+        XAConnection actual = 
xaConnectionWrapperFixTrue.wrap(createXADataSource(), mockConnection());
+        assertThat(actual.getXAResource(), 
instanceOf(JDBC4MysqlXAConnection.class));
+    }
+    
+    private XADataSource createXADataSource() {
+        DatabaseType databaseType = DatabaseTypeFactory.getInstance("FIXTURE");
+        DataSource dataSource = DataSourceUtils.build(HikariDataSource.class, 
databaseType, "foo_ds");
+        XADataSourceDefinitionFixture xaDataSourceDefinitionFixTure = new 
XADataSourceDefinitionFixture();

Review Comment:
   How about use mock if fixture is not for SPI test?



##########
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/XAConnectionWrapperFactoryTest.java:
##########
@@ -17,17 +17,46 @@
 
 package org.apache.shardingsphere.transaction.xa.jta.connection;
 
+import com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection;
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
-import 
org.apache.shardingsphere.transaction.xa.jta.connection.dialect.H2XAConnectionWrapper;
+import org.apache.shardingsphere.transaction.xa.fixture.DataSourceUtils;
+import 
org.apache.shardingsphere.transaction.xa.fixture.XAConnectionWrapperFixture;
+import 
org.apache.shardingsphere.transaction.xa.fixture.XADataSourceDefinitionFixture;
+import 
org.apache.shardingsphere.transaction.xa.jta.datasource.swapper.DataSourceSwapper;
 import org.junit.Test;
 
+import javax.sql.DataSource;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public final class XAConnectionWrapperFactoryTest {
     
     @Test
-    public void assertGetInstance() {
-        
assertThat(XAConnectionWrapperFactory.getInstance(DatabaseTypeFactory.getInstance("H2")),
 instanceOf(H2XAConnectionWrapper.class));
+    public void assertGetInstance() throws SQLException {
+        XAConnectionWrapper xaConnectionWrapperFixTrue = new 
XAConnectionWrapperFixture();
+        XAConnection actual = 
xaConnectionWrapperFixTrue.wrap(createXADataSource(), mockConnection());
+        assertThat(actual.getXAResource(), 
instanceOf(JDBC4MysqlXAConnection.class));
+    }
+    
+    private XADataSource createXADataSource() {
+        DatabaseType databaseType = DatabaseTypeFactory.getInstance("FIXTURE");
+        DataSource dataSource = DataSourceUtils.build(HikariDataSource.class, 
databaseType, "foo_ds");
+        XADataSourceDefinitionFixture xaDataSourceDefinitionFixTure = new 
XADataSourceDefinitionFixture();

Review Comment:
   Typo variable name `xaDataSourceDefinitionFixTure`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to