/*
* Copyright 2013 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.way.relational;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import br.com.objectos.way.base.sql.Credential;
import br.com.objectos.way.base.sql.Credentials;
import br.com.objectos.way.dbunit.DBUnit;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
@Test
@Guice(modules = { WayRelationalTestModule.class })
public class WayRelationalTest {
@Inject
private DBUnit dbUnit;
private Credential credential;
@BeforeClass
public void prepararDBUnit() {
dbUnit.loadDefaultDataSet();
credential = Credentials.testingOf("WAY_RELATIONAL");
}
public void standard() {
Module module = WayRelational.standardModuleUsing(credential);
Injector injector = com.google.inject.Guice.createInjector(module);
ConnectionProvider provider = injector.getInstance(ConnectionProvider.class);
ConnectionProviderC3p0 c3p0 = (ConnectionProviderC3p0) provider;
ComboPooledDataSource ds = c3p0.getDataSource();
assertThat(ds.getMaxPoolSize(), equalTo(50));
Options options = injector.getInstance(Options.class);
assertThat(options.getBatchSize(), equalTo(2000));
assertThat(options.getIterationLength(), equalTo(2000));
}
public void standard_pool_custom_options() {
Module module = WayRelational.using(credential)
.withCustomOptions()
.batchSize(10)
.iterationLength(20)
.done()
.buildModule();
Injector injector = com.google.inject.Guice.createInjector(module);
ConnectionProvider provider = injector.getInstance(ConnectionProvider.class);
ConnectionProviderC3p0 c3p0 = (ConnectionProviderC3p0) provider;
ComboPooledDataSource ds = c3p0.getDataSource();
assertThat(ds.getMaxPoolSize(), equalTo(50));
Options options = injector.getInstance(Options.class);
assertThat(options.getBatchSize(), equalTo(10));
assertThat(options.getIterationLength(), equalTo(20));
}
}