@@ -32,7 +32,7 @@ import org.sonar.api.rules.Rule; | |||
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; | |||
@@ -48,7 +48,7 @@ import static org.mockito.Mockito.times; | |||
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; | |||
@@ -45,25 +45,30 @@ public class DatabaseMigrator implements ServerComponent { | |||
* @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; | |||
} | |||
} |
@@ -21,12 +21,12 @@ package org.sonar.core.dashboard; | |||
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; | |||
@@ -21,7 +21,7 @@ package org.sonar.core.dashboard; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.core.persistence.DaoTestCase; | |||
import org.sonar.core.persistence.AbstractDaoTestCase; | |||
import java.util.Date; | |||
@@ -30,7 +30,7 @@ import static org.hamcrest.CoreMatchers.nullValue; | |||
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; | |||
@@ -24,14 +24,14 @@ import org.apache.ibatis.session.ResultContext; | |||
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"); |
@@ -24,14 +24,14 @@ import org.apache.ibatis.session.ResultContext; | |||
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"); |
@@ -21,7 +21,7 @@ package org.sonar.core.duplication; | |||
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; | |||
@@ -29,7 +29,7 @@ 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; | |||
@@ -25,11 +25,11 @@ import org.sonar.core.filter.CriterionDto; | |||
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 |
@@ -20,14 +20,13 @@ | |||
package org.sonar.core.persistence; | |||
import com.google.common.collect.Maps; | |||
import org.apache.commons.io.IOUtils; | |||
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.CompositeDataSet; | |||
import org.dbunit.dataset.DataSetException; | |||
import org.dbunit.dataset.IDataSet; | |||
import org.dbunit.dataset.ITable; | |||
@@ -42,13 +41,11 @@ 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 { | |||
public abstract class AbstractDaoTestCase { | |||
private static Database database; | |||
private static MyBatis myBatis; | |||
private static DatabaseCommands databaseCommands; | |||
@@ -58,10 +55,9 @@ public abstract class DaoTestCase { | |||
@BeforeClass | |||
public static void startDatabase() throws Exception { | |||
Settings settings = new Settings(); | |||
settings.setProperties(Maps.fromProperties(System.getProperties())); | |||
boolean hasDialect = settings.hasKey("sonar.jdbc.dialect"); | |||
Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties())); | |||
boolean hasDialect = settings.hasKey("sonar.jdbc.dialect"); | |||
if (hasDialect) { | |||
database = new DefaultDatabase(settings); | |||
} else { | |||
@@ -82,7 +78,7 @@ public abstract class DaoTestCase { | |||
} | |||
@After | |||
public void tearDownDbUnit() throws Exception { | |||
public void stopConnection() throws Exception { | |||
if (databaseTester != null) { | |||
databaseTester.onTearDown(); | |||
} | |||
@@ -102,40 +98,30 @@ public abstract class DaoTestCase { | |||
return myBatis; | |||
} | |||
protected final void setupData(String... testNames) { | |||
InputStream[] streams = new InputStream[testNames.length]; | |||
protected void setupData(String testName) { | |||
InputStream stream = null; | |||
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); | |||
} | |||
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(streams); | |||
setupData(stream); | |||
} finally { | |||
for (InputStream stream : streams) { | |||
IOUtils.closeQuietly(stream); | |||
} | |||
Closeables.closeQuietly(stream); | |||
} | |||
} | |||
protected final void setupData(InputStream... dataSetStream) { | |||
private void setupData(InputStream dataStream) { | |||
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); | |||
ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(dataStream)); | |||
dataSet.addReplacementObject("[null]", null); | |||
dataSet.addReplacementObject("[false]", databaseCommands.getFalse()); | |||
dataSet.addReplacementObject("[true]", databaseCommands.getTrue()); | |||
databaseTester.setDataSet(compositeDataSet); | |||
databaseTester.setDataSet(dataSet); | |||
connection = databaseTester.getConnection(); | |||
connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory()); | |||
@@ -146,11 +132,11 @@ public abstract class DaoTestCase { | |||
} | |||
} | |||
protected final void checkTables(String testName, String... tables) { | |||
protected void checkTables(String testName, String... tables) { | |||
checkTables(testName, new String[] {}, tables); | |||
} | |||
protected final void checkTables(String testName, String[] excludedColumnNames, String... tables) { | |||
protected void checkTables(String testName, String[] excludedColumnNames, String... tables) { | |||
try { | |||
IDataSet dataSet = getCurrentDataSet(); | |||
IDataSet expectedDataSet = getExpectedData(testName); | |||
@@ -165,7 +151,7 @@ public abstract class DaoTestCase { | |||
} | |||
} | |||
protected final void assertEmptyTables(String... emptyTables) { | |||
protected void assertEmptyTables(String... emptyTables) { | |||
for (String table : emptyTables) { | |||
try { | |||
Assert.assertEquals("Table " + table + " not empty.", 0, getCurrentDataSet().getTable(table).getRowCount()); | |||
@@ -175,7 +161,7 @@ public abstract class DaoTestCase { | |||
} | |||
} | |||
protected final IDataSet getExpectedData(String testName) { | |||
private IDataSet getExpectedData(String testName) { | |||
String className = getClass().getName(); | |||
className = String.format("/%s/%s-result.xml", className.replace(".", "/"), testName); | |||
@@ -183,11 +169,11 @@ public abstract class DaoTestCase { | |||
try { | |||
return getData(in); | |||
} finally { | |||
IOUtils.closeQuietly(in); | |||
Closeables.closeQuietly(in); | |||
} | |||
} | |||
protected final IDataSet getData(InputStream stream) { | |||
private IDataSet getData(InputStream stream) { | |||
try { | |||
ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream)); | |||
dataSet.addReplacementObject("[null]", null); | |||
@@ -199,7 +185,7 @@ public abstract class DaoTestCase { | |||
} | |||
} | |||
protected final IDataSet getCurrentDataSet() { | |||
private IDataSet getCurrentDataSet() { | |||
try { | |||
return connection.createDataSet(); | |||
} catch (SQLException e) { | |||
@@ -207,20 +193,6 @@ public abstract class DaoTestCase { | |||
} | |||
} | |||
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()); | |||
@@ -230,9 +202,4 @@ public abstract class DaoTestCase { | |||
protected IDatabaseConnection getConnection() { | |||
return connection; | |||
} | |||
protected IDatabaseTester getDatabaseTester() { | |||
return databaseTester; | |||
} | |||
} |
@@ -31,6 +31,6 @@ public class DaoUtilsTest { | |||
public void should_list_all_dao_classes() { | |||
List<Class<?>> daoClasses = DaoUtils.getDaoClasses(); | |||
assertThat(daoClasses.size()).isGreaterThan(1); | |||
assertThat(daoClasses).isNotEmpty(); | |||
} | |||
} |
@@ -26,7 +26,7 @@ import static org.hamcrest.CoreMatchers.is; | |||
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"); |
@@ -45,13 +45,13 @@ public class DdlUtilsTest { | |||
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()) { |
@@ -101,6 +101,7 @@ public class DefaultDatabaseTest { | |||
DefaultDatabase db = new DefaultDatabase(settings); | |||
db.start(); | |||
db.stop(); | |||
assertThat(db.getDialect().getId(), Is.is("h2")); | |||
assertThat(((BasicDataSource) db.getDataSource()).getMaxActive(), Is.is(1)); |
@@ -114,7 +114,6 @@ public class H2Database implements Database { | |||
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; | |||
} |
@@ -24,7 +24,6 @@ import org.junit.Before; | |||
import org.junit.Test; | |||
import java.sql.Connection; | |||
import java.sql.ResultSet; | |||
import java.sql.SQLException; | |||
import static org.fest.assertions.Assertions.assertThat; | |||
@@ -45,21 +44,17 @@ public class H2DatabaseTest { | |||
@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); | |||
} | |||
} |
@@ -21,7 +21,7 @@ package org.sonar.core.properties; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.core.persistence.DaoTestCase; | |||
import org.sonar.core.persistence.AbstractDaoTestCase; | |||
import java.util.List; | |||
@@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.hasItems; | |||
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; | |||
@@ -21,12 +21,12 @@ package org.sonar.core.purge; | |||
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. | |||
*/ |
@@ -25,7 +25,7 @@ import org.hamcrest.Description; | |||
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; | |||
@@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.is; | |||
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; | |||
@@ -21,13 +21,13 @@ package org.sonar.core.resource; | |||
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; | |||
@@ -23,7 +23,7 @@ import org.hamcrest.core.Is; | |||
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; | |||
@@ -32,7 +32,7 @@ import java.sql.SQLException; | |||
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; | |||
@@ -23,13 +23,13 @@ import org.junit.Before; | |||
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(); |
@@ -21,11 +21,11 @@ package org.sonar.core.review; | |||
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; | |||
@@ -22,7 +22,7 @@ package org.sonar.core.review; | |||
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; | |||
@@ -30,7 +30,7 @@ import static org.hamcrest.CoreMatchers.is; | |||
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; | |||
@@ -22,13 +22,13 @@ package org.sonar.core.rule; | |||
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; | |||
@@ -21,12 +21,12 @@ package org.sonar.core.template; | |||
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; | |||
@@ -21,13 +21,13 @@ package org.sonar.core.user; | |||
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; | |||
@@ -24,14 +24,14 @@ import org.sonar.api.config.Settings; | |||
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() { |
@@ -1,46 +0,0 @@ | |||
/* | |||
* 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(); | |||
} | |||
} |
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.jpa.test; | |||
import org.junit.AfterClass; | |||
import org.apache.commons.io.IOUtils; | |||
import org.dbunit.Assertion; | |||
import org.dbunit.DataSourceDatabaseTester; | |||
@@ -53,7 +55,7 @@ import java.sql.SQLException; | |||
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; | |||
@@ -97,11 +99,18 @@ public abstract class AbstractDbUnitTestCase { | |||
} | |||
} | |||
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() { | |||
@@ -113,7 +122,7 @@ public abstract class AbstractDbUnitTestCase { | |||
}; | |||
} | |||
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++) { | |||
@@ -134,7 +143,7 @@ public abstract class AbstractDbUnitTestCase { | |||
} | |||
} | |||
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++) { | |||
@@ -155,11 +164,11 @@ public abstract class AbstractDbUnitTestCase { | |||
} | |||
} | |||
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(); | |||
@@ -176,7 +185,7 @@ public abstract class AbstractDbUnitTestCase { | |||
} | |||
} | |||
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); | |||
@@ -188,7 +197,7 @@ public abstract class AbstractDbUnitTestCase { | |||
} | |||
} | |||
private final IDataSet getData(InputStream stream) { | |||
private IDataSet getData(InputStream stream) { | |||
try { | |||
ReplacementDataSet dataSet = new ReplacementDataSet(new FlatXmlDataSet(stream)); | |||
dataSet.addReplacementObject("[null]", null); | |||
@@ -198,7 +207,7 @@ public abstract class AbstractDbUnitTestCase { | |||
} | |||
} | |||
private final IDataSet getCurrentDataSet() { | |||
private IDataSet getCurrentDataSet() { | |||
try { | |||
return connection.createDataSet(); | |||
} catch (SQLException e) { |
@@ -22,7 +22,7 @@ package org.sonar.server.platform; | |||
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; | |||
@@ -32,7 +32,7 @@ import static org.hamcrest.Matchers.nullValue; | |||
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(); | |||