Skip to content

Commit

Permalink
Refactor HikariJDBCParameterDecoratorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 5, 2020
1 parent ecbb9f2 commit 8a6c13b
Showing 1 changed file with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,37 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.decorator;

import com.zaxxer.hikari.HikariDataSource;
import org.junit.Before;
import org.junit.Test;

import java.util.Properties;

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

public final class HikariJDBCParameterDecoratorTest {

private HikariJDBCParameterDecorator hikariJDBCParameterDecorator;

@Before
public void setUp() {
hikariJDBCParameterDecorator = new HikariJDBCParameterDecorator();
}

@Test
public void assertGetTypeResultIsHikariDataSource() {
assertEquals(HikariDataSource.class, hikariJDBCParameterDecorator.getType());
assertSame(HikariDataSource.class, new HikariJDBCParameterDecorator().getType());
}

@Test
public void assertDecoratedHikariDataSource() {
HikariDataSource hikariDataSource = new HikariDataSource();
hikariJDBCParameterDecorator.decorate(hikariDataSource);
Properties properties = hikariDataSource.getDataSourceProperties();
assertThat(properties.getProperty("useServerPrepStmts"), is(Boolean.TRUE.toString()));
assertThat(properties.getProperty("cachePrepStmts"), is(Boolean.TRUE.toString()));
assertThat(properties.getProperty("prepStmtCacheSize"), is("250"));
assertThat(properties.getProperty("prepStmtCacheSqlLimit"), is("2048"));
assertThat(properties.getProperty("useLocalSessionState"), is(Boolean.TRUE.toString()));
assertThat(properties.getProperty("rewriteBatchedStatements"), is(Boolean.TRUE.toString()));
assertThat(properties.getProperty("cacheResultSetMetadata"), is(Boolean.FALSE.toString()));
assertThat(properties.getProperty("cacheServerConfiguration"), is(Boolean.TRUE.toString()));
assertThat(properties.getProperty("elideSetAutoCommits"), is(Boolean.TRUE.toString()));
assertThat(properties.getProperty("maintainTimeStats"), is(Boolean.FALSE.toString()));
assertThat(properties.getProperty("netTimeoutForStreamingResults"), is("0"));
assertThat(properties.getProperty("tinyInt1isBit"), is(Boolean.FALSE.toString()));
new HikariJDBCParameterDecorator().decorate(hikariDataSource);
Properties props = hikariDataSource.getDataSourceProperties();
assertThat(props.getProperty("useServerPrepStmts"), is(Boolean.TRUE.toString()));
assertThat(props.getProperty("cachePrepStmts"), is(Boolean.TRUE.toString()));
assertThat(props.getProperty("prepStmtCacheSize"), is("250"));
assertThat(props.getProperty("prepStmtCacheSqlLimit"), is("2048"));
assertThat(props.getProperty("useLocalSessionState"), is(Boolean.TRUE.toString()));
assertThat(props.getProperty("rewriteBatchedStatements"), is(Boolean.TRUE.toString()));
assertThat(props.getProperty("cacheResultSetMetadata"), is(Boolean.FALSE.toString()));
assertThat(props.getProperty("cacheServerConfiguration"), is(Boolean.TRUE.toString()));
assertThat(props.getProperty("elideSetAutoCommits"), is(Boolean.TRUE.toString()));
assertThat(props.getProperty("maintainTimeStats"), is(Boolean.FALSE.toString()));
assertThat(props.getProperty("netTimeoutForStreamingResults"), is("0"));
assertThat(props.getProperty("tinyInt1isBit"), is(Boolean.FALSE.toString()));
}
}

0 comments on commit 8a6c13b

Please sign in to comment.