import org.sonar.api.rules.Violation;
import org.sonar.api.violations.ViolationQuery;
import org.sonar.batch.index.ResourcePersister;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.review.ReviewDao;
import org.sonar.core.review.ReviewDto;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-public class ReviewWorkflowDecoratorTest extends DaoTestCase {
+public class ReviewWorkflowDecoratorTest extends AbstractDaoTestCase {
private ReviewWorkflowDecorator decorator;
private ReviewNotifications notifications;
* @return true if the database has been created, false if this database is not supported
*/
public boolean createDatabase() {
- if (DdlUtils.supportsDialect(database.getDialect().getId())) {
- LoggerFactory.getLogger(getClass()).info("Create database");
- SqlSession session = myBatis.openSession();
- Connection connection = session.getConnection();
+ if (!DdlUtils.supportsDialect(database.getDialect().getId())) {
+ return false;
+ }
+
+ LoggerFactory.getLogger(getClass()).info("Create database");
+ SqlSession session = null;
+ Connection connection = null;
+ try {
+ session = myBatis.openSession();
+ connection = session.getConnection();
+ DdlUtils.createSchema(connection, database.getDialect().getId());
+ } finally {
try {
- DdlUtils.createSchema(connection, database.getDialect().getId());
- } finally {
- try {
- MyBatis.closeQuietly(session);
+ MyBatis.closeQuietly(session);
- // The connection is probably already closed by session.close()
- // but it's not documented in mybatis javadoc.
+ // The connection is probably already closed by session.close()
+ // but it's not documented in mybatis javadoc.
+ if (null != connection) {
connection.close();
- } catch (Exception e) {
- // ignore
}
+ } catch (Exception e) {
+ // ignore
}
- return true;
}
- return false;
+ return true;
}
}
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class ActiveDashboardDaoTest extends DaoTestCase {
+public class ActiveDashboardDaoTest extends AbstractDaoTestCase {
private ActiveDashboardDao dao;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Date;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-public class DashboardDaoTest extends DaoTestCase {
+public class DashboardDaoTest extends AbstractDaoTestCase {
private DashboardDao dao;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.MyBatis;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-public class DependencyMapperTest extends DaoTestCase {
+public class DependencyMapperTest extends AbstractDaoTestCase {
@Test
public void should_find_all() {
setupData("fixture");
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.MyBatis;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-public class ResourceSnapshotMapperTest extends DaoTestCase {
+public class ResourceSnapshotMapperTest extends AbstractDaoTestCase {
@Test
public void should_find_all() {
setupData("fixture");
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class DuplicationDaoTest extends DaoTestCase {
+public class DuplicationDaoTest extends AbstractDaoTestCase {
private DuplicationDao dao;
import org.sonar.core.filter.FilterColumnDto;
import org.sonar.core.filter.FilterDao;
import org.sonar.core.filter.FilterDto;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.fest.assertions.Assertions.assertThat;
-public class FilterDaoTest extends DaoTestCase {
+public class FilterDaoTest extends AbstractDaoTestCase {
private FilterDao dao;
@Before
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.persistence;
+
+import com.google.common.collect.Maps;
+import com.google.common.io.Closeables;
+import org.dbunit.Assertion;
+import org.dbunit.DataSourceDatabaseTester;
+import org.dbunit.DatabaseUnitException;
+import org.dbunit.IDatabaseTester;
+import org.dbunit.database.DatabaseConfig;
+import org.dbunit.database.IDatabaseConnection;
+import org.dbunit.dataset.DataSetException;
+import org.dbunit.dataset.IDataSet;
+import org.dbunit.dataset.ITable;
+import org.dbunit.dataset.ReplacementDataSet;
+import org.dbunit.dataset.filter.DefaultColumnFilter;
+import org.dbunit.dataset.xml.FlatXmlDataSet;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.sonar.api.config.Settings;
+
+import java.io.InputStream;
+import java.sql.SQLException;
+
+import static org.junit.Assert.fail;
+
+public abstract class AbstractDaoTestCase {
+ private static Database database;
+ private static MyBatis myBatis;
+ private static DatabaseCommands databaseCommands;
+
+ private IDatabaseTester databaseTester;
+ private IDatabaseConnection connection;
+
+ @BeforeClass
+ public static void startDatabase() throws Exception {
+ Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties()));
+
+ boolean hasDialect = settings.hasKey("sonar.jdbc.dialect");
+ if (hasDialect) {
+ database = new DefaultDatabase(settings);
+ } else {
+ database = new H2Database();
+ }
+ database.start();
+
+ myBatis = new MyBatis(database);
+ myBatis.start();
+
+ databaseCommands = DatabaseCommands.forDialect(database.getDialect());
+ }
+
+ @Before
+ public void setupDbUnit() throws SQLException {
+ databaseCommands.truncateDatabase(myBatis.openSession().getConnection());
+ databaseTester = new DataSourceDatabaseTester(database.getDataSource());
+ }
+
+ @After
+ public void stopConnection() throws Exception {
+ if (databaseTester != null) {
+ databaseTester.onTearDown();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ }
+
+ @AfterClass
+ public static void stopDatabase() {
+ if (database != null) {
+ database.stop();
+ }
+ }
+
+ protected MyBatis getMyBatis() {
+ return myBatis;
+ }
+
+ protected void setupData(String testName) {
+ InputStream stream = null;
+ try {
+ String className = getClass().getName();
+ className = String.format("/%s/%s.xml", className.replace(".", "/"), testName);
+ stream = getClass().getResourceAsStream(className);
+ if (stream == null) {
+ throw new RuntimeException("Test not found :" + className);
+ }
+
+ setupData(stream);
+ } finally {
+ Closeables.closeQuietly(stream);
+ }
+ }
+
+ private void setupData(InputStream dataStream) {
+ try {
+ ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(dataStream));
+ dataSet.addReplacementObject("[null]", null);
+ dataSet.addReplacementObject("[false]", databaseCommands.getFalse());
+ dataSet.addReplacementObject("[true]", databaseCommands.getTrue());
+
+ databaseTester.setDataSet(dataSet);
+ connection = databaseTester.getConnection();
+
+ connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
+ databaseCommands.getDbunitDatabaseOperation().execute(connection, databaseTester.getDataSet());
+
+ } catch (Exception e) {
+ throw translateException("Could not setup DBUnit data", e);
+ }
+ }
+
+ protected void checkTables(String testName, String... tables) {
+ checkTables(testName, new String[] {}, tables);
+ }
+
+ protected void checkTables(String testName, String[] excludedColumnNames, String... tables) {
+ try {
+ IDataSet dataSet = getCurrentDataSet();
+ IDataSet expectedDataSet = getExpectedData(testName);
+ for (String table : tables) {
+ ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
+ Assertion.assertEquals(expectedDataSet.getTable(table), filteredTable);
+ }
+ } catch (DataSetException e) {
+ throw translateException("Error while checking results", e);
+ } catch (DatabaseUnitException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ protected void assertEmptyTables(String... emptyTables) {
+ for (String table : emptyTables) {
+ try {
+ Assert.assertEquals("Table " + table + " not empty.", 0, getCurrentDataSet().getTable(table).getRowCount());
+ } catch (DataSetException e) {
+ throw translateException("Error while checking results", e);
+ }
+ }
+ }
+
+ private IDataSet getExpectedData(String testName) {
+ String className = getClass().getName();
+ className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName);
+
+ InputStream in = getClass().getResourceAsStream(className);
+ try {
+ return getData(in);
+ } finally {
+ Closeables.closeQuietly(in);
+ }
+ }
+
+ private IDataSet getData(InputStream stream) {
+ try {
+ ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
+ dataSet.addReplacementObject("[null]", null);
+ dataSet.addReplacementObject("[false]", databaseCommands.getFalse());
+ dataSet.addReplacementObject("[true]", databaseCommands.getTrue());
+ return dataSet;
+ } catch (Exception e) {
+ throw translateException("Could not read the dataset stream", e);
+ }
+ }
+
+ private IDataSet getCurrentDataSet() {
+ try {
+ return connection.createDataSet();
+ } catch (SQLException e) {
+ throw translateException("Could not create the current dataset", e);
+ }
+ }
+
+ private static RuntimeException translateException(String msg, Exception cause) {
+ RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
+ runtimeException.setStackTrace(cause.getStackTrace());
+ return runtimeException;
+ }
+
+ protected IDatabaseConnection getConnection() {
+ return connection;
+ }
+}
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.core.persistence;
-
-import com.google.common.collect.Maps;
-import org.apache.commons.io.IOUtils;
-import org.dbunit.Assertion;
-import org.dbunit.DataSourceDatabaseTester;
-import org.dbunit.DatabaseUnitException;
-import org.dbunit.IDatabaseTester;
-import org.dbunit.database.DatabaseConfig;
-import org.dbunit.database.IDatabaseConnection;
-import org.dbunit.dataset.CompositeDataSet;
-import org.dbunit.dataset.DataSetException;
-import org.dbunit.dataset.IDataSet;
-import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.ReplacementDataSet;
-import org.dbunit.dataset.filter.DefaultColumnFilter;
-import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.sonar.api.config.Settings;
-
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.sql.SQLException;
-
-import static org.junit.Assert.fail;
-
-public abstract class DaoTestCase {
-
- private static Database database;
- private static MyBatis myBatis;
- private static DatabaseCommands databaseCommands;
-
- private IDatabaseTester databaseTester;
- private IDatabaseConnection connection;
-
- @BeforeClass
- public static void startDatabase() throws Exception {
- Settings settings = new Settings();
- settings.setProperties(Maps.fromProperties(System.getProperties()));
- boolean hasDialect = settings.hasKey("sonar.jdbc.dialect");
-
- if (hasDialect) {
- database = new DefaultDatabase(settings);
- } else {
- database = new H2Database();
- }
- database.start();
-
- myBatis = new MyBatis(database);
- myBatis.start();
-
- databaseCommands = DatabaseCommands.forDialect(database.getDialect());
- }
-
- @Before
- public void setupDbUnit() throws SQLException {
- databaseCommands.truncateDatabase(myBatis.openSession().getConnection());
- databaseTester = new DataSourceDatabaseTester(database.getDataSource());
- }
-
- @After
- public void tearDownDbUnit() throws Exception {
- if (databaseTester != null) {
- databaseTester.onTearDown();
- }
- if (connection != null) {
- connection.close();
- }
- }
-
- @AfterClass
- public static void stopDatabase() {
- if (database != null) {
- database.stop();
- }
- }
-
- protected MyBatis getMyBatis() {
- return myBatis;
- }
-
- protected final void setupData(String... testNames) {
- InputStream[] streams = new InputStream[testNames.length];
- try {
- for (int i = 0; i < testNames.length; i++) {
- String className = getClass().getName();
- className = String.format("/%s/%s.xml", className.replace(".", "/"), testNames[i]);
- streams[i] = getClass().getResourceAsStream(className);
- if (streams[i] == null) {
- throw new RuntimeException("Test not found :" + className);
- }
- }
-
- setupData(streams);
-
- } finally {
- for (InputStream stream : streams) {
- IOUtils.closeQuietly(stream);
- }
- }
- }
-
- protected final void setupData(InputStream... dataSetStream) {
- try {
- IDataSet[] dataSets = new IDataSet[dataSetStream.length];
- for (int i = 0; i < dataSetStream.length; i++) {
- ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(dataSetStream[i]));
- dataSet.addReplacementObject("[null]", null);
- dataSet.addReplacementObject("[false]", databaseCommands.getFalse());
- dataSet.addReplacementObject("[true]", databaseCommands.getTrue());
- dataSets[i] = dataSet;
- }
- CompositeDataSet compositeDataSet = new CompositeDataSet(dataSets);
-
- databaseTester.setDataSet(compositeDataSet);
- connection = databaseTester.getConnection();
-
- connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory());
- databaseCommands.getDbunitDatabaseOperation().execute(connection, databaseTester.getDataSet());
-
- } catch (Exception e) {
- throw translateException("Could not setup DBUnit data", e);
- }
- }
-
- protected final void checkTables(String testName, String... tables) {
- checkTables(testName, new String[] {}, tables);
- }
-
- protected final void checkTables(String testName, String[] excludedColumnNames, String... tables) {
- try {
- IDataSet dataSet = getCurrentDataSet();
- IDataSet expectedDataSet = getExpectedData(testName);
- for (String table : tables) {
- ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
- Assertion.assertEquals(expectedDataSet.getTable(table), filteredTable);
- }
- } catch (DataSetException e) {
- throw translateException("Error while checking results", e);
- } catch (DatabaseUnitException e) {
- fail(e.getMessage());
- }
- }
-
- protected final void assertEmptyTables(String... emptyTables) {
- for (String table : emptyTables) {
- try {
- Assert.assertEquals("Table " + table + " not empty.", 0, getCurrentDataSet().getTable(table).getRowCount());
- } catch (DataSetException e) {
- throw translateException("Error while checking results", e);
- }
- }
- }
-
- protected final IDataSet getExpectedData(String testName) {
- String className = getClass().getName();
- className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName);
-
- InputStream in = getClass().getResourceAsStream(className);
- try {
- return getData(in);
- } finally {
- IOUtils.closeQuietly(in);
- }
- }
-
- protected final IDataSet getData(InputStream stream) {
- try {
- ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
- dataSet.addReplacementObject("[null]", null);
- dataSet.addReplacementObject("[false]", databaseCommands.getFalse());
- dataSet.addReplacementObject("[true]", databaseCommands.getTrue());
- return dataSet;
- } catch (Exception e) {
- throw translateException("Could not read the dataset stream", e);
- }
- }
-
- protected final IDataSet getCurrentDataSet() {
- try {
- return connection.createDataSet();
- } catch (SQLException e) {
- throw translateException("Could not create the current dataset", e);
- }
- }
-
- protected String getCurrentDataSetAsXML() {
- return getDataSetAsXML(getCurrentDataSet());
- }
-
- protected String getDataSetAsXML(IDataSet dataset) {
- try {
- StringWriter writer = new StringWriter();
- FlatXmlDataSet.write(dataset, writer);
- return writer.getBuffer().toString();
- } catch (Exception e) {
- throw translateException("Could not build XML from dataset", e);
- }
- }
-
- private static RuntimeException translateException(String msg, Exception cause) {
- RuntimeException runtimeException = new RuntimeException(String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
- runtimeException.setStackTrace(cause.getStackTrace());
- return runtimeException;
- }
-
- protected IDatabaseConnection getConnection() {
- return connection;
- }
-
- protected IDatabaseTester getDatabaseTester() {
- return databaseTester;
- }
-
-}
public void should_list_all_dao_classes() {
List<Class<?>> daoClasses = DaoUtils.getDaoClasses();
- assertThat(daoClasses.size()).isGreaterThan(1);
+ assertThat(daoClasses).isNotEmpty();
}
}
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
-public class DatabaseVersionTest extends DaoTestCase {
+public class DatabaseVersionTest extends AbstractDaoTestCase {
@Test
public void getVersion() {
setupData("getVersion");
Connection connection = DriverManager.getConnection("jdbc:h2:mem:sonar_test");
DdlUtils.createSchema(connection, "h2");
- int tables = countTables(connection);
+ int tableCount = countTables(connection);
connection.close();
- assertThat(tables).isGreaterThan(30);
+ assertThat(tableCount).isGreaterThan(30);
}
- private int countTables(Connection connection) throws SQLException {
+ static int countTables(Connection connection) throws SQLException {
int count = 0;
ResultSet resultSet = connection.getMetaData().getTables(null, null, null, new String[] {"TABLE"});
while (resultSet.next()) {
DefaultDatabase db = new DefaultDatabase(settings);
db.start();
+ db.stop();
assertThat(db.getDialect().getId(), Is.is("h2"));
assertThat(((BasicDataSource) db.getDataSource()).getMaxActive(), Is.is(1));
public Properties getHibernateProperties() {
Properties properties = new Properties();
properties.put("hibernate.hbm2ddl.auto", "validate");
- properties.put(Environment.DIALECT, getDialect().getHibernateDialectClass().getName());
properties.put(Environment.CONNECTION_PROVIDER, CustomHibernateConnectionProvider.class.getName());
return properties;
}
import org.junit.Test;
import java.sql.Connection;
-import java.sql.ResultSet;
import java.sql.SQLException;
import static org.fest.assertions.Assertions.assertThat;
@Test
public void shouldExecuteDdlAtStartup() throws SQLException {
Connection connection = db.getDataSource().getConnection();
-
- int tables = 0;
- ResultSet resultSet = connection.getMetaData().getTables(null, null, null, new String[] {"TABLE"});
- while (resultSet.next()) {
- tables++;
- }
-
+ int tableCount = DdlUtilsTest.countTables(connection);
connection.close();
- assertThat(tables).isGreaterThan(30);
+ assertThat(tableCount).isGreaterThan(30);
}
@Test
public void shouldLimitThePoolSize() {
- assertThat(((BasicDataSource) db.getDataSource()).getMaxActive()).isEqualTo(2);
- assertThat(((BasicDataSource) db.getDataSource()).getMaxIdle()).isEqualTo(2);
+ BasicDataSource dataSource = (BasicDataSource) db.getDataSource();
+
+ assertThat(dataSource.getMaxActive()).isEqualTo(2);
+ assertThat(dataSource.getMaxIdle()).isEqualTo(2);
}
}
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.List;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class PropertiesDaoTest extends DaoTestCase {
+public class PropertiesDaoTest extends AbstractDaoTestCase {
private PropertiesDao dao;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.MyBatis;
import java.util.Arrays;
-public class PurgeCommandsTest extends DaoTestCase {
+public class PurgeCommandsTest extends AbstractDaoTestCase {
/**
* Test that all related data is deleted.
*/
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.resources.Scopes;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.resource.ResourceDao;
import static org.junit.Assert.assertThat;
import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
-public class PurgeDaoTest extends DaoTestCase {
+public class PurgeDaoTest extends AbstractDaoTestCase {
private PurgeDao dao;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.List;
import static org.fest.assertions.Assertions.assertThat;
-public class ResourceDaoTest extends DaoTestCase {
+public class ResourceDaoTest extends AbstractDaoTestCase {
private ResourceDao dao;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.sql.Connection;
import java.sql.ResultSet;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertThat;
-public class ResourceIndexerDaoTest extends DaoTestCase {
+public class ResourceIndexerDaoTest extends AbstractDaoTestCase {
private static ResourceIndexerDao dao;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Map;
import static org.fest.assertions.Assertions.assertThat;
-public class ResourceKeyUpdaterDaoTest extends DaoTestCase {
+public class ResourceKeyUpdaterDaoTest extends AbstractDaoTestCase {
@Rule
public ExpectedException thrown = ExpectedException.none();
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Date;
-public class ReviewCommentDaoTest extends DaoTestCase {
+public class ReviewCommentDaoTest extends AbstractDaoTestCase {
private ReviewCommentDao dao;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.utils.DateUtils;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Collection;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
-public class ReviewDaoTest extends DaoTestCase {
+public class ReviewDaoTest extends AbstractDaoTestCase {
private ReviewDao dao;
import org.hamcrest.core.Is;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.List;
import static org.junit.Assert.assertThat;
-public class RuleDaoTest extends DaoTestCase {
+public class RuleDaoTest extends AbstractDaoTestCase {
private static RuleDao dao;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class LoadedTemplateDaoTest extends DaoTestCase {
+public class LoadedTemplateDaoTest extends AbstractDaoTestCase {
private LoadedTemplateDao dao;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
-public class AuthorDaoTest extends DaoTestCase {
+public class AuthorDaoTest extends AbstractDaoTestCase {
private AuthorDao dao;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.workflow.Comment;
import org.sonar.api.workflow.internal.DefaultReview;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import java.util.Arrays;
import java.util.Date;
import static org.fest.assertions.Assertions.assertThat;
-public class ReviewDatabaseStoreTest extends DaoTestCase {
+public class ReviewDatabaseStoreTest extends AbstractDaoTestCase {
@Test
public void store() {
+++ /dev/null
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2012 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.jpa.session;
-
-import org.junit.Test;
-
-public class ThreadLocalDatabaseSessionFactoryTest {
-
-
- @Test
- public void shouldCreateOneSessionPerThread() {
-// final MemoryDatabaseConnector connector = new MemoryDatabaseConnector();
-// connector.start();
-// final DatabaseSessionFactory factory = new ThreadLocalDatabaseSessionFactory(connector);
-//
-// final DatabaseSession junitThreadSession = factory.getSession();
-// assertTrue(junitThreadSession == factory.getSession());
-//
-// new Thread() {
-// @Override
-// public void run() {
-// DatabaseSession threadSession = factory.getSession();
-// assertTrue(threadSession != junitThreadSession);
-// }
-//
-// }.start();
- }
-
-}
*/
package org.sonar.jpa.test;
+import org.junit.AfterClass;
+
import org.apache.commons.io.IOUtils;
import org.dbunit.Assertion;
import org.dbunit.DataSourceDatabaseTester;
import static org.junit.Assert.fail;
/**
- * Heavily duplicates DaoTestCase as long as Hibernate is in use.
+ * Heavily duplicates AbstractDaoTestCase as long as Hibernate is in use.
*/
public abstract class AbstractDbUnitTestCase {
private static Database database;
}
}
- public DatabaseSession getSession() {
+ @AfterClass
+ public static void stopDatabase() {
+ if (database != null) {
+ database.stop();
+ }
+ }
+
+ protected DatabaseSession getSession() {
return session;
}
- public DatabaseSessionFactory getSessionFactory() {
+ protected DatabaseSessionFactory getSessionFactory() {
return new DatabaseSessionFactory() {
public DatabaseSession getSession() {
};
}
- protected final void setupData(String... testNames) {
+ protected void setupData(String... testNames) {
InputStream[] streams = new InputStream[testNames.length];
try {
for (int i = 0; i < testNames.length; i++) {
}
}
- private final void setupData(InputStream... dataSetStream) {
+ private void setupData(InputStream... dataSetStream) {
try {
IDataSet[] dataSets = new IDataSet[dataSetStream.length];
for (int i = 0; i < dataSetStream.length; i++) {
}
}
- protected final void checkTables(String testName, String... tables) {
+ protected void checkTables(String testName, String... tables) {
checkTables(testName, new String[0], tables);
}
- protected final void checkTables(String testName, String[] excludedColumnNames, String... tables) {
+ protected void checkTables(String testName, String[] excludedColumnNames, String... tables) {
getSession().commit();
try {
IDataSet dataSet = getCurrentDataSet();
}
}
- private final IDataSet getExpectedData(String testName) {
+ private IDataSet getExpectedData(String testName) {
String className = getClass().getName();
className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName);
}
}
- private final IDataSet getData(InputStream stream) {
+ private IDataSet getData(InputStream stream) {
try {
ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream));
dataSet.addReplacementObject("[null]", null);
}
}
- private final IDataSet getCurrentDataSet() {
+ private IDataSet getCurrentDataSet() {
try {
return connection.createDataSet();
} catch (SQLException e) {
import org.apache.commons.configuration.BaseConfiguration;
import org.junit.Test;
import org.sonar.api.config.PropertyDefinitions;
-import org.sonar.core.persistence.DaoTestCase;
+import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.properties.PropertiesDao;
import java.io.File;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-public class ServerSettingsTest extends DaoTestCase {
+public class ServerSettingsTest extends AbstractDaoTestCase {
private static File home = getHome();