/* * Copyright 1999-2015 dangdang.com. *
* Licensed 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 com.dangdang.ddframe.rdb.sharding.json; import com.mysql.jdbc.Driver; import org.apache.commons.dbcp.BasicDataSource; import org.junit.Test; import javax.sql.DataSource; import java.util.HashMap; import java.util.Map; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; public final class DataSourceJsonConverterTest { private final String dataSourceMapJson = "[{\"name\":\"ds_jdbc_1\",\"clazz\":\"org.apache.commons.dbcp.BasicDataSource\",\"defaultAutoCommit\":\"true\"," + "\"defaultReadOnly\":\"false\",\"defaultTransactionIsolation\":\"-1\",\"driverClassName\":\"com.mysql.jdbc.Driver\",\"initialSize\":\"0\",\"logAbandoned\":\"false\"," + "\"maxActive\":\"8\",\"maxIdle\":\"8\",\"maxOpenPreparedStatements\":\"-1\",\"maxWait\":\"-1\",\"minEvictableIdleTimeMillis\":\"1800000\",\"minIdle\":\"0\"," + "\"numTestsPerEvictionRun\":\"3\",\"password\":\"\",\"removeAbandoned\":\"false\",\"removeAbandonedTimeout\":\"300\",\"testOnBorrow\":\"true\",\"testOnReturn\":\"false\"," + "\"testWhileIdle\":\"false\",\"timeBetweenEvictionRunsMillis\":\"-1\",\"url\":\"jdbc:mysql://localhost:3306/ds_jdbc_1\",\"username\":\"root\",\"validationQueryTimeout\":\"-1\"}," + "{\"name\":\"ds_jdbc_0\",\"clazz\":\"org.apache.commons.dbcp.BasicDataSource\",\"defaultAutoCommit\":\"true\",\"defaultReadOnly\":\"false\",\"defaultTransactionIsolation\":\"-1\"," + "\"driverClassName\":\"com.mysql.jdbc.Driver\",\"initialSize\":\"0\",\"logAbandoned\":\"false\",\"maxActive\":\"8\",\"maxIdle\":\"8\",\"maxOpenPreparedStatements\":\"-1\"," + "\"maxWait\":\"-1\",\"minEvictableIdleTimeMillis\":\"1800000\",\"minIdle\":\"0\",\"numTestsPerEvictionRun\":\"3\",\"password\":\"\",\"removeAbandoned\":\"false\"," + "\"removeAbandonedTimeout\":\"300\",\"testOnBorrow\":\"true\",\"testOnReturn\":\"false\",\"testWhileIdle\":\"false\",\"timeBetweenEvictionRunsMillis\":\"-1\"," + "\"url\":\"jdbc:mysql://localhost:3306/ds_jdbc_0\",\"username\":\"root\",\"validationQueryTimeout\":\"-1\"}]"; @Test public void assertToJson() { assertThat(DataSourceJsonConverter.toJson(createDataSourceMap()), is(dataSourceMapJson)); } @Test public void assertFromJson() { Map