Skip to content

Commit

Permalink
Merge pull request #2856 from FujiwaraTakumi/dev
Browse files Browse the repository at this point in the history
add unit test cases about mariadb;
  • Loading branch information
terrymanu committed Aug 15, 2019
2 parents 6f6da87 + 165883c commit a67c09f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.apache.shardingsphere.core.database.DatabaseTypes;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Test;
import org.mariadb.jdbc.MariaDbDataSource;
import org.postgresql.xa.PGXADataSource;

import javax.sql.XADataSource;
Expand All @@ -35,7 +36,13 @@ public void assertCreateH2XADataSource() {
XADataSource xaDataSource = XADataSourceFactory.build(DatabaseTypes.getActualDatabaseType("H2"));
assertThat(xaDataSource, instanceOf(JdbcDataSource.class));
}


@Test
public void assertCreateMariaDBXADataSource() {
XADataSource xaDataSource = XADataSourceFactory.build(DatabaseTypes.getActualDatabaseType("MariaDB"));
assertThat(xaDataSource, instanceOf(MariaDbDataSource.class));
}

@Test
public void assertCreatePGXADataSource() {
XADataSource xaDataSource = XADataSourceFactory.build(DatabaseTypes.getActualDatabaseType("PostgreSQL"));
Expand Down
Expand Up @@ -18,11 +18,7 @@
package org.apache.shardingsphere.transaction.xa.jta.datasource.properties;

import org.apache.shardingsphere.core.database.DatabaseTypes;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.dialect.H2XADataSourceDefinition;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.dialect.MySQLXADataSourceDefinition;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.dialect.OracleXADataSourceDefinition;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.dialect.PostgreSQLXADataSourceDefinition;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.dialect.SQLServerXADataSourceDefinition;
import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.dialect.*;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.instanceOf;
Expand All @@ -39,6 +35,11 @@ public void assertCreateXAPropertiesForH2() {
public void assertCreateXAPropertiesForMySQL() {
assertThat(XADataSourceDefinitionFactory.getXADataSourceDefinition(DatabaseTypes.getActualDatabaseType("MySQL")), instanceOf(MySQLXADataSourceDefinition.class));
}

@Test
public void assertCreateXAPropertiesForMariaDB() {
assertThat(XADataSourceDefinitionFactory.getXADataSourceDefinition(DatabaseTypes.getActualDatabaseType("MariaDB")), instanceOf(MariaDBXADataSourceDefinition.class));
}

@Test
public void assertCreateXAPropertiesForPostgreSQL() {
Expand Down
@@ -0,0 +1,49 @@
/*
* 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.jta.datasource.properties.dialect;

import org.apache.shardingsphere.core.config.DatabaseAccessConfiguration;
import org.hamcrest.CoreMatchers;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public final class MariaDBXADataSourceDefinitionTest {

@Test
public void assertGetXADriverClassName() {
assertThat(new MariaDBXADataSourceDefinition().getXADriverClassName(),
CoreMatchers.<Collection<String>>is(Arrays.asList(org.mariadb.jdbc.MariaDbDataSource.class.getName())));
}

@Test
public void assertGetXAProperties() {
Properties actual = new MariaDBXADataSourceDefinition().getXAProperties(new DatabaseAccessConfiguration("jdbc:mysql://127.0.0.1:3306/demo", "root", "root"));
assertThat(actual.getProperty("user"), is("root"));
assertThat(actual.getProperty("password"), is("root"));
assertThat(actual.getProperty("url"), is("jdbc:mysql://127.0.0.1:3306/demo"));
assertThat(actual.getProperty("ServerName"), is("127.0.0.1"));
assertThat(actual.getProperty("port"), is("3306"));
assertThat(actual.getProperty("DatabaseName"), is("demo"));
}
}

0 comments on commit a67c09f

Please sign in to comment.