Skip to content

Commit

Permalink
code clear
Browse files Browse the repository at this point in the history
  • Loading branch information
beijing-penguin committed Nov 19, 2019
1 parent c48844e commit 1728ecb
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 195 deletions.
Expand Up @@ -19,8 +19,6 @@

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;


/**
Expand All @@ -29,8 +27,6 @@
* @author duanchao
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceInfo {

Expand Down
Expand Up @@ -35,13 +35,9 @@ public final class ShardingSphereDataSourceMetaDataTest {
@Before
public void setUp() {
final Map<String, DataSourceInfo> dataSourceInfoMap = new HashMap<String, DataSourceInfo>();
DataSourceInfo info0 = new DataSourceInfo();
info0.setUrl("jdbc:mysql://127.0.0.1:3306/db_0");
info0.setUsername("test");
DataSourceInfo info0 = new DataSourceInfo("jdbc:mysql://127.0.0.1:3306/db_0", "test");

DataSourceInfo info1 = new DataSourceInfo();
info1.setUrl("jdbc:mysql://127.0.0.1:3306/db_1");
info1.setUsername("test");
DataSourceInfo info1 = new DataSourceInfo("jdbc:mysql://127.0.0.1:3306/db_1", "test");

dataSourceInfoMap.put("ds_0", info0);
dataSourceInfoMap.put("ds_1", info1);
Expand Down
Expand Up @@ -17,29 +17,19 @@

package org.apache.shardingsphere.core.metadata.datasource.dialect;

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Before;
import org.junit.Test;

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

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Test;

public final class H2DataSourceMetaDataTest {

private DataSourceInfo dataSourceInfo;

@Before
public void setUp() {
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setUrl("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
dataSourceInfo.setUsername("test");
}

@Test
public void assertDataSourceInfoParam() {
H2DataSourceMetaData actual = new H2DataSourceMetaData(dataSourceInfo);
H2DataSourceMetaData actual = new H2DataSourceMetaData(new DataSourceInfo("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "test"));
assertThat(actual.getHostName(), is(""));
assertThat(actual.getPort(), is(-1));
assertThat(actual.getCatalog(), is("ds_0"));
Expand All @@ -48,24 +38,23 @@ public void assertDataSourceInfoParam() {

@Test
public void assertGetPropertiesWithMem() {
H2DataSourceMetaData actual = new H2DataSourceMetaData(dataSourceInfo);
H2DataSourceMetaData actual = new H2DataSourceMetaData(new DataSourceInfo("jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "test"));
assertThat(actual.getHostName(), is(""));
assertThat(actual.getPort(), is(-1));
assertEquals(actual.getSchemaName(), null);
}

@Test
public void assertGetPropertiesWithSymbol() {
dataSourceInfo.setUrl("jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
H2DataSourceMetaData actual = new H2DataSourceMetaData(dataSourceInfo);
H2DataSourceMetaData actual = new H2DataSourceMetaData(new DataSourceInfo("jdbc:h2:~:ds-0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "test"));
assertThat(actual.getHostName(), is(""));
assertThat(actual.getPort(), is(-1));
assertEquals(actual.getSchemaName(), null);
}

@Test(expected = UnrecognizedDatabaseURLException.class)
public void assertGetPropertiesFailure() {
dataSourceInfo.setUrl("jdbc:h2:file:/data/sample");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:h2:file:/data/sample", "test");
new H2DataSourceMetaData(dataSourceInfo);
}
}
Expand Up @@ -17,28 +17,19 @@

package org.apache.shardingsphere.core.metadata.datasource.dialect;

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Before;
import org.junit.Test;

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

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Test;

public final class MySQLDataSourceMetaDataTest {

private DataSourceInfo dataSourceInfo;

@Before
public void setUp() {
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setUsername("test");
}

@Test
public void assertDataSourceInfoParam() {
dataSourceInfo.setUrl("jdbc:mysql://127.0.0.1:9999/ds_0?serverTimezone=UTC&useSSL=false");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:mysql://127.0.0.1:9999/ds_0?serverTimezone=UTC&useSSL=false", "test");
MySQLDataSourceMetaData actual = new MySQLDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(9999));
Expand All @@ -48,7 +39,7 @@ public void assertDataSourceInfoParam() {

@Test
public void assertGetPropertiesWithPort() {
dataSourceInfo.setUrl("jdbc:mysql://127.0.0.1:9999/ds_0?serverTimezone=UTC&useSSL=false");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:mysql://127.0.0.1:9999/ds_0?serverTimezone=UTC&useSSL=false", "test");
MySQLDataSourceMetaData actual = new MySQLDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(9999));
Expand All @@ -58,7 +49,7 @@ public void assertGetPropertiesWithPort() {

@Test
public void assertGetPropertiesWithDefaultPort() {
dataSourceInfo.setUrl("jdbc:mysql:loadbalance://127.0.0.1/ds_0?serverTimezone=UTC&useSSL=false");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:mysql:loadbalance://127.0.0.1/ds_0?serverTimezone=UTC&useSSL=false", "test");
MySQLDataSourceMetaData actual = new MySQLDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(3306));
Expand All @@ -67,7 +58,7 @@ public void assertGetPropertiesWithDefaultPort() {

@Test(expected = UnrecognizedDatabaseURLException.class)
public void assertGetPropertiesFailure() {
dataSourceInfo.setUrl("jdbc:mysql:xxxxxxxx");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:mysql:xxxxxxxx", "test");
new MySQLDataSourceMetaData(dataSourceInfo);
}
}
Expand Up @@ -17,28 +17,19 @@

package org.apache.shardingsphere.core.metadata.datasource.dialect;

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Before;
import org.junit.Test;

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

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Test;

public final class OracleDataSourceMetaDataTest {

private DataSourceInfo dataSourceInfo;

@Before
public void setUp() {
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setUsername("test");
}

@Test
public void assertDataSourceInfoParam() {
dataSourceInfo.setUrl("jdbc:oracle:thin:@//127.0.0.1:9999/ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:oracle:thin:@//127.0.0.1:9999/ds_0", "test");
OracleDataSourceMetaData actual = new OracleDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(9999));
Expand All @@ -48,15 +39,15 @@ public void assertDataSourceInfoParam() {

@Test
public void assertGetPropertiesWithPort() {
dataSourceInfo.setUrl("jdbc:oracle:thin:@//127.0.0.1:9999/ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:oracle:thin:@//127.0.0.1:9999/ds_0", "test");
OracleDataSourceMetaData actual = new OracleDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(9999));
}

@Test
public void assertGetPropertiesWithDefaultPort() {
dataSourceInfo.setUrl("jdbc:oracle:oci:@127.0.0.1/ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:oracle:oci:@127.0.0.1/ds_0", "test");
OracleDataSourceMetaData actual = new OracleDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(1521));
Expand All @@ -65,7 +56,7 @@ public void assertGetPropertiesWithDefaultPort() {

@Test(expected = UnrecognizedDatabaseURLException.class)
public void assertGetPropertiesFailure() {
dataSourceInfo.setUrl("jdbc:oracle:xxxxxxxx");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:oracle:xxxxxxxx", "test");
new OracleDataSourceMetaData(dataSourceInfo);
}
}
Expand Up @@ -17,27 +17,19 @@

package org.apache.shardingsphere.core.metadata.datasource.dialect;

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Before;
import org.junit.Test;

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

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Test;

public final class PostgreSQLDataSourceMetaDataTest {
private DataSourceInfo dataSourceInfo;

@Before
public void setUp() {
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setUsername("test");
}

@Test
public void assertDataSourceInfoParam() {
dataSourceInfo.setUrl("jdbc:postgresql://127.0.0.1:9999/ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:postgresql://127.0.0.1:9999/ds_0", "test");
PostgreSQLDataSourceMetaData actual = new PostgreSQLDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(9999));
Expand All @@ -47,7 +39,7 @@ public void assertDataSourceInfoParam() {

@Test
public void assertGetPropertiesWithPort() {
dataSourceInfo.setUrl("jdbc:postgresql://127.0.0.1:9999/ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:postgresql://127.0.0.1:9999/ds_0", "test");
PostgreSQLDataSourceMetaData actual = new PostgreSQLDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(9999));
Expand All @@ -56,7 +48,7 @@ public void assertGetPropertiesWithPort() {

@Test
public void assertGetPropertiesWithDefaultPort() {
dataSourceInfo.setUrl("jdbc:postgresql://127.0.0.1/ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:postgresql://127.0.0.1/ds_0", "test");
PostgreSQLDataSourceMetaData actual = new PostgreSQLDataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is("127.0.0.1"));
assertThat(actual.getPort(), is(5432));
Expand All @@ -66,7 +58,7 @@ public void assertGetPropertiesWithDefaultPort() {

@Test(expected = UnrecognizedDatabaseURLException.class)
public void assertGetPropertiesFailure() {
dataSourceInfo.setUrl("jdbc:postgresql:xxxxxxxx");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:postgresql:xxxxxxxx", "test");
new PostgreSQLDataSourceMetaData(dataSourceInfo);
}
}
Expand Up @@ -23,23 +23,13 @@

import org.apache.shardingsphere.core.metadata.datasource.exception.UnrecognizedDatabaseURLException;
import org.apache.shardingsphere.spi.database.DataSourceInfo;
import org.junit.Before;
import org.junit.Test;

public final class SQL92DataSourceMetaDataTest {

private DataSourceInfo dataSourceInfo;

@Before
public void setUp() {
dataSourceInfo = new DataSourceInfo();
dataSourceInfo.setUrl("jdbc:sql92_db:ds_0");
dataSourceInfo.setUsername("test");
}

@Test
public void assertDataSourceInfoParam() {
dataSourceInfo.setUrl("jdbc:sql92_db:ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:sql92_db:ds_0", "test");
SQL92DataSourceMetaData actual = new SQL92DataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is(""));
assertThat(actual.getPort(), is(-1));
Expand All @@ -49,7 +39,7 @@ public void assertDataSourceInfoParam() {

@Test
public void assertGetProperties() {
dataSourceInfo.setUrl("jdbc:sql92_db:ds_0");
DataSourceInfo dataSourceInfo = new DataSourceInfo("jdbc:sql92_db:ds_0", "test");
SQL92DataSourceMetaData actual = new SQL92DataSourceMetaData(dataSourceInfo);
assertThat(actual.getHostName(), is(""));
assertThat(actual.getPort(), is(-1));
Expand All @@ -59,7 +49,7 @@ public void assertGetProperties() {

@Test(expected = UnrecognizedDatabaseURLException.class)
public void assertGetPropertiesFailure() {
dataSourceInfo.setUrl("xxx:xxxx:xxxxxxxx");
DataSourceInfo dataSourceInfo = new DataSourceInfo("xxx:xxxx:xxxxxxxx", "test");
new SQL92DataSourceMetaData(dataSourceInfo);
}
}

0 comments on commit 1728ecb

Please sign in to comment.