XAConnectionFactory { public static XAConnection createXAConnection(final DatabaseType databaseType, final XADataSource xaDataSource, final Connection connection) { switch (databaseType.getName()) { case "MySQL": return new MySQLXAConnectionWrapper().wrap(xaDataSource, connection); case "MariaDB": return new MariaDBXAConnectionWrapper().wrap(xaDataSource, connection); case "PostgreSQL": return new PostgreSQLXAConnectionWrapper().wrap(xaDataSource, connection); case "H2": return new H2XAConnectionWrapper().wrap(xaDataSource, connection); case "Oracle": return new OracleXAConnectionWrapper().wrap(xaDataSource, connection); default: throw new UnsupportedOperationException(String.format("Cannot support database type: `%s`", databaseType)); } }  static XAConnection createXAConnection(final DatabaseType databaseType, final XADataSource xaDataSource, final Connection connection);  }
@Test(expected = Exception.class) public void assertCreateMySQLXAConnection() { XAConnectionFactory.createXAConnection(DatabaseTypes.getActualDatabaseType("MySQL"), xaDataSource, connection); }
@Test(expected = Exception.class) public void assertCreateMariaDBXAConnection() { assertThat(XAConnectionFactory.createXAConnection(DatabaseTypes.getActualDatabaseType("MariaDB"), xaDataSource, connection), instanceOf(MariaXaConnection.class)); }
@Test public void assertCreatePostgreSQLXAConnection() { assertThat(XAConnectionFactory.createXAConnection(DatabaseTypes.getActualDatabaseType("PostgreSQL"), xaDataSource, connection), instanceOf(PGXAConnection.class)); }
@Test public void assertCreateH2XAConnection() { assertThat(XAConnectionFactory.createXAConnection(DatabaseTypes.getActualDatabaseType("H2"), xaDataSource, connection), instanceOf(JdbcXAConnection.class)); }
@Test @Ignore("oracle jdbc driver is not import because of the limitations of license") public void assertCreateOracleXAConnection() throws ClassNotFoundException { Class<?> clazz = Class.forName("oracle.jdbc.xa.client.OracleXAConnection"); assertThat(XAConnectionFactory.createXAConnection(DatabaseTypes.getActualDatabaseType("Oracle"), xaDataSource, connection), instanceOf(clazz)); }
@Test(expected = UnsupportedOperationException.class) public void assertCreateUnknownXAConnectionThrowsUnsupportedOperationException() { XAConnectionFactory.createXAConnection(DatabaseTypes.getActualDatabaseType("SQL92"), xaDataSource, connection); }