diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-07-05 21:45:32 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-07-06 09:22:50 +0200 |
commit | 305df737845a9f3c982735e28907ba6dbdf84623 (patch) | |
tree | ef0ab2c9d6ff3329c8d87439fbd1214cd5e786dd /sonar-db | |
parent | 32af292b745b7226bacc3f34d612437664af0ba3 (diff) | |
download | sonarqube-305df737845a9f3c982735e28907ba6dbdf84623.tar.gz sonarqube-305df737845a9f3c982735e28907ba6dbdf84623.zip |
Improve testability of Dao
Diffstat (limited to 'sonar-db')
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/DaoUtils.java | 4 | ||||
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/DbClient.java (renamed from sonar-db/src/main/java/org/sonar/db/DbClient2.java) | 31 | ||||
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/MyBatis.java | 4 | ||||
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java (renamed from sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java) | 36 | ||||
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/component/ResourceIndexMapper.java (renamed from sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java) | 2 | ||||
-rw-r--r-- | sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java (renamed from sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerQuery.java) | 16 | ||||
-rw-r--r-- | sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml (renamed from sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml) | 2 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/AbstractDaoTestCase.java | 274 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java | 10 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/DbTester.java | 37 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java | 129 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/TestDb.java | 28 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java | 2 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java (renamed from sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java) | 45 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/issue/ActionPlanDaoTest.java | 12 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java | 8 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java | 93 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java | 24 | ||||
-rw-r--r-- | sonar-db/src/test/java/org/sonar/db/user/AuthorDaoTest.java | 10 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotIndexPackages.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource-result.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource-result.xml) | 0 | ||||
-rw-r--r-- | sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource.xml (renamed from sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource.xml) | 0 |
39 files changed, 258 insertions, 509 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/DaoUtils.java b/sonar-db/src/main/java/org/sonar/db/DaoUtils.java index 7e3773f2b0d..4269182f2a7 100644 --- a/sonar-db/src/main/java/org/sonar/db/DaoUtils.java +++ b/sonar-db/src/main/java/org/sonar/db/DaoUtils.java @@ -24,7 +24,7 @@ import java.util.List; import org.sonar.db.activity.ActivityDao; import org.sonar.db.component.ComponentLinkDao; import org.sonar.db.component.ResourceDao; -import org.sonar.db.component.ResourceIndexerDao; +import org.sonar.db.component.ResourceIndexDao; import org.sonar.db.component.ResourceKeyUpdaterDao; import org.sonar.db.component.SnapshotDao; import org.sonar.db.compute.AnalysisReportDao; @@ -97,7 +97,7 @@ public final class DaoUtils { QualityProfileDao.class, PurgeDao.class, CharacteristicDao.class, - ResourceIndexerDao.class, + ResourceIndexDao.class, ResourceDao.class, ResourceKeyUpdaterDao.class, RoleDao.class, diff --git a/sonar-db/src/main/java/org/sonar/db/DbClient2.java b/sonar-db/src/main/java/org/sonar/db/DbClient.java index 92cbd39c2c5..aad304f08aa 100644 --- a/sonar-db/src/main/java/org/sonar/db/DbClient2.java +++ b/sonar-db/src/main/java/org/sonar/db/DbClient.java @@ -25,7 +25,7 @@ import javax.annotation.Nullable; import org.sonar.db.activity.ActivityDao; import org.sonar.db.component.ComponentLinkDao; import org.sonar.db.component.ResourceDao; -import org.sonar.db.component.ResourceIndexerDao; +import org.sonar.db.component.ResourceIndexDao; import org.sonar.db.component.SnapshotDao; import org.sonar.db.compute.AnalysisReportDao; import org.sonar.db.dashboard.DashboardDao; @@ -52,8 +52,9 @@ import org.sonar.db.user.GroupMembershipDao; import org.sonar.db.user.RoleDao; import org.sonar.db.user.UserGroupDao; -public class DbClient2 { +public class DbClient { + private final Database database; private final MyBatis myBatis; private final QualityProfileDao qualityProfileDao; private final CharacteristicDao debtCharacteristicDao; @@ -79,13 +80,14 @@ public class DbClient2 { private final WidgetPropertyDao widgetPropertyDao; private final FileSourceDao fileSourceDao; private final AuthorDao authorDao; - private final ResourceIndexerDao componentIndexDao; + private final ResourceIndexDao componentIndexDao; private final ComponentLinkDao componentLinkDao; private final EventDao eventDao; private final PurgeDao purgeDao; private final QualityGateConditionDao gateConditionDao; - public DbClient2(MyBatis myBatis, Dao[] daos) { + public DbClient(Database database, MyBatis myBatis, Dao[] daos) { + this.database = database; this.myBatis = myBatis; Map<Class, Dao> map = new IdentityHashMap<>(); @@ -116,11 +118,17 @@ public class DbClient2 { widgetPropertyDao = getDao(map, WidgetPropertyDao.class); fileSourceDao = getDao(map, FileSourceDao.class); authorDao = getDao(map, AuthorDao.class); - componentIndexDao = getDao(map, ResourceIndexerDao.class); + componentIndexDao = getDao(map, ResourceIndexDao.class); componentLinkDao = getDao(map, ComponentLinkDao.class); eventDao = getDao(map, EventDao.class); purgeDao = getDao(map, PurgeDao.class); gateConditionDao = getDao(map, QualityGateConditionDao.class); + doOnLoad(map); + } + + // should be removed, but till used by sonar-server + protected void doOnLoad(Map<Class, Dao> daoByClass) { + } public DbSession openSession(boolean batch) { @@ -131,6 +139,10 @@ public class DbClient2 { MyBatis.closeQuietly(session); } + public Database getDatabase() { + return database; + } + public IssueDao issueDao() { return issueDao; } @@ -223,7 +235,7 @@ public class DbClient2 { return authorDao; } - public ResourceIndexerDao componentIndexDao() { + public ResourceIndexDao componentIndexDao() { return componentIndexDao; } @@ -247,7 +259,12 @@ public class DbClient2 { return gateConditionDao; } - private <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) { + protected <K extends Dao> K getDao(Map<Class, Dao> map, Class<K> clazz) { return (K) map.get(clazz); } + + // should be removed. Still used by some old DAO in sonar-server + public MyBatis getMyBatis() { + return myBatis; + } } diff --git a/sonar-db/src/main/java/org/sonar/db/MyBatis.java b/sonar-db/src/main/java/org/sonar/db/MyBatis.java index 5926def8753..e4e3bce008b 100644 --- a/sonar-db/src/main/java/org/sonar/db/MyBatis.java +++ b/sonar-db/src/main/java/org/sonar/db/MyBatis.java @@ -48,7 +48,7 @@ import org.sonar.db.component.ComponentMapper; import org.sonar.db.component.FilePathWithHashDto; import org.sonar.db.component.ResourceDto; import org.sonar.db.component.ResourceIndexDto; -import org.sonar.db.component.ResourceIndexerMapper; +import org.sonar.db.component.ResourceIndexMapper; import org.sonar.db.component.ResourceKeyUpdaterMapper; import org.sonar.db.component.ResourceMapper; import org.sonar.db.component.SnapshotDto; @@ -249,7 +249,7 @@ public class MyBatis { IssueMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class, IsAliveMapper.class, LoadedTemplateMapper.class, MeasureFilterMapper.class, Migration44Mapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class, - ResourceKeyUpdaterMapper.class, ResourceIndexerMapper.class, RoleMapper.class, RuleMapper.class, + ResourceKeyUpdaterMapper.class, ResourceIndexMapper.class, RoleMapper.class, RuleMapper.class, SchemaMigrationMapper.class, SemaphoreMapper.class, UserMapper.class, GroupMapper.class, UserGroupMapper.class, WidgetMapper.class, WidgetPropertyMapper.class, FileSourceMapper.class, ActionPlanMapper.class, ActionPlanStatsMapper.class, diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java index 827ece8fd1b..b146a517f65 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerDao.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexDao.java @@ -31,9 +31,9 @@ import org.sonar.db.AbstractDao; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; -public class ResourceIndexerDao extends AbstractDao { +public class ResourceIndexDao extends AbstractDao { - private static final String SELECT_RESOURCES = "org.sonar.db.component.ResourceIndexerMapper.selectResources"; + private static final String SELECT_RESOURCES = "org.sonar.db.component.ResourceIndexMapper.selectResources"; public static final int MINIMUM_KEY_SIZE = 3; public static final int SINGLE_INDEX_SIZE = 2; @@ -44,18 +44,18 @@ public class ResourceIndexerDao extends AbstractDao { private static final String[] NOT_RENAMABLE_QUALIFIERS = {Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE, Qualifiers.CLASS}; private static final String[] NOT_RENAMABLE_SCOPES = {Scopes.FILE}; - public ResourceIndexerDao(MyBatis myBatis, System2 system2) { + public ResourceIndexDao(MyBatis myBatis, System2 system2) { super(myBatis, system2); } public List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(DbSession session, String query, String viewOrSubViewUuid) { - return session.getMapper(ResourceIndexerMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%"); + return session.getMapper(ResourceIndexMapper.class).selectProjectIdsFromQueryAndViewOrSubViewUuid(query + "%", "%." + viewOrSubViewUuid + ".%"); } /** * This method is reentrant. It can be executed even if the project is already indexed. */ - public ResourceIndexerDao indexProject(final long rootProjectId) { + public ResourceIndexDao indexProject(final long rootProjectId) { DbSession session = myBatis().openSession(true); try { indexProject(rootProjectId, session); @@ -68,18 +68,18 @@ public class ResourceIndexerDao extends AbstractDao { } public void indexProject(final long rootProjectId, DbSession session) { - ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); + ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class); doIndexProject(rootProjectId, session, mapper); } /** * This method is reentrant. It can be executed even if some projects are already indexed. */ - public ResourceIndexerDao indexProjects() { + public ResourceIndexDao indexProjects() { final DbSession session = myBatis().openSession(true); try { - final ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); - session.select("org.sonar.db.component.ResourceIndexerMapper.selectRootProjectIds", /* workaround to get booleans */ResourceIndexerQuery.create(), new ResultHandler() { + final ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class); + session.select(ResourceIndexMapper.class.getName() + ".selectRootProjectIds", /* workaround to get booleans */ResourceIndexQuery.create(), new ResultHandler() { @Override public void handleResult(ResultContext context) { Integer rootProjectId = (Integer) context.getResultObject(); @@ -94,9 +94,9 @@ public class ResourceIndexerDao extends AbstractDao { } } - private void doIndexProject(long rootProjectId, SqlSession session, final ResourceIndexerMapper mapper) { + private void doIndexProject(long rootProjectId, SqlSession session, final ResourceIndexMapper mapper) { // non indexed resources - ResourceIndexerQuery query = ResourceIndexerQuery.create() + ResourceIndexQuery query = ResourceIndexQuery.create() .setNonIndexedOnly(true) .setQualifiers(NOT_RENAMABLE_QUALIFIERS) .setScopes(NOT_RENAMABLE_SCOPES) @@ -112,7 +112,7 @@ public class ResourceIndexerDao extends AbstractDao { // some resources can be renamed, so index must be regenerated // -> delete existing rows and create them again - query = ResourceIndexerQuery.create() + query = ResourceIndexQuery.create() .setNonIndexedOnly(false) .setQualifiers(RENAMABLE_QUALIFIERS) .setScopes(RENAMABLE_SCOPES) @@ -129,7 +129,7 @@ public class ResourceIndexerDao extends AbstractDao { }); } - void doIndex(ResourceDto resource, ResourceIndexerMapper mapper) { + void doIndex(ResourceDto resource, ResourceIndexMapper mapper) { String key = nameToKey(resource.getName()); if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) { insertIndexEntries(key, resource.getId(), resource.getQualifier(), resource.getRootId(), resource.getName().length(), mapper); @@ -147,7 +147,7 @@ public class ResourceIndexerDao extends AbstractDao { public boolean indexResource(DbSession session, long id) { boolean indexed = false; - ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); + ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class); ResourceDto resource = mapper.selectResourceToIndex(id); if (resource != null) { Long rootId = resource.getRootId(); @@ -162,7 +162,7 @@ public class ResourceIndexerDao extends AbstractDao { public boolean indexResource(int id, String name, String qualifier, int rootId) { boolean indexed = false; SqlSession session = myBatis().openSession(false); - ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); + ResourceIndexMapper mapper = session.getMapper(ResourceIndexMapper.class); try { indexed = indexResource(id, name, qualifier, rootId, session, mapper); } finally { @@ -171,7 +171,7 @@ public class ResourceIndexerDao extends AbstractDao { return indexed; } - private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexerMapper mapper) { + private boolean indexResource(long id, String name, String qualifier, long rootId, SqlSession session, ResourceIndexMapper mapper) { boolean indexed = false; String key = nameToKey(name); if (key.length() >= MINIMUM_KEY_SIZE || key.length() == SINGLE_INDEX_SIZE) { @@ -185,7 +185,7 @@ public class ResourceIndexerDao extends AbstractDao { return indexed; } - private void insertIndexEntries(String key, long resourceId, String qualifier, long rootId, int nameLength, ResourceIndexerMapper mapper) { + private void insertIndexEntries(String key, long resourceId, String qualifier, long rootId, int nameLength, ResourceIndexMapper mapper) { ResourceIndexDto dto = new ResourceIndexDto() .setResourceId(resourceId) .setQualifier(qualifier) @@ -205,7 +205,7 @@ public class ResourceIndexerDao extends AbstractDao { * If the resource is indexed with a different key, then this index is dropped and the * resource must be indexed again. */ - private boolean sanitizeIndex(long resourceId, String key, ResourceIndexerMapper mapper) { + private boolean sanitizeIndex(long resourceId, String key, ResourceIndexMapper mapper) { ResourceIndexDto masterIndex = mapper.selectMasterIndexByResourceId(resourceId); if (masterIndex != null && !StringUtils.equals(key, masterIndex.getKey())) { // resource has been renamed -> drop existing indexes diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexMapper.java index a0cb17b2ccf..31efd21338e 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexMapper.java @@ -22,7 +22,7 @@ package org.sonar.db.component; import java.util.List; import org.apache.ibatis.annotations.Param; -public interface ResourceIndexerMapper { +public interface ResourceIndexMapper { List<Long> selectProjectIdsFromQueryAndViewOrSubViewUuid(@Param("query") String query, @Param("viewUuidQuery") String viewUuidQuery); diff --git a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerQuery.java b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java index f05204aa130..6d5e495aad3 100644 --- a/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexerQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/component/ResourceIndexQuery.java @@ -19,17 +19,17 @@ */ package org.sonar.db.component; -final class ResourceIndexerQuery { +final class ResourceIndexQuery { private long rootProjectId; private String[] scopes = null; private String[] qualifiers = null; private boolean nonIndexedOnly = false; - private ResourceIndexerQuery() { + private ResourceIndexQuery() { } - public static ResourceIndexerQuery create() { - return new ResourceIndexerQuery(); + public static ResourceIndexQuery create() { + return new ResourceIndexQuery(); } public String[] getScopes() { @@ -40,12 +40,12 @@ final class ResourceIndexerQuery { return qualifiers; } - public ResourceIndexerQuery setScopes(String[] scopes) { + public ResourceIndexQuery setScopes(String[] scopes) { this.scopes = scopes; return this; } - public ResourceIndexerQuery setQualifiers(String[] qualifiers) { + public ResourceIndexQuery setQualifiers(String[] qualifiers) { this.qualifiers = qualifiers; return this; } @@ -54,7 +54,7 @@ final class ResourceIndexerQuery { return rootProjectId; } - public ResourceIndexerQuery setRootProjectId(long i) { + public ResourceIndexQuery setRootProjectId(long i) { this.rootProjectId = i; return this; } @@ -63,7 +63,7 @@ final class ResourceIndexerQuery { return nonIndexedOnly; } - public ResourceIndexerQuery setNonIndexedOnly(boolean b) { + public ResourceIndexQuery setNonIndexedOnly(boolean b) { this.nonIndexedOnly = b; return this; } diff --git a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml index b9a10673e3c..1228c975365 100644 --- a/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexerMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/component/ResourceIndexMapper.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.sonar.db.component.ResourceIndexerMapper"> +<mapper namespace="org.sonar.db.component.ResourceIndexMapper"> <select id="selectProjectIdsFromQueryAndViewOrSubViewUuid" parameterType="map" resultType="long"> SELECT r.resource_id FROM resource_index r diff --git a/sonar-db/src/test/java/org/sonar/db/AbstractDaoTestCase.java b/sonar-db/src/test/java/org/sonar/db/AbstractDaoTestCase.java index 756a3437595..43b8c75e036 100644 --- a/sonar-db/src/test/java/org/sonar/db/AbstractDaoTestCase.java +++ b/sonar-db/src/test/java/org/sonar/db/AbstractDaoTestCase.java @@ -19,50 +19,13 @@ */ package org.sonar.db; -import com.google.common.collect.Maps; -import com.google.common.io.Closeables; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URI; -import java.net.URISyntaxException; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Map; -import java.util.Properties; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.text.StrSubstitutor; -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.dbunit.ext.mssql.InsertIdentityOperation; -import org.dbunit.ext.mysql.MySqlMetadataHandler; -import org.dbunit.operation.DatabaseOperation; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; +import java.util.ArrayList; +import java.util.List; +import org.junit.Rule; import org.junit.experimental.categories.Category; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.config.Settings; -import org.sonar.db.deprecated.NullQueue; -import org.sonar.db.dialect.MySql; +import org.sonar.api.utils.System2; import org.sonar.test.DbTests; -import static org.junit.Assert.fail; - /** * @deprecated use an instance of {@link DbTester instead} instead, * and do no forget to annotated the test class with {@link org.sonar.test.DbTests}. @@ -71,130 +34,15 @@ import static org.junit.Assert.fail; @Deprecated public abstract class AbstractDaoTestCase { - private static final Logger LOG = LoggerFactory.getLogger(AbstractDaoTestCase.class); - private static Database database; - private static DatabaseCommands databaseCommands; - private static MyBatis myBatis; - private static String login; - - private IDatabaseTester databaseTester; - - @BeforeClass - public static void startDatabase() throws Exception { - if (database == null) { - Settings settings = new Settings().setProperties(Maps.fromProperties(System.getProperties())); - if (settings.hasKey("orchestrator.configUrl")) { - loadOrchestratorSettings(settings); - } - login = settings.getString("sonar.jdbc.username"); - for (String key : settings.getKeysStartingWith("sonar.jdbc")) { - LOG.info(key + ": " + settings.getString(key)); - } - boolean hasDialect = settings.hasKey("sonar.jdbc.dialect"); - if (hasDialect) { - database = new DefaultDatabase(settings); - } else { - database = new H2Database("test", true); - } - database.start(); - LOG.info("Test Database: " + database); - databaseCommands = DatabaseCommands.forDialect(database.getDialect()); - - myBatis = new MyBatis(database, new NullQueue()); - myBatis.start(); - } - } - - /** - * Orchestrator is the name of a SonarSource close-source library for database and integration testing. - */ - private static void loadOrchestratorSettings(Settings settings) throws URISyntaxException, IOException { - String url = settings.getString("orchestrator.configUrl"); - URI uri = new URI(url); - InputStream input = null; - try { - if (url.startsWith("file:")) { - File file = new File(uri); - input = FileUtils.openInputStream(file); - } else { - HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); - int responseCode = connection.getResponseCode(); - if (responseCode >= 400) { - throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode); - } - - input = connection.getInputStream(); - - } - Properties props = new Properties(); - props.load(input); - settings.addProperties(props); - for (Map.Entry<String, String> entry : settings.getProperties().entrySet()) { - String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}"); - settings.setProperty(entry.getKey(), interpolatedValue); - } - } finally { - IOUtils.closeQuietly(input); - } - } - - 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; - } - - @Before - public void startDbUnit() throws Exception { - databaseCommands.truncateDatabase(database.getDataSource()); - databaseTester = new DataSourceDatabaseTester(database.getDataSource(), databaseCommands.useLoginAsSchema() ? login : null); - } - - protected MyBatis getMyBatis() { - return myBatis; - } - - protected Database getDatabase() { - return database; - } + @Rule + public DbTester dbTester = DbTester.create(System2.INSTANCE); protected 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); - databaseCommands.resetPrimaryKeys(database.getDataSource()); - } catch (SQLException e) { - throw translateException("Could not setup DBUnit data", e); - } finally { - for (InputStream stream : streams) { - IOUtils.closeQuietly(stream); - } - } - } - - private void setupData(InputStream... dataSetStream) { - IDatabaseConnection connection = openDbUnitConnection(); - try { - IDataSet[] dataSets = new IDataSet[dataSetStream.length]; - for (int i = 0; i < dataSetStream.length; i++) { - dataSets[i] = getData(dataSetStream[i]); - } - databaseTester.setDataSet(new CompositeDataSet(dataSets)); - new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, databaseTester.getDataSet()); - } catch (Exception e) { - throw translateException("Could not setup DBUnit data", e); - } finally { - closeDbUnitConnection(connection); + List<String> filenames = new ArrayList<>(); + for (String testName : testNames) { + filenames.add(testName + (testName.endsWith(".xml") ? "" : ".xml")); } + dbTester.prepareDbUnit(getClass(), filenames.toArray(new String[filenames.size()])); } protected void checkTables(String testName, String... tables) { @@ -202,107 +50,15 @@ public abstract class AbstractDaoTestCase { } protected void checkTables(String testName, String[] excludedColumnNames, String... tables) { - IDatabaseConnection connection = openDbUnitConnection(); - try { - IDataSet dataSet = connection.createDataSet(); - IDataSet expectedDataSet = getExpectedData(testName); - for (String table : tables) { - ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames); - ITable filteredExpectedTable = DefaultColumnFilter.excludedColumnsTable(expectedDataSet.getTable(table), excludedColumnNames); - Assertion.assertEquals(filteredExpectedTable, filteredTable); - } - } catch (DatabaseUnitException e) { - fail(e.getMessage()); - } catch (SQLException e) { - throw translateException("Error while checking results", e); - } finally { - closeDbUnitConnection(connection); - } + dbTester.assertDbUnit(getClass(), testName + (testName.endsWith("-result.xml") ? "" : "-result.xml"), excludedColumnNames, tables); } protected void checkTable(String testName, String table, String... columns) { - IDatabaseConnection connection = openDbUnitConnection(); - try { - IDataSet dataSet = connection.createDataSet(); - IDataSet expectedDataSet = getExpectedData(testName); - ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns); - ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns); - Assertion.assertEquals(filteredExpectedTable, filteredTable); - } catch (DatabaseUnitException e) { - fail(e.getMessage()); - } catch (SQLException e) { - throw translateException("Error while checking results", e); - } finally { - closeDbUnitConnection(connection); - } - } - - protected void assertEmptyTables(String... emptyTables) { - IDatabaseConnection connection = openDbUnitConnection(); - try { - IDataSet dataSet = connection.createDataSet(); - for (String table : emptyTables) { - try { - Assert.assertEquals("Table " + table + " not empty.", 0, dataSet.getTable(table).getRowCount()); - } catch (DataSetException e) { - throw translateException("Error while checking results", e); - } - } - } catch (SQLException e) { - throw translateException("Error while checking results", e); - } finally { - closeDbUnitConnection(connection); - } - } - - private IDatabaseConnection openDbUnitConnection() { - try { - IDatabaseConnection connection = databaseTester.getConnection(); - connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, databaseCommands.getDbUnitFactory()); - connection.getConfig().setFeature(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, false); - connection.getConfig().setFeature(DatabaseConfig.FEATURE_SKIP_ORACLE_RECYCLEBIN_TABLES, true); - if (MySql.ID.equals(database.getDialect().getId())) { - connection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, false); - connection.getConfig().setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler()); - } - return connection; - } catch (Exception e) { - throw new IllegalStateException("Fail to open dbunit connection", e); - } + dbTester.assertDbUnitTable(getClass(), testName + (testName.endsWith("-result.xml") ? "" : "-result.xml"), table, columns); } - private void closeDbUnitConnection(IDatabaseConnection c) { - try { - c.close(); - } catch (SQLException e) { - throw new IllegalStateException("Fail to close dbunit connection", e); - } - } - - private IDataSet getExpectedData(String testName) { - String className = getClass().getName(); - String fileName = String.format("/%s/%s-result.xml", className.replace('.', '/'), testName); - InputStream in = getClass().getResourceAsStream(fileName); - 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]", Boolean.FALSE); - dataSet.addReplacementObject("[true]", Boolean.TRUE); - return dataSet; - } catch (Exception e) { - throw translateException("Could not read the dataset stream", e); - } - } - - protected Connection getConnection() throws SQLException { - return database.getDataSource().getConnection(); + @Deprecated + protected MyBatis getMyBatis() { + return dbTester.myBatis(); } } diff --git a/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java b/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java index 1b6acbb3eb2..9a619b36a1e 100644 --- a/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/DatabaseUtilsTest.java @@ -41,8 +41,8 @@ import static org.mockito.Mockito.verify; public class DatabaseUtilsTest extends AbstractDaoTestCase { @Test - public void should_close_connection() throws SQLException { - Connection connection = getConnection(); + public void should_close_connection() throws Exception { + Connection connection = dbTester.openConnection(); assertThat(isClosed(connection)).isFalse(); DatabaseUtils.closeQuietly(connection); @@ -56,8 +56,8 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase { } @Test - public void should_close_statement_and_resultset() throws SQLException { - Connection connection = getConnection(); + public void should_close_statement_and_resultset() throws Exception { + Connection connection = dbTester.openConnection(); try { PreparedStatement statement = connection.prepareStatement(selectDual()); ResultSet rs = statement.executeQuery(); @@ -143,7 +143,7 @@ public class DatabaseUtilsTest extends AbstractDaoTestCase { private String selectDual() { String sql = "SELECT 1"; - if (Oracle.ID.equals(getDatabase().getDialect().getId())) { + if (Oracle.ID.equals(dbTester.database().getDialect().getId())) { sql = "SELECT 1 FROM DUAL"; } return sql; diff --git a/sonar-db/src/test/java/org/sonar/db/DbTester.java b/sonar-db/src/test/java/org/sonar/db/DbTester.java index dfa4e9cfef0..30bc65fa1e3 100644 --- a/sonar-db/src/test/java/org/sonar/db/DbTester.java +++ b/sonar-db/src/test/java/org/sonar/db/DbTester.java @@ -49,7 +49,6 @@ import org.dbunit.dataset.filter.DefaultColumnFilter; import org.dbunit.dataset.xml.FlatXmlDataSet; import org.dbunit.ext.mssql.InsertIdentityOperation; import org.dbunit.operation.DatabaseOperation; -import org.junit.After; import org.junit.rules.ExternalResource; import org.picocontainer.containers.TransientPicoContainer; import org.sonar.api.utils.System2; @@ -71,7 +70,7 @@ public class DbTester extends ExternalResource { private final System2 system2; private final TestDb db; - private DbClient2 client; + private DbClient client; private DbSession session = null; @Deprecated @@ -100,11 +99,12 @@ public class DbTester extends ExternalResource { truncateTables(); } - @After - public void closeSession() throws Exception { + @Override + protected void after() { if (session != null) { MyBatis.closeQuietly(session); } + db.close(); } public DbSession getSession() { @@ -118,7 +118,7 @@ public class DbTester extends ExternalResource { db.truncateTables(); } - public DbClient2 getDbClient() { + public DbClient getDbClient() { if (client == null) { TransientPicoContainer ioc = new TransientPicoContainer(); ioc.addComponent(db.getMyBatis()); @@ -127,7 +127,7 @@ public class DbTester extends ExternalResource { ioc.addComponent(daoClass); } List<Dao> daos = ioc.getComponents(Dao.class); - client = new DbClient2(db.getMyBatis(), daos.toArray(new Dao[daos.size()])); + client = new DbClient(db.getDatabase(), db.getMyBatis(), daos.toArray(new Dao[daos.size()])); } return client; } @@ -263,6 +263,24 @@ public class DbTester extends ExternalResource { } } + public void assertDbUnitTable(Class testClass, String filename, String table, String... columns) { + IDatabaseConnection connection = dbUnitConnection(); + try { + IDataSet dataSet = connection.createDataSet(); + String path = "/" + testClass.getName().replace('.', '/') + "/" + filename; + IDataSet expectedDataSet = dbUnitDataSet(testClass.getResourceAsStream(path)); + ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns); + ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns); + Assertion.assertEquals(filteredExpectedTable, filteredTable); + } catch (DatabaseUnitException e) { + fail(e.getMessage()); + } catch (SQLException e) { + throw translateException("Error while checking results", e); + } finally { + closeQuietly(connection); + } + } + public void assertDbUnit(Class testClass, String filename, String... tables) { assertDbUnit(testClass, filename, new String[0], tables); } @@ -372,7 +390,7 @@ public class DbTester extends ExternalResource { } } - private static RuntimeException translateException(String msg, Exception cause) { + public 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; @@ -400,4 +418,9 @@ public class DbTester extends ExternalResource { public Database database() { return db.getDatabase(); } + + public DatabaseCommands getCommands() { + return db.getCommands(); + } + } diff --git a/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java b/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java index 970f9090fd1..4326aa15b88 100644 --- a/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java +++ b/sonar-db/src/test/java/org/sonar/db/ResultSetIteratorTest.java @@ -24,9 +24,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.NoSuchElementException; -import org.apache.commons.dbutils.DbUtils; -import org.junit.After; -import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -42,107 +39,105 @@ public class ResultSetIteratorTest { @ClassRule public static DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, ResultSetIteratorTest.class, "schema.sql"); - Connection connection = null; - - @Before - public void setUp() throws Exception { - connection = dbTester.openConnection(); - } - - @After - public void tearDown() { - DbUtils.closeQuietly(connection); - } - @Test public void create_iterator_from_statement() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); - FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); + try (Connection connection = dbTester.openConnection()) { + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); + FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); - assertThat(iterator.hasNext()).isTrue(); + assertThat(iterator.hasNext()).isTrue(); - // calling multiple times hasNext() is ok - assertThat(iterator.hasNext()).isTrue(); + // calling multiple times hasNext() is ok + assertThat(iterator.hasNext()).isTrue(); - assertThat(iterator.next()).isEqualTo(10); - assertThat(iterator.hasNext()).isTrue(); - assertThat(iterator.next()).isEqualTo(20); + assertThat(iterator.next()).isEqualTo(10); + assertThat(iterator.hasNext()).isTrue(); + assertThat(iterator.next()).isEqualTo(20); - // call next() without calling hasNext() - assertThat(iterator.next()).isEqualTo(30); - assertThat(iterator.hasNext()).isFalse(); + // call next() without calling hasNext() + assertThat(iterator.next()).isEqualTo(30); + assertThat(iterator.hasNext()).isFalse(); - try { - iterator.next(); - fail(); - } catch (NoSuchElementException e) { - // ok - } + try { + iterator.next(); + fail(); + } catch (NoSuchElementException e) { + // ok + } - iterator.close(); - // statement is closed by ResultSetIterator - assertThat(stmt.isClosed()).isTrue(); + iterator.close(); + // statement is closed by ResultSetIterator + assertThat(stmt.isClosed()).isTrue(); + } } @Test public void iterate_empty_list() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0"); - FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); + try (Connection connection = dbTester.openConnection()) { + PreparedStatement stmt = connection.prepareStatement("select * from issues where id < 0"); + FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); - assertThat(iterator.hasNext()).isFalse(); + assertThat(iterator.hasNext()).isFalse(); + } } @Test public void create_iterator_from_result_set() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); - ResultSet rs = stmt.executeQuery(); - FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs); + try (Connection connection = dbTester.openConnection()) { + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); + ResultSet rs = stmt.executeQuery(); + FirstIntColumnIterator iterator = new FirstIntColumnIterator(rs); - assertThat(iterator.next()).isEqualTo(10); - assertThat(iterator.next()).isEqualTo(20); - assertThat(iterator.next()).isEqualTo(30); + assertThat(iterator.next()).isEqualTo(10); + assertThat(iterator.next()).isEqualTo(20); + assertThat(iterator.next()).isEqualTo(30); - iterator.close(); - assertThat(rs.isClosed()).isTrue(); - stmt.close(); + iterator.close(); + assertThat(rs.isClosed()).isTrue(); + stmt.close(); + } } @Test public void remove_row_is_not_supported() throws Exception { - PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); - FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); - - try { - iterator.remove(); - fail(); - } catch (UnsupportedOperationException ok) { - // ok + try (Connection connection = dbTester.openConnection()) { + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); + FirstIntColumnIterator iterator = new FirstIntColumnIterator(stmt); + + try { + iterator.remove(); + fail(); + } catch (UnsupportedOperationException ok) { + // ok + } + + iterator.close(); } - - iterator.close(); } @Test public void fail_to_read_row() throws Exception { dbTester.prepareDbUnit(getClass(), "feed.xml"); - PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); - FailIterator iterator = new FailIterator(stmt); - - assertThat(iterator.hasNext()).isTrue(); - try { - iterator.next(); - fail(); - } catch (IllegalStateException e) { - assertThat(e.getCause()).isInstanceOf(SQLException.class); + try (Connection connection = dbTester.openConnection()) { + PreparedStatement stmt = connection.prepareStatement("select * from issues order by id"); + FailIterator iterator = new FailIterator(stmt); + + assertThat(iterator.hasNext()).isTrue(); + try { + iterator.next(); + fail(); + } catch (IllegalStateException e) { + assertThat(e.getCause()).isInstanceOf(SQLException.class); + } + iterator.close(); } - iterator.close(); } private static class FirstIntColumnIterator extends ResultSetIterator<Integer> { diff --git a/sonar-db/src/test/java/org/sonar/db/TestDb.java b/sonar-db/src/test/java/org/sonar/db/TestDb.java index 715ea17af6d..3ab4fc41346 100644 --- a/sonar-db/src/test/java/org/sonar/db/TestDb.java +++ b/sonar-db/src/test/java/org/sonar/db/TestDb.java @@ -60,6 +60,17 @@ class TestDb { private DatabaseCommands commands; private IDatabaseTester tester; private MyBatis myBatis; + private boolean isDefault; + + static TestDb create(@Nullable String schemaPath) { + if (schemaPath == null) { + if (DEFAULT == null) { + DEFAULT = new TestDb(null); + } + return DEFAULT; + } + return new TestDb(schemaPath); + } private TestDb(@Nullable String schemaPath) { if (db == null) { @@ -87,6 +98,7 @@ class TestDb { throw new AssumptionViolatedException("Test disabled because it supports only H2"); } } + isDefault = (schemaPath == null); LOG.info("Test Database: " + db); commands = DatabaseCommands.forDialect(db.getDialect()); @@ -105,20 +117,10 @@ class TestDb { } } - static TestDb create(@Nullable String schemaPath) { - if (schemaPath == null) { - if (DEFAULT == null) { - DEFAULT = new TestDb(null); - } - return DEFAULT; + void close() { + if (!isDefault) { + db.stop(); } - return new TestDb(schemaPath); - } - - void stop() { - db.stop(); - db = null; - myBatis = null; } Database getDatabase() { diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java index a6c809330f1..0936f6c8f76 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceDaoTest.java @@ -307,7 +307,7 @@ public class ResourceDaoTest extends AbstractDaoTestCase { session.rollback(); - assertEmptyTables("projects"); + assertThat(dbTester.countRowsOfTable("projects")).isZero(); } @Test diff --git a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java index deb992be365..df1195d46ff 100644 --- a/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexerDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/component/ResourceIndexDaoTest.java @@ -19,27 +19,17 @@ */ package org.sonar.db.component; -import java.sql.Connection; -import java.sql.ResultSet; import java.sql.SQLException; -import org.junit.Before; import org.junit.Test; import org.sonar.api.resources.Qualifiers; -import org.sonar.api.utils.System2; import org.sonar.db.AbstractDaoTestCase; import org.sonar.db.DbSession; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -public class ResourceIndexerDaoTest extends AbstractDaoTestCase { +public class ResourceIndexDaoTest extends AbstractDaoTestCase { - private static ResourceIndexerDao dao; - - @Before - public void createDao() { - dao = new ResourceIndexerDao(getMyBatis(), mock(System2.class)); - } + ResourceIndexDao dao = dbTester.getDbClient().componentIndexDao(); @Test public void shouldIndexResource() { @@ -82,29 +72,12 @@ public class ResourceIndexerDaoTest extends AbstractDaoTestCase { setupData("shouldNotIndexPackages"); dao.indexProject(1); - - Connection connection = getConnection(); - ResultSet rs = null; - try { - // project - rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=1"); - rs.next(); - assertThat(rs.getInt(1)).isGreaterThan(0); - - // directory - rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=2"); - rs.next(); - assertThat(rs.getInt(1)).isEqualTo(0); - - // file - rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=3"); - rs.next(); - assertThat(rs.getInt(1)).isGreaterThan(0); - } finally { - if (null != rs) { - rs.close(); - } - } + // project + assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=1")).isGreaterThan(0); + // directory + assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=2")).isEqualTo(0); + // file + assertThat(dbTester.countSql("select count(resource_id) from resource_index where resource_id=3")).isGreaterThan(0); } @Test @@ -157,7 +130,7 @@ public class ResourceIndexerDaoTest extends AbstractDaoTestCase { setupData("select_project_ids_from_query_and_view_or_sub_view_uuid"); String viewUuid = "EFGH"; - DbSession session = getMyBatis().openSession(false); + DbSession session = dbTester.getSession(); assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "project", viewUuid)).containsOnly(1L, 2L); assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "one", viewUuid)).containsOnly(1L); assertThat(dao.selectProjectIdsFromQueryAndViewOrSubViewUuid(session, "two", viewUuid)).containsOnly(2L); diff --git a/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanDaoTest.java b/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanDaoTest.java index 939fc01ed36..85439f61db8 100644 --- a/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/issue/ActionPlanDaoTest.java @@ -22,23 +22,15 @@ package org.sonar.db.issue; import java.util.Collection; import java.util.List; -import org.apache.ibatis.session.SqlSession; -import org.junit.Before; import org.junit.Test; import org.sonar.db.AbstractDaoTestCase; -import org.sonar.db.MyBatis; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; public class ActionPlanDaoTest extends AbstractDaoTestCase { - ActionPlanDao dao; - - @Before - public void createDao() { - dao = new ActionPlanDao(getMyBatis()); - } + ActionPlanDao dao = dbTester.getDbClient().actionPlanDao(); @Test public void should_insert_new_action_plan() { @@ -92,13 +84,11 @@ public class ActionPlanDaoTest extends AbstractDaoTestCase { public void should_find_by_keys_on_huge_number_of_keys() { setupData("shared"); - SqlSession session = getMyBatis().openSession(); List<String> hugeNbOKeys = newArrayList(); for (int i = 0; i < 4500; i++) { hugeNbOKeys.add("ABCD" + i); } List<ActionPlanDto> result = dao.findByKeys(hugeNbOKeys); - MyBatis.closeQuietly(session); // The goal of this test is only to check that the query do no fail, not to check the number of results assertThat(result).isEmpty(); diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index 0da36e52b04..1c6e6f67b8f 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -27,6 +27,7 @@ import org.sonar.db.AbstractDaoTestCase; import org.sonar.db.MyBatis; import static com.google.common.collect.Lists.newArrayList; +import static org.assertj.core.api.Assertions.assertThat; public class PurgeCommandsTest extends AbstractDaoTestCase { @@ -117,7 +118,12 @@ public class PurgeCommandsTest extends AbstractDaoTestCase { new PurgeCommands(session, profiler).deleteResources(newArrayList(new IdUuidPair(1L, "1"))); } - assertEmptyTables("projects", "snapshots", "events", "issues", "issue_changes", "authors"); + assertThat(dbTester.countRowsOfTable("projects")).isZero(); + assertThat(dbTester.countRowsOfTable("snapshots")).isZero(); + assertThat(dbTester.countRowsOfTable("events")).isZero(); + assertThat(dbTester.countRowsOfTable("issues")).isZero(); + assertThat(dbTester.countRowsOfTable("issue_changes")).isZero(); + assertThat(dbTester.countRowsOfTable("authors")).isZero(); } /** diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 11aa33abc18..0417fb5e919 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -20,61 +20,46 @@ package org.sonar.db.purge; import java.util.List; -import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.sonar.api.resources.Scopes; import org.sonar.api.utils.System2; -import org.sonar.db.AbstractDaoTestCase; -import org.sonar.db.DbSession; -import org.sonar.db.MyBatis; -import org.sonar.db.component.ResourceDao; +import org.sonar.db.DbTester; +import org.sonar.test.DbTests; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class PurgeDaoTest extends AbstractDaoTestCase { +@Category(DbTests.class) +public class PurgeDaoTest { - private PurgeDao sut; - private System2 system2; - private DbSession dbSession; + System2 system2 = mock(System2.class); - private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) { - for (PurgeableSnapshotDto snapshot : snapshots) { - if (snapshot.getSnapshotId() == id) { - return snapshot; - } - } - return null; - } + @Rule + public DbTester dbTester = DbTester.create(system2); + + PurgeDao sut = dbTester.getDbClient().purgeDao(); @Before public void before() { - system2 = mock(System2.class); when(system2.now()).thenReturn(1450000000000L); - dbSession = getMyBatis().openSession(false); - - sut = new PurgeDao(getMyBatis(), new ResourceDao(getMyBatis(), system2), system2); - } - - @After - public void after() { - MyBatis.closeQuietly(dbSession); } @Test public void shouldDeleteAbortedBuilds() { - setupData("shouldDeleteAbortedBuilds"); + dbTester.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml"); sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("shouldDeleteAbortedBuilds", "snapshots"); + dbTester.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots"); } @Test public void should_purge_project() { - setupData("shouldPurgeProject"); + dbTester.prepareDbUnit(getClass(), "shouldPurgeProject.xml"); sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("shouldPurgeProject", "projects", "snapshots"); + dbTester.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots"); } private PurgeConfiguration newConfigurationWith30Days() { @@ -87,35 +72,35 @@ public class PurgeDaoTest extends AbstractDaoTestCase { @Test public void delete_file_sources_of_disabled_resources() { - setupData("delete_file_sources_of_disabled_resources"); + dbTester.prepareDbUnit(getClass(), "delete_file_sources_of_disabled_resources.xml"); sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("delete_file_sources_of_disabled_resources", "file_sources"); + dbTester.assertDbUnit(getClass(), "delete_file_sources_of_disabled_resources-result.xml", "file_sources"); } @Test public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() { - setupData("shouldDeleteHistoricalDataOfDirectoriesAndFiles"); + dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml"); sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[] {Scopes.DIRECTORY, Scopes.FILE}, 30), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("shouldDeleteHistoricalDataOfDirectoriesAndFiles", "projects", "snapshots"); + dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots"); } @Test public void disable_resources_without_last_snapshot() { - setupData("disable_resources_without_last_snapshot"); + dbTester.prepareDbUnit(getClass(), "disable_resources_without_last_snapshot.xml"); sut.purge(newConfigurationWith30Days(system2), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("disable_resources_without_last_snapshot", new String[] {"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues"); + dbTester.assertDbUnit(getClass(), "disable_resources_without_last_snapshot-result.xml", new String[]{"issue_close_date", "issue_update_date"}, "projects", "snapshots", "issues"); } @Test public void shouldDeleteSnapshots() { - setupData("shouldDeleteSnapshots"); + dbTester.prepareDbUnit(getClass(), "shouldDeleteSnapshots.xml"); sut.deleteSnapshots(PurgeSnapshotQuery.create().setIslast(false).setResourceId(1L), new PurgeProfiler()); - checkTables("shouldDeleteSnapshots", "snapshots"); + dbTester.assertDbUnit(getClass(), "shouldDeleteSnapshots-result.xml", "snapshots"); } @Test public void shouldSelectPurgeableSnapshots() { - setupData("shouldSelectPurgeableSnapshots"); + dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableSnapshots.xml"); List<PurgeableSnapshotDto> snapshots = sut.selectPurgeableSnapshots(1L); assertThat(snapshots).hasSize(3); @@ -129,31 +114,45 @@ public class PurgeDaoTest extends AbstractDaoTestCase { @Test public void should_delete_project_and_associated_data() { - setupData("shouldDeleteProject"); + dbTester.prepareDbUnit(getClass(), "shouldDeleteProject.xml"); sut.deleteResourceTree(new IdUuidPair(1L, "A"), new PurgeProfiler()); - assertEmptyTables("projects", "snapshots", "action_plans", "issues", "issue_changes", "file_sources"); + assertThat(dbTester.countRowsOfTable("projects")).isZero(); + assertThat(dbTester.countRowsOfTable("snapshots")).isZero(); + assertThat(dbTester.countRowsOfTable("action_plans")).isZero(); + assertThat(dbTester.countRowsOfTable("issues")).isZero(); + assertThat(dbTester.countRowsOfTable("issue_changes")).isZero(); + assertThat(dbTester.countRowsOfTable("file_sources")).isZero(); } @Test public void should_delete_old_closed_issues() { - setupData("should_delete_old_closed_issues"); + dbTester.prepareDbUnit(getClass(), "should_delete_old_closed_issues.xml"); sut.purge(newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("should_delete_old_closed_issues", "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_delete_old_closed_issues-result.xml", "issues", "issue_changes"); } @Test public void should_delete_all_closed_issues() { - setupData("should_delete_all_closed_issues"); + dbTester.prepareDbUnit(getClass(), "should_delete_all_closed_issues.xml"); sut.purge(new PurgeConfiguration(new IdUuidPair(1L, "1"), new String[0], 0), PurgeListener.EMPTY, new PurgeProfiler()); - checkTables("should_delete_all_closed_issues", "issues", "issue_changes"); + dbTester.assertDbUnit(getClass(), "should_delete_all_closed_issues-result.xml", "issues", "issue_changes"); } @Test public void select_purgeable_file_uuids_and_only_them() { - setupData("select_purgeable_file_uuids"); + dbTester.prepareDbUnit(getClass(), "select_purgeable_file_uuids.xml"); - List<String> uuids = sut.selectPurgeableFiles(dbSession, 1L); + List<String> uuids = sut.selectPurgeableFiles(dbTester.getSession(), 1L); assertThat(uuids).containsOnly("GHIJ"); } + + private static PurgeableSnapshotDto getById(List<PurgeableSnapshotDto> snapshots, long id) { + for (PurgeableSnapshotDto snapshot : snapshots) { + if (snapshot.getSnapshotId() == id) { + return snapshot; + } + } + return null; + } } diff --git a/sonar-db/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java b/sonar-db/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java index 8e2840e09df..daa5b1d5777 100644 --- a/sonar-db/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/qualitygate/QualityGateConditionDaoTest.java @@ -31,16 +31,11 @@ public class QualityGateConditionDaoTest extends AbstractDaoTestCase { "id", "qgate_id", "metric_id", "operator", "value_warning", "value_error", "period" }; - private static QualityGateConditionDao dao; - - @Before - public void createDao() { - dao = new QualityGateConditionDao(getMyBatis()); - } + QualityGateConditionDao dao = dbTester.getDbClient().gateConditionDao(); @Test public void testInsert() throws Exception { - setupData("insert"); + setupData("insert.xml"); QualityGateConditionDto newCondition = new QualityGateConditionDto() .setQualityGateId(1L).setMetricId(2L).setOperator("GT").setWarningThreshold("10").setErrorThreshold("20").setPeriod(3); dao.insert(newCondition); @@ -50,14 +45,14 @@ public class QualityGateConditionDaoTest extends AbstractDaoTestCase { @Test public void testSelectForQualityGate() throws Exception { - setupData("selectForQualityGate"); + setupData("selectForQualityGate.xml"); assertThat(dao.selectForQualityGate(1L)).hasSize(3); assertThat(dao.selectForQualityGate(2L)).hasSize(2); } @Test public void testSelectById() throws Exception { - setupData("selectForQualityGate"); + setupData("selectForQualityGate.xml"); QualityGateConditionDto selectById = dao.selectById(1L); assertThat(selectById).isNotNull(); assertThat(selectById.getId()).isNotNull().isNotEqualTo(0L); @@ -72,21 +67,22 @@ public class QualityGateConditionDaoTest extends AbstractDaoTestCase { @Test public void testDelete() throws Exception { - setupData("selectForQualityGate"); + setupData("selectForQualityGate.xml"); dao.delete(new QualityGateConditionDto().setId(1L)); checkTable("delete", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS); } @Test public void testUpdate() throws Exception { - setupData("selectForQualityGate"); + setupData("selectForQualityGate.xml"); dao.update(new QualityGateConditionDto().setId(1L).setMetricId(7L).setOperator(">").setPeriod(1).setWarningThreshold("50").setErrorThreshold("80")); - checkTable("update", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS); + checkTable("update-result.xml", "quality_gate_conditions", COLUMNS_WITHOUT_TIMESTAMPS); } + @Test public void shouldCleanConditions() { - setupData("shouldCleanConditions"); + setupData("shouldCleanConditions.xml"); dao.deleteConditionsWithInvalidMetrics(); - checkTables("shouldCleanConditions", "quality_gate_conditions"); + checkTables("shouldCleanConditions-result.xml", new String[]{"created_at", "updated_at"}, "quality_gate_conditions"); } } diff --git a/sonar-db/src/test/java/org/sonar/db/user/AuthorDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/AuthorDaoTest.java index 9cda23c3417..4c845c60381 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/AuthorDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/AuthorDaoTest.java @@ -19,11 +19,8 @@ */ package org.sonar.db.user; -import org.junit.Before; import org.junit.Test; -import org.sonar.api.utils.System2; import org.sonar.db.AbstractDaoTestCase; -import org.sonar.db.component.ResourceDao; import org.sonar.db.component.ResourceDto; import static org.assertj.core.api.Assertions.assertThat; @@ -31,12 +28,7 @@ import static org.junit.Assert.fail; public class AuthorDaoTest extends AbstractDaoTestCase { - private AuthorDao dao; - - @Before - public void setUp() { - dao = new AuthorDao(getMyBatis(), new ResourceDao(getMyBatis(), System2.INSTANCE)); - } + AuthorDao dao = dbTester.getDbClient().authorDao(); @Test public void shouldSelectByLogin() { diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml index aff69473ce1..aff69473ce1 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/select_project_ids_from_query_and_view_or_sub_view_uuid.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject-result.xml index 48899d945c3..48899d945c3 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml index a1cd4ef6f5a..a1cd4ef6f5a 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexMultiModulesProject.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml index ee9ab480a7c..ee9ab480a7c 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects.xml index 0043b4ced0b..0043b4ced0b 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexProjects.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexProjects.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource-result.xml index f4cf0805ede..f4cf0805ede 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource.xml index 5a4a28b7df3..5a4a28b7df3 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexResource.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource-result.xml index c9941e492bd..c9941e492bd 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource.xml index 5a4a28b7df3..5a4a28b7df3 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldIndexTwoLettersLongResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldIndexTwoLettersLongResource.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotIndexPackages.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml index 0043b4ced0b..0043b4ced0b 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotIndexPackages.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotIndexPackages.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource-result.xml index 4292af5708d..4292af5708d 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource.xml index 89a3a8c465d..89a3a8c465d 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldNotReindexUnchangedResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldNotReindexUnchangedResource.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml index 52db35f3ad4..52db35f3ad4 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml index af5863edbda..af5863edbda 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexNewTwoLettersLongResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexNewTwoLettersLongResource.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource-result.xml index 52db35f3ad4..52db35f3ad4 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml index 529e83c1a44..529e83c1a44 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReIndexTwoLettersLongResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReIndexTwoLettersLongResource.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml index e28b5945816..e28b5945816 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml index 84815e52e64..84815e52e64 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexProjectAfterRenaming.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource-result.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource-result.xml index b9f39157aea..b9f39157aea 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource-result.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource-result.xml diff --git a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource.xml b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource.xml index 89a3a8c465d..89a3a8c465d 100644 --- a/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexerDaoTest/shouldReindexResource.xml +++ b/sonar-db/src/test/resources/org/sonar/db/component/ResourceIndexDaoTest/shouldReindexResource.xml |