From bc8d33b22754a60417a7979f35011280fa53149a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Fri, 26 Feb 2016 14:45:52 +0100 Subject: [PATCH] SONAR-7330 Remove old RuleDao and ActiveRuleDao --- .../java/org/sonar/server/db/DbClient.java | 14 - .../sonar/server/debt/DebtModelBackup.java | 6 +- .../platformlevel/PlatformLevel1.java | 6 - .../RuleActivatorContextFactory.java | 10 +- .../qualityprofile/db/ActiveRuleDao.java | 257 --------- .../qualityprofile/db/package-info.java | 23 - .../index/ActiveRuleNormalizer.java | 7 +- .../qualityprofile/ws/ChangelogAction.java | 7 +- .../org/sonar/server/rule/db/RuleDao.java | 134 ----- .../sonar/server/rule/db/package-info.java | 22 - .../server/rule/index/RuleNormalizer.java | 9 +- .../org/sonar/server/db/DbClientTest.java | 62 -- .../server/debt/DebtModelBackupTest.java | 23 +- .../IssueBulkChangeServiceMediumTest.java | 6 +- .../issue/IssueCommentServiceMediumTest.java | 6 +- .../server/issue/IssueServiceMediumTest.java | 4 +- .../ws/SearchActionComponentsMediumTest.java | 8 +- .../issue/ws/SearchActionMediumTest.java | 4 +- .../project/ws/BulkDeleteActionTest.java | 27 +- .../server/project/ws/DeleteActionTest.java | 27 +- .../server/qualityprofile/ActiveRuleTest.java | 529 ------------------ .../ws/ChangelogActionTest.java | 20 +- .../org/sonar/server/rule/db/RuleDaoTest.java | 332 ----------- .../rule/ws/CreateActionMediumTest.java | 7 +- .../server/rule/ws/RulesWsMediumTest.java | 2 +- .../rule/ws/SearchActionMediumTest.java | 6 +- .../server/rule/ws/ShowActionMediumTest.java | 123 ++-- .../rule/ws/UpdateActionMediumTest.java | 12 +- .../db/ActiveRuleDaoTest/delete-result.xml | 9 - .../delete_from_profile-result.xml | 9 - .../delete_from_rule-result.xml | 9 - .../delete_parameter-result.xml | 12 - .../delete_parameters-result.xml | 12 - ...lete_parameters_from_profile_id-result.xml | 16 - .../delete_parameters_from_profile_id.xml | 16 - .../db/ActiveRuleDaoTest/empty.xml | 9 - .../db/ActiveRuleDaoTest/insert-result.xml | 5 - .../insert_parameter-result.xml | 5 - .../db/ActiveRuleDaoTest/insert_parameter.xml | 11 - .../db/ActiveRuleDaoTest/shared.xml | 26 - .../db/ActiveRuleDaoTest/update-result.xml | 9 - .../update_parameter-result.xml | 8 - .../server/rule/db/RuleDaoTest/empty.xml | 3 - .../rule/db/RuleDaoTest/insert-result.xml | 15 - .../rule/db/RuleDaoTest/insert_all-result.xml | 25 - .../RuleDaoTest/insert_parameter-result.xml | 13 - .../rule/db/RuleDaoTest/insert_parameter.xml | 12 - .../server/rule/db/RuleDaoTest/selectAll.xml | 14 - .../server/rule/db/RuleDaoTest/selectById.xml | 10 - .../rule/db/RuleDaoTest/selectNonManual.xml | 10 - .../rule/db/RuleDaoTest/selectParameters.xml | 9 - .../rule/db/RuleDaoTest/select_by_name.xml | 10 - .../db/RuleDaoTest/select_by_rule_key.xml | 10 - .../select_by_sub_characteristic_id.xml | 43 -- .../select_parameters_by_language.xml | 18 - .../select_parameters_by_rule_id.xml | 15 - .../select_parameters_by_rule_ids.xml | 16 - .../rule/db/RuleDaoTest/update-result.xml | 32 -- .../server/rule/db/RuleDaoTest/update.xml | 21 - .../RuleDaoTest/update_parameter-result.xml | 8 - .../rule/db/RuleDaoTest/update_parameter.xml | 7 - 61 files changed, 133 insertions(+), 2007 deletions(-) delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/package-info.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java delete mode 100644 server/sonar-server/src/main/java/org/sonar/server/rule/db/package-info.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleTest.java delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_profile-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_rule-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameter-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/empty.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/shared.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update_parameter-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/empty.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_all-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectAll.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectById.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectNonManual.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectParameters.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_name.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_rule_key.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_sub_characteristic_id.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_language.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_id.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_ids.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter-result.xml delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter.xml diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java index ea36495f8c2..a47a99bb4f3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/DbClient.java @@ -23,8 +23,6 @@ import java.util.Map; import org.sonar.db.Dao; import org.sonar.db.Database; import org.sonar.db.MyBatis; -import org.sonar.server.qualityprofile.db.ActiveRuleDao; -import org.sonar.server.rule.db.RuleDao; /** * Should be replaced by {@link org.sonar.db.DbClient}, but some DAOs @@ -34,24 +32,12 @@ import org.sonar.server.rule.db.RuleDao; @Deprecated public class DbClient extends org.sonar.db.DbClient { - private ActiveRuleDao activeRuleDao; - private RuleDao ruleDao; - public DbClient(Database database, MyBatis myBatis, Dao... daos) { super(database, myBatis, daos); } @Override protected void doOnLoad(Map daoByClass) { - this.activeRuleDao = (ActiveRuleDao) daoByClass.get(ActiveRuleDao.class); - this.ruleDao = (RuleDao) daoByClass.get(RuleDao.class); - } - - public ActiveRuleDao deprecatedActiveRuleDao() { - return activeRuleDao; } - public RuleDao deprecatedRuleDao() { - return ruleDao; - } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java index 0f73e6d850c..aed342810d7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java +++ b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java @@ -35,10 +35,10 @@ import org.sonar.api.utils.ValidationMessages; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.MyBatis; import org.sonar.db.rule.RuleDto; -import org.sonar.server.db.DbClient; import org.sonar.server.debt.DebtModelXMLExporter.RuleDebt; import org.sonar.server.rule.RuleDefinitionsLoader; import org.sonar.server.rule.RuleOperations; @@ -154,8 +154,8 @@ public class DebtModelBackup { rule.setRemediationFunction(null); rule.setRemediationCoefficient(null); rule.setRemediationOffset(null); - rule.setUpdatedAt(updateDate); - dbClient.deprecatedRuleDao().update(session, rule); + rule.setUpdatedAtInMs(updateDate.getTime()); + dbClient.ruleDao().update(session, rule); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java index cfbf3199350..b80f2732985 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel1.java @@ -42,11 +42,9 @@ import org.sonar.server.platform.Platform; import org.sonar.server.platform.ServerImpl; import org.sonar.server.platform.ServerSettings; import org.sonar.server.platform.TempFolderProvider; -import org.sonar.server.qualityprofile.db.ActiveRuleDao; import org.sonar.server.qualityprofile.index.ActiveRuleIndex2; import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer; import org.sonar.server.ruby.PlatformRackBridge; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.rule.index.RuleIndex2; import org.sonar.server.rule.index.RuleNormalizer; import org.sonar.server.search.EsSearchModule; @@ -103,10 +101,6 @@ public class PlatformLevel1 extends PlatformLevel { // Elasticsearch EsSearchModule.class, - // DAOs to be moved to sonar-db - RuleDao.class, - ActiveRuleDao.class, - // rules/qprofiles RuleIndex2.class, ActiveRuleIndex2.class, diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java index 8ae46b3c39d..17f0217d8c8 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/RuleActivatorContextFactory.java @@ -76,13 +76,13 @@ public class RuleActivatorContextFactory { } private RuleDto initRule(RuleKey ruleKey, RuleActivatorContext context, DbSession dbSession) { - RuleDto rule = db.deprecatedRuleDao().getNullableByKey(dbSession, ruleKey); - if (rule == null) { + Optional rule = db.ruleDao().selectByKey(dbSession, ruleKey); + if (!rule.isPresent()) { throw new BadRequestException("Rule not found: " + ruleKey); } - context.setRule(rule); - context.setRuleParams(db.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, rule.getKey())); - return rule; + context.setRule(rule.get()); + context.setRuleParams(db.ruleDao().selectRuleParamsByRuleKey(dbSession, rule.get().getKey())); + return rule.get(); } private void initActiveRules(String profileKey, RuleKey ruleKey, RuleActivatorContext context, DbSession session, boolean parent) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java deleted file mode 100644 index a9b0656fa4d..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/ActiveRuleDao.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualityprofile.db; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import java.util.List; -import javax.annotation.CheckForNull; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.sonar.api.utils.System2; -import org.sonar.db.DatabaseUtils; -import org.sonar.db.DbSession; -import org.sonar.db.qualityprofile.ActiveRuleDto; -import org.sonar.db.qualityprofile.ActiveRuleKey; -import org.sonar.db.qualityprofile.SqlActiveRuleKey; -import org.sonar.db.qualityprofile.ActiveRuleMapper; -import org.sonar.db.qualityprofile.ActiveRuleParamDto; -import org.sonar.db.qualityprofile.QualityProfileDao; -import org.sonar.db.qualityprofile.QualityProfileDto; -import org.sonar.db.rule.RuleDto; -import org.sonar.server.db.BaseDao; -import org.sonar.server.rule.db.RuleDao; -import org.sonar.server.search.IndexDefinition; - -import static java.util.Collections.emptyList; - -@Deprecated -public class ActiveRuleDao extends BaseDao { - - private static final String QUALITY_PROFILE_IS_NOT_PERSISTED = "Quality profile is not persisted (missing id)"; - private static final String RULE_IS_NOT_PERSISTED = "Rule is not persisted"; - private static final String RULE_PARAM_IS_NOT_PERSISTED = "Rule param is not persisted"; - private static final String ACTIVE_RULE_KEY_CANNOT_BE_NULL = "ActiveRuleKey cannot be null"; - private static final String ACTIVE_RULE_IS_NOT_PERSISTED = "ActiveRule is not persisted"; - private static final String ACTIVE_RULE_IS_ALREADY_PERSISTED = "ActiveRule is already persisted"; - private static final String ACTIVE_RULE_PARAM_IS_NOT_PERSISTED = "ActiveRuleParam is not persisted"; - private static final String ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED = "ActiveRuleParam is already persisted"; - private static final String PARAMETER_NAME_CANNOT_BE_NULL = "ParameterName cannot be null"; - - // TODO remove once key is finalized (used only to get id for SQL statement) - private final RuleDao ruleDao; - private final QualityProfileDao profileDao; - - public ActiveRuleDao(QualityProfileDao profileDao, RuleDao ruleDao, System2 system) { - super(IndexDefinition.ACTIVE_RULE, ActiveRuleMapper.class, system); - this.ruleDao = ruleDao; - this.profileDao = profileDao; - } - - @CheckForNull - @Deprecated - public ActiveRuleDto selectById(DbSession session, int activeRuleId) { - ActiveRuleDto activeRule = mapper(session).selectById(activeRuleId); - if (activeRule != null) { - QualityProfileDto profile = profileDao.selectById(session, activeRule.getProfileId()); - RuleDto rule = ruleDao.selectById(session, activeRule.getRuleId()); - if (profile != null && rule != null) { - activeRule.setKey(ActiveRuleKey.of(profile.getKey(), rule.getKey())); - return activeRule; - } - } - return null; - } - - @Override - protected ActiveRuleDto doGetNullableByKey(DbSession session, ActiveRuleKey key) { - return mapper(session).selectByKey(key.qProfile(), key.ruleKey().repository(), key.ruleKey().rule()); - } - - @Override - protected ActiveRuleDto doInsert(DbSession session, ActiveRuleDto item) { - Preconditions.checkArgument(item.getProfileId() != null, QUALITY_PROFILE_IS_NOT_PERSISTED); - Preconditions.checkArgument(item.getRuleId() != null, RULE_IS_NOT_PERSISTED); - Preconditions.checkArgument(item.getId() == null, ACTIVE_RULE_IS_ALREADY_PERSISTED); - mapper(session).insert(item); - return item; - } - - @Override - protected ActiveRuleDto doUpdate(DbSession session, ActiveRuleDto item) { - Preconditions.checkArgument(item.getProfileId() != null, QUALITY_PROFILE_IS_NOT_PERSISTED); - Preconditions.checkArgument(item.getRuleId() != null, ActiveRuleDao.RULE_IS_NOT_PERSISTED); - Preconditions.checkArgument(item.getId() != null, ACTIVE_RULE_IS_NOT_PERSISTED); - mapper(session).update(item); - return item; - } - - @Override - protected void doDeleteByKey(DbSession session, ActiveRuleKey key) { - ActiveRuleDto activeRule = getNullableByKey(session, key); - if (activeRule != null) { - mapper(session).deleteParameters(activeRule.getId()); - mapper(session).delete(activeRule.getId()); - } - } - - /** - * Finder methods for Rules - */ - - public List selectByRule(DbSession dbSession, RuleDto rule) { - Preconditions.checkNotNull(rule.getId(), RULE_IS_NOT_PERSISTED); - return mapper(dbSession).selectByRuleId(rule.getId()); - } - - public List selectAll(DbSession dbSession) { - return mapper(dbSession).selectAll(); - } - - public List selectAllParams(DbSession dbSession) { - return mapper(dbSession).selectAllParams(); - } - - public Optional selectByActiveRuleKey(DbSession dbSession, ActiveRuleKey key) { - return Optional.fromNullable(mapper(dbSession).selectByKey(key.qProfile(), key.ruleKey().repository(), key.ruleKey().rule())); - } - - public List selectByActiveRuleKeys(final DbSession dbSession, final List keys) { - if (keys.isEmpty()) { - return emptyList(); - } - - List sqlKeys = new ArrayList<>(); - for (ActiveRuleKey key : keys) { - sqlKeys.add(new SqlActiveRuleKey(key)); - } - - return DatabaseUtils.executeLargeInputs(sqlKeys, new Function, List>() { - @Override - public List apply(@Nonnull List input) { - return mapper(dbSession).selectByKeys(input); - } - }); - } - - /** - * Nested DTO ActiveRuleParams - */ - - public ActiveRuleParamDto insertParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { - Preconditions.checkArgument(activeRule.getId() != null, ACTIVE_RULE_IS_NOT_PERSISTED); - Preconditions.checkArgument(activeRuleParam.getId() == null, ACTIVE_RULE_PARAM_IS_ALREADY_PERSISTED); - Preconditions.checkNotNull(activeRuleParam.getRulesParameterId(), RULE_PARAM_IS_NOT_PERSISTED); - - activeRuleParam.setActiveRuleId(activeRule.getId()); - mapper(session).insertParameter(activeRuleParam); - this.enqueueInsert(activeRuleParam, activeRule.getKey(), session); - return activeRuleParam; - } - - public void deleteParamByKeyAndName(DbSession session, ActiveRuleKey key, String param) { - // TODO SQL rewrite to delete by key - ActiveRuleDto activeRule = getNullableByKey(session, key); - if (activeRule != null) { - ActiveRuleParamDto activeRuleParam = mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), param); - if (activeRuleParam != null) { - mapper(session).deleteParameter(activeRuleParam.getId()); - } - } - } - - public void updateParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { - Preconditions.checkNotNull(activeRule.getId(), ACTIVE_RULE_IS_NOT_PERSISTED); - Preconditions.checkNotNull(activeRuleParam.getId(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED); - mapper(session).updateParameter(activeRuleParam); - this.enqueueUpdate(activeRuleParam, activeRule.getKey(), session); - } - - public void deleteParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { - Preconditions.checkNotNull(activeRule.getId(), ACTIVE_RULE_IS_NOT_PERSISTED); - Preconditions.checkNotNull(activeRuleParam.getId(), ACTIVE_RULE_PARAM_IS_NOT_PERSISTED); - mapper(session).deleteParameter(activeRuleParam.getId()); - this.enqueueDelete(activeRuleParam, activeRule.getKey(), session); - } - - public void deleteByProfileKey(DbSession session, String profileKey) { - /** Functional cascade for params */ - for (ActiveRuleDto activeRule : selectByProfileKey(session, profileKey)) { - delete(session, activeRule); - } - } - - public List selectByProfileKey(DbSession session, String profileKey) { - return mapper(session).selectByProfileKey(profileKey); - } - - /** - * Finder methods for ActiveRuleParams - */ - - public List selectParamsByActiveRuleKey(DbSession session, ActiveRuleKey key) { - Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL); - ActiveRuleDto activeRule = this.getByKey(session, key); - return mapper(session).selectParamsByActiveRuleId(activeRule.getId()); - } - - public List selectParamsByActiveRuleId(DbSession dbSession, Integer activeRuleId) { - return mapper(dbSession).selectParamsByActiveRuleId(activeRuleId); - } - - public List selectParamsByActiveRuleIds(final DbSession dbSession, List activeRuleIds) { - if (activeRuleIds.isEmpty()) { - return emptyList(); - } - - return DatabaseUtils.executeLargeInputs(activeRuleIds, new Function, List>() { - @Override - public List apply(@Nullable List input) { - return mapper(dbSession).selectParamsByActiveRuleIds(input); - } - }); - } - - @CheckForNull - public ActiveRuleParamDto selectParamByKeyAndName(ActiveRuleKey key, String name, DbSession session) { - Preconditions.checkNotNull(key, ACTIVE_RULE_KEY_CANNOT_BE_NULL); - Preconditions.checkNotNull(name, PARAMETER_NAME_CANNOT_BE_NULL); - ActiveRuleDto activeRule = getNullableByKey(session, key); - if (activeRule != null) { - return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), name); - } - return null; - } - - public void deleteParamsByRuleParam(DbSession dbSession, RuleDto rule, String paramKey) { - List activeRules = selectByRule(dbSession, rule); - for (ActiveRuleDto activeRule : activeRules) { - for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleKey(dbSession, activeRule.getKey())) { - if (activeParam.getKey().equals(paramKey)) { - deleteParam(dbSession, activeRule, activeParam); - } - } - } - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/package-info.java deleted file mode 100644 index f9e750d2df3..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/db/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault -package org.sonar.server.qualityprofile.db; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java index bb57481a027..df27cd9773b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleNormalizer.java @@ -104,10 +104,7 @@ public class ActiveRuleNormalizer extends BaseNormalizer result = new Result<>(response); for (SearchHit hit : response.getHits().getHits()) { QProfileActivity profileActivity = new QProfileActivity(hit.getSource()); - RuleDto ruleDto = dbClient.deprecatedRuleDao().getNullableByKey(session, profileActivity.ruleKey()); - profileActivity.ruleName(ruleDto != null ? ruleDto.getName() : null); + Optional ruleDto = dbClient.ruleDao().selectByKey(session, profileActivity.ruleKey()); + profileActivity.ruleName(ruleDto.isPresent() ? ruleDto.get().getName() : null); String login = profileActivity.getLogin(); if (login != null) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java b/server/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java deleted file mode 100644 index a9f830e0d0c..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/db/RuleDao.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule.db; - -import com.google.common.base.Preconditions; -import java.util.List; -import javax.annotation.CheckForNull; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.utils.System2; -import org.sonar.db.DbSession; -import org.sonar.db.rule.RuleDto; -import org.sonar.db.rule.RuleMapper; -import org.sonar.db.rule.RuleParamDto; -import org.sonar.server.db.BaseDao; -import org.sonar.server.search.IndexDefinition; - -public class RuleDao extends BaseDao { - - public RuleDao(System2 system) { - super(IndexDefinition.RULE, RuleMapper.class, system); - } - - @Override - public RuleDto doGetNullableByKey(DbSession session, RuleKey key) { - return mapper(session).selectByKey(key); - } - - public RuleDto getByName(String name, DbSession session) { - return mapper(session).selectByName(name); - } - - @Override - protected RuleDto doInsert(DbSession session, RuleDto item) { - mapper(session).insert(item); - return item; - } - - @Override - protected RuleDto doUpdate(DbSession session, RuleDto item) { - mapper(session).update(item); - return item; - } - - @Override - protected void doDeleteByKey(DbSession session, RuleKey key) { - throw new UnsupportedOperationException("Rules cannot be deleted"); - } - - @CheckForNull - public RuleDto selectById(DbSession session, int id) { - return mapper(session).selectById(id); - } - - @CheckForNull - public RuleDto selectTemplate(RuleDto rule, DbSession session) { - Preconditions.checkNotNull(rule.getTemplateId(), "Rule has no persisted template!"); - return mapper(session).selectById(rule.getTemplateId()); - } - - /** - * Finder methods for Rules - */ - - public List selectByNonManual(DbSession session) { - return mapper(session).selectNonManual(); - } - - public List selectAll(DbSession session) { - return mapper(session).selectAll(); - } - - /** - * Nested DTO RuleParams - */ - - public void insertRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { - Preconditions.checkNotNull(rule.getId(), "Rule id must be set"); - param.setRuleId(rule.getId()); - mapper(session).insertParameter(param); - this.enqueueInsert(param, rule.getKey(), session); - } - - public RuleParamDto updateRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { - Preconditions.checkNotNull(rule.getId(), "Rule id must be set"); - Preconditions.checkNotNull(param.getId(), "Param is not yet persisted must be set"); - param.setRuleId(rule.getId()); - mapper(session).updateParameter(param); - this.enqueueUpdate(param, rule.getKey(), session); - return param; - } - - public void deleteRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { - Preconditions.checkNotNull(param.getId(), "Param is not persisted"); - mapper(session).deleteParameter(param.getId()); - this.enqueueDelete(param, rule.getKey(), session); - } - - /** - * Finder methods for RuleParams - */ - - public List selectAllRuleParams(DbSession session) { - return mapper(session).selectAllParams(); - } - - public List selectRuleParamsByRuleKey(DbSession session, RuleKey key) { - return mapper(session).selectParamsByRuleKey(key); - } - - public List selectRulesByDebtSubCharacteristicId(DbSession session, int id) { - return mapper(session).selectBySubCharacteristicId(id); - } - - public List selectEnabledAndNonManual(DbSession session) { - return mapper(session).selectEnabledAndNonManual(); - } -} diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/db/package-info.java b/server/sonar-server/src/main/java/org/sonar/server/rule/db/package-info.java deleted file mode 100644 index 82875a93fd1..00000000000 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/db/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -@ParametersAreNonnullByDefault package org.sonar.server.rule.db; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java index 1ae6050a094..1573785d7a1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/index/RuleNormalizer.java @@ -19,6 +19,7 @@ */ package org.sonar.server.rule.index; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -179,9 +180,9 @@ public class RuleNormalizer extends BaseNormalizer { Integer templateId = rule.getTemplateId(); String templateKeyFieldValue = null; if (templateId != null) { - RuleDto templateRule = db.deprecatedRuleDao().selectById(session, templateId); - if (templateRule != null) { - RuleKey templateKey = templateRule.getKey(); + Optional templateRule = db.ruleDao().selectById(templateId, session); + if (templateRule.isPresent()) { + RuleKey templateKey = templateRule.get().getKey(); templateKeyFieldValue = templateKey != null ? templateKey.toString() : null; } } @@ -223,7 +224,7 @@ public class RuleNormalizer extends BaseNormalizer { .doc(update) .upsert(upsert)); - for (RuleParamDto param : db.deprecatedRuleDao().selectRuleParamsByRuleKey(session, rule.getKey())) { + for (RuleParamDto param : db.ruleDao().selectRuleParamsByRuleKey(session, rule.getKey())) { requests.addAll(normalizeNested(param, rule.getKey())); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java deleted file mode 100644 index cdd1537afa5..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/db/DbClientTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.db; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.sonar.api.utils.System2; -import org.sonar.db.DbSession; -import org.sonar.db.DbTester; -import org.sonar.db.MyBatis; -import org.sonar.db.qualityprofile.QualityProfileDao; -import org.sonar.server.qualityprofile.db.ActiveRuleDao; -import org.sonar.server.rule.db.RuleDao; -import org.sonar.test.DbTests; - -import static org.assertj.core.api.Assertions.assertThat; - -@Category(DbTests.class) -public class DbClientTest { - - @Rule - public DbTester db = DbTester.create(System2.INSTANCE); - - @Test - public void get_daos() throws Exception { - MyBatis myBatis = db.myBatis(); - RuleDao ruleDao = new RuleDao(System2.INSTANCE); - QualityProfileDao qualityProfileDao = new QualityProfileDao(myBatis, System2.INSTANCE); - ActiveRuleDao activeRuleDao = new ActiveRuleDao(qualityProfileDao, ruleDao, System2.INSTANCE); - - DbClient client = new DbClient(db.database(), myBatis, ruleDao, activeRuleDao, qualityProfileDao); - - assertThat(client.getDatabase()).isSameAs(db.database()); - DbSession dbSession = client.openSession(true); - assertThat(dbSession).isNotNull(); - assertThat(dbSession.getConnection().isClosed()).isFalse(); - dbSession.close(); - - // DAO - assertThat(client.qualityProfileDao()).isSameAs(qualityProfileDao); - assertThat(client.deprecatedActiveRuleDao()).isSameAs(activeRuleDao); - assertThat(client.deprecatedRuleDao()).isSameAs(ruleDao); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java index b75c45c2a04..5a0db3f71c9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelBackupTest.java @@ -40,10 +40,10 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.api.utils.ValidationMessages; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; -import org.sonar.server.db.DbClient; import org.sonar.server.debt.DebtModelXMLExporter.RuleDebt; import org.sonar.server.rule.RuleDefinitionsLoader; import org.sonar.server.rule.RuleOperations; @@ -75,8 +75,6 @@ public class DebtModelBackupTest { @Mock RuleDao ruleDao; @Mock - org.sonar.server.rule.db.RuleDao deprecatedRuleDao; - @Mock RuleOperations ruleOperations; @Mock DebtRulesXMLImporter rulesXMLImporter; @@ -106,7 +104,6 @@ public class DebtModelBackupTest { currentId = 10; when(dbClient.openSession(false)).thenReturn(session); when(dbClient.ruleDao()).thenReturn(ruleDao); - when(dbClient.deprecatedRuleDao()).thenReturn(deprecatedRuleDao); underTest = new DebtModelBackup(dbClient, ruleOperations, rulesXMLImporter, debtModelXMLExporter, defLoader, system2, userSessionRule); @@ -246,7 +243,7 @@ public class DebtModelBackupTest { underTest.reset(); verify(ruleDao).selectEnabledAndNonManual(session); - verify(deprecatedRuleDao).update(eq(session), ruleCaptor.capture()); + verify(ruleDao).update(eq(session), ruleCaptor.capture()); verifyNoMoreInteractions(ruleDao); verify(session).commit(); @@ -256,12 +253,12 @@ public class DebtModelBackupTest { assertThat(rule.getDefaultRemediationFunction()).isEqualTo("LINEAR_OFFSET"); assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("4h"); assertThat(rule.getDefaultRemediationOffset()).isEqualTo("20min"); - assertThat(rule.getUpdatedAt()).isEqualTo(now); + assertThat(rule.getUpdatedAtInMs()).isEqualTo(now.getTime()); assertThat(rule.getRemediationFunction()).isNull(); assertThat(rule.getRemediationCoefficient()).isNull(); assertThat(rule.getRemediationOffset()).isNull(); - assertThat(rule.getUpdatedAt()).isEqualTo(now); + assertThat(rule.getUpdatedAtInMs()).isEqualTo(now.getTime()); } @Test @@ -288,7 +285,7 @@ public class DebtModelBackupTest { underTest.reset(); verify(ruleDao).selectEnabledAndNonManual(session); - verify(deprecatedRuleDao).update(eq(session), ruleCaptor.capture()); + verify(ruleDao).update(eq(session), ruleCaptor.capture()); verifyNoMoreInteractions(ruleDao); verify(session).commit(); @@ -297,7 +294,7 @@ public class DebtModelBackupTest { assertThat(rule.getDefaultRemediationFunction()).isNull(); assertThat(rule.getDefaultRemediationCoefficient()).isNull(); assertThat(rule.getDefaultRemediationOffset()).isNull(); - assertThat(rule.getUpdatedAt()).isEqualTo(now); + assertThat(rule.getUpdatedAtInMs()).isEqualTo(now.getTime()); } @Test @@ -330,7 +327,7 @@ public class DebtModelBackupTest { underTest.reset(); verify(ruleDao).selectEnabledAndNonManual(session); - verify(deprecatedRuleDao, times(2)).update(eq(session), ruleCaptor.capture()); + verify(ruleDao, times(2)).update(eq(session), ruleCaptor.capture()); verifyNoMoreInteractions(ruleDao); verify(session).commit(); @@ -340,12 +337,12 @@ public class DebtModelBackupTest { assertThat(rule.getDefaultRemediationFunction()).isEqualTo("LINEAR_OFFSET"); assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("4h"); assertThat(rule.getDefaultRemediationOffset()).isEqualTo("20min"); - assertThat(rule.getUpdatedAt()).isEqualTo(now); + assertThat(rule.getUpdatedAtInMs()).isEqualTo(now.getTime()); assertThat(rule.getRemediationFunction()).isNull(); assertThat(rule.getRemediationCoefficient()).isNull(); assertThat(rule.getRemediationOffset()).isNull(); - assertThat(rule.getUpdatedAt()).isEqualTo(now); + assertThat(rule.getUpdatedAtInMs()).isEqualTo(now.getTime()); } @Test @@ -355,7 +352,7 @@ public class DebtModelBackupTest { underTest.reset(); verify(ruleDao).selectEnabledAndNonManual(session); - verify(deprecatedRuleDao, never()).update(eq(session), any(RuleDto.class)); + verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); verifyZeroInteractions(defLoader); verify(session).commit(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java index db8abe13705..ce3f9e2c3b2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java @@ -36,19 +36,19 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; +import org.sonar.db.component.SnapshotTesting; import org.sonar.db.issue.IssueDao; import org.sonar.db.issue.IssueDto; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; -import org.sonar.db.component.ComponentTesting; -import org.sonar.db.component.SnapshotTesting; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.user.UserSession; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java index 791dfac1c16..7188ae8b0d0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java @@ -36,18 +36,18 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentTesting; import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; +import org.sonar.db.component.SnapshotTesting; import org.sonar.db.issue.IssueDao; import org.sonar.db.issue.IssueDto; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; -import org.sonar.db.component.ComponentTesting; -import org.sonar.db.component.SnapshotTesting; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.search.IndexClient; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java index 2658a61b427..2913daeb75d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java @@ -36,7 +36,6 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import org.sonar.api.security.DefaultGroups; import org.sonar.api.web.UserRole; -import org.sonar.server.issue.workflow.Transition; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -47,6 +46,7 @@ import org.sonar.db.issue.ActionPlanDto; import org.sonar.db.issue.IssueDao; import org.sonar.db.issue.IssueDto; import org.sonar.db.protobuf.DbFileSources; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.source.FileSourceDao; @@ -62,9 +62,9 @@ import org.sonar.server.issue.index.IssueDoc; import org.sonar.server.issue.index.IssueIndex; import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.issue.index.IssueIndexer; +import org.sonar.server.issue.workflow.Transition; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.rule.index.RuleIndexer; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java index 43438a7c7dd..c1c808e8712 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsMediumTest.java @@ -36,17 +36,15 @@ import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ComponentTesting; import org.sonar.db.issue.IssueDto; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; -import org.sonar.db.component.ComponentTesting; import org.sonar.server.issue.IssueTesting; -import org.sonarqube.ws.client.issue.IssueFilterParameters; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionUpdater; -import org.sonarqube.ws.MediaTypes; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.view.index.ViewDoc; @@ -56,6 +54,8 @@ import org.sonar.server.ws.WsActionTester; import org.sonar.server.ws.WsTester; import org.sonar.server.ws.WsTester.Result; import org.sonarqube.ws.Issues; +import org.sonarqube.ws.MediaTypes; +import org.sonarqube.ws.client.issue.IssueFilterParameters; import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java index f6f196f17fe..1d357708df2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java @@ -41,20 +41,20 @@ import org.sonar.db.issue.IssueChangeDao; import org.sonar.db.issue.IssueChangeDto; import org.sonar.db.issue.IssueDao; import org.sonar.db.issue.IssueDto; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; import org.sonar.server.issue.IssueQuery; import org.sonar.server.issue.IssueTesting; -import org.sonarqube.ws.client.issue.IssueFilterParameters; import org.sonar.server.issue.index.IssueIndexer; import org.sonar.server.permission.PermissionChange; import org.sonar.server.permission.PermissionUpdater; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.search.QueryContext; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; +import org.sonarqube.ws.client.issue.IssueFilterParameters; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java index da71a05384b..394408c8fe6 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/BulkDeleteActionTest.java @@ -21,7 +21,6 @@ package org.sonar.server.project.ws; import com.google.common.collect.ImmutableMap; import java.util.Arrays; -import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -36,30 +35,24 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; import org.sonar.core.permission.GlobalPermissions; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.component.ResourceDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.issue.IssueDao; +import org.sonar.db.component.SnapshotTesting; import org.sonar.db.issue.IssueDto; -import org.sonar.db.purge.PurgeDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.component.ComponentCleanerService; import org.sonar.server.component.ComponentFinder; -import org.sonar.db.component.SnapshotTesting; -import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.issue.IssueTesting; import org.sonar.server.issue.index.IssueAuthorizationIndexer; import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.issue.index.IssueIndexer; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.test.index.TestDoc; import org.sonar.server.test.index.TestIndexDefinition; import org.sonar.server.test.index.TestIndexer; @@ -92,17 +85,12 @@ public class BulkDeleteActionTest { public ExpectedException expectedException = ExpectedException.none(); WsTester ws; - DbClient dbClient; - DbSession dbSession; + DbClient dbClient = db.getDbClient(); + DbSession dbSession = db.getSession(); ResourceType resourceType; @Before public void setUp() { - ComponentDao componentDao = new ComponentDao(); - ResourceDao resourceDao = new ResourceDao(db.myBatis(), System2.INSTANCE); - PurgeDao purgeDao = new PurgeDao(db.myBatis(), resourceDao, System2.INSTANCE); - dbClient = new DbClient(db.database(), db.myBatis(), componentDao, purgeDao, new RuleDao(System2.INSTANCE), new IssueDao(db.myBatis()), new SnapshotDao()); - dbSession = dbClient.openSession(false); resourceType = mock(ResourceType.class); when(resourceType.getBooleanProperty(anyString())).thenReturn(true); ResourceTypes mockResourceTypes = mock(ResourceTypes.class); @@ -120,11 +108,6 @@ public class BulkDeleteActionTest { es.truncateIndices(); } - @After - public void tearDown() { - dbSession.close(); - } - @Test public void delete_projects_and_data_in_db_by_uuids() throws Exception { long snapshotId1 = insertNewProjectInDbAndReturnSnapshotId(1); @@ -222,7 +205,7 @@ public class BulkDeleteActionTest { .newProjectDto("project-uuid-" + suffix) .setKey("project-key-" + suffix); RuleDto rule = RuleTesting.newDto(RuleKey.of("sonarqube", "rule-" + suffix)); - dbClient.deprecatedRuleDao().insert(dbSession, rule); + dbClient.ruleDao().insert(dbSession, rule); IssueDto issue = IssueTesting.newDto(rule, project, project).setKee("issue-key-" + suffix); dbClient.componentDao().insert(dbSession, project); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, SnapshotTesting.newSnapshotForProject(project)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java index f7c2d04efdd..d36cae4fe8f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/project/ws/DeleteActionTest.java @@ -20,7 +20,6 @@ package org.sonar.server.project.ws; import com.google.common.collect.ImmutableMap; -import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -34,30 +33,24 @@ import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rule.RuleKey; import org.sonar.api.utils.System2; import org.sonar.api.web.UserRole; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.component.ComponentDao; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.component.ResourceDao; -import org.sonar.db.component.SnapshotDao; import org.sonar.db.component.SnapshotDto; -import org.sonar.db.issue.IssueDao; +import org.sonar.db.component.SnapshotTesting; import org.sonar.db.issue.IssueDto; -import org.sonar.db.purge.PurgeDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.component.ComponentCleanerService; import org.sonar.server.component.ComponentFinder; -import org.sonar.db.component.SnapshotTesting; -import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.ForbiddenException; import org.sonar.server.issue.IssueTesting; import org.sonar.server.issue.index.IssueAuthorizationIndexer; import org.sonar.server.issue.index.IssueIndexDefinition; import org.sonar.server.issue.index.IssueIndexer; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.test.index.TestDoc; import org.sonar.server.test.index.TestIndexDefinition; import org.sonar.server.test.index.TestIndexer; @@ -93,19 +86,14 @@ public class DeleteActionTest { WsTester ws; - DbClient dbClient; + DbClient dbClient = db.getDbClient(); - DbSession dbSession; + DbSession dbSession = db.getSession(); ResourceType resourceType; @Before public void setUp() { - ComponentDao componentDao = new ComponentDao(); - ResourceDao resourceDao = new ResourceDao(db.myBatis(), System2.INSTANCE); - PurgeDao purgeDao = new PurgeDao(db.myBatis(), resourceDao, System2.INSTANCE); - dbClient = new DbClient(db.database(), db.myBatis(), componentDao, purgeDao, new RuleDao(System2.INSTANCE), new IssueDao(db.myBatis()), new SnapshotDao()); - dbSession = dbClient.openSession(false); resourceType = mock(ResourceType.class); when(resourceType.getBooleanProperty(anyString())).thenReturn(true); ResourceTypes mockResourceTypes = mock(ResourceTypes.class); @@ -127,11 +115,6 @@ public class DeleteActionTest { es.truncateIndices(); } - @After - public void tearDown() { - dbSession.close(); - } - @Test public void delete_project_and_data_in_db_by_uuid() throws Exception { long snapshotId1 = insertNewProjectInDbAndReturnSnapshotId(1); @@ -244,7 +227,7 @@ public class DeleteActionTest { .newProjectDto("project-uuid-" + suffix) .setKey("project-key-" + suffix); RuleDto rule = RuleTesting.newDto(RuleKey.of("sonarqube", "rule-" + suffix)); - dbClient.deprecatedRuleDao().insert(dbSession, rule); + dbClient.ruleDao().insert(dbSession, rule); IssueDto issue = IssueTesting.newDto(rule, project, project).setKee("issue-key-" + suffix); dbClient.componentDao().insert(dbSession, project); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, SnapshotTesting.newSnapshotForProject(project)); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleTest.java deleted file mode 100644 index 069366b9559..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ActiveRuleTest.java +++ /dev/null @@ -1,529 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.qualityprofile; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.rule.Severity; -import org.sonar.api.server.debt.DebtRemediationFunction; -import org.sonar.db.DbSession; -import org.sonar.db.qualityprofile.ActiveRuleDto; -import org.sonar.db.qualityprofile.ActiveRuleParamDto; -import org.sonar.db.qualityprofile.QualityProfileDto; -import org.sonar.db.rule.RuleDto; -import org.sonar.db.rule.RuleParamDto; -import org.sonar.db.rule.RuleTesting; -import org.sonar.server.db.DbClient; -import org.sonar.server.platform.Platform; -import org.sonar.server.qualityprofile.index.ActiveRuleIndex; -import org.sonar.server.qualityprofile.index.ActiveRuleNormalizer; -import org.sonar.server.rule.db.RuleDao; -import org.sonar.server.search.FacetValue; -import org.sonar.server.search.IndexClient; -import org.sonar.server.tester.ServerTester; -import org.sonar.server.tester.UserSessionRule; - -import static com.google.common.collect.Lists.newArrayList; -import static org.assertj.core.api.Assertions.assertThat; - -// TODO To be removed when dao v2 is removed -@Ignore -public class ActiveRuleTest { - - @ClassRule - public static ServerTester tester = new ServerTester(); - - @Rule - public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester); - - DbClient db; - RuleDao dao; - IndexClient index; - DbSession dbSession; - - @Before - public void before() { - dao = tester.get(RuleDao.class); - tester.clearDbAndIndexes(); - db = tester.get(DbClient.class); - index = tester.get(IndexClient.class); - dbSession = tester.get(DbClient.class).openSession(false); - } - - @After - public void after() { - if (dbSession != null) { - dbSession.close(); - } - } - - @Test - public void synchronize_index() { - Date beginning = new Date(); - - QualityProfileDto profile1 = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profile1); - - RuleDto rule1 = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR); - db.deprecatedRuleDao().insert(dbSession, rule1); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile1, rule1).setSeverity("BLOCKER"); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - // 1. Synchronize since 0 - tester.clearIndexes(); - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull(); - db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, new Date(0L)); - dbSession.commit(); - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull(); - - // 2. Synchronize since beginning - tester.clearIndexes(); - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull(); - db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, beginning); - dbSession.commit(); - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull(); - - // 3. Assert startup picks it up - tester.clearIndexes(); - assertThat(index.get(ActiveRuleIndex.class).getLastSynchronization()).isNull(); - tester.get(Platform.class).executeStartupTasks(); - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNotNull(); - assertThat(index.get(ActiveRuleIndex.class).getLastSynchronization()).isNotNull(); - } - - /** - * SONAR-6540 - */ - @Test - public void active_rule_linked_to_not_existing_rule_should_be_ignored() throws SQLException { - QualityProfileDto profile = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profile); - - RuleDto rule = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR); - db.deprecatedRuleDao().insert(dbSession, rule); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER"); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - // Remove rule -> Active rule is now linked to a not existing rule - executeSql(String.format("DELETE FROM rules WHERE id=%s", rule.getId())); - dbSession.commit(); - - // Synchronize index from start - tester.clearIndexes(); - db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, new Date(0L)); - dbSession.commit(); - - // Active does not exist in the index - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull(); - } - - /** - * SONAR-6540 - */ - @Test - public void active_rule_linked_to_not_existing_profile_should_be_ignored() throws SQLException { - QualityProfileDto profile = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profile); - - RuleDto rule = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR); - db.deprecatedRuleDao().insert(dbSession, rule); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER"); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - // Remove quality profile -> active rule is now linked to a not existing quality profile - executeSql(String.format("DELETE FROM rules_profiles WHERE id=%s", profile.getId())); - dbSession.commit(); - - // Synchronize index from start - tester.clearIndexes(); - db.deprecatedActiveRuleDao().synchronizeAfter(dbSession, new Date(0L)); - dbSession.commit(); - - // Active does not exist in the index - assertThat(index.get(ActiveRuleIndex.class).getNullableByKey(activeRule.getKey())).isNull(); - } - - @Test - public void insert_and_index_active_rule() { - QualityProfileDto profileDto = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profileDto); - RuleKey ruleKey = RuleTesting.XOO_X1; - RuleDto ruleDto = newRuleDto(ruleKey); - db.deprecatedRuleDao().insert(dbSession, ruleDto); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) - .setInheritance(ActiveRule.Inheritance.INHERITED.name()) - .setSeverity(Severity.BLOCKER); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - // verify db - assertThat(db.deprecatedActiveRuleDao().getByKey(dbSession, activeRule.getKey())).isNotNull(); - List persistedDtos = db.deprecatedActiveRuleDao().selectByRule(dbSession, ruleDto); - assertThat(persistedDtos).hasSize(1); - - // verify es - ActiveRule hit = index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey()); - assertThat(hit).isNotNull(); - assertThat(hit.key()).isEqualTo(activeRule.getKey()); - assertThat(hit.inheritance().name()).isEqualTo(activeRule.getInheritance()); - assertThat(hit.parentKey()).isNull(); - assertThat(hit.severity()).isEqualTo(activeRule.getSeverityString()); - } - - @Test - public void insert_and_index_active_rule_param() { - // insert and index - QualityProfileDto profileDto = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profileDto); - RuleKey ruleKey = RuleTesting.XOO_X1; - RuleDto ruleDto = newRuleDto(ruleKey); - db.deprecatedRuleDao().insert(dbSession, ruleDto); - - RuleParamDto minParam = new RuleParamDto() - .setName("min") - .setType("STRING"); - db.deprecatedRuleDao().insertRuleParam(dbSession, ruleDto, minParam); - - RuleParamDto maxParam = new RuleParamDto() - .setName("max") - .setType("STRING"); - db.deprecatedRuleDao().insertRuleParam(dbSession, ruleDto, maxParam); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) - .setInheritance(ActiveRule.Inheritance.INHERITED.name()) - .setSeverity(Severity.BLOCKER); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - - ActiveRuleParamDto activeRuleMinParam = ActiveRuleParamDto.createFor(minParam) - .setValue("minimum"); - db.deprecatedActiveRuleDao().insertParam(dbSession, activeRule, activeRuleMinParam); - - ActiveRuleParamDto activeRuleMaxParam = ActiveRuleParamDto.createFor(maxParam) - .setValue("maximum"); - db.deprecatedActiveRuleDao().insertParam(dbSession, activeRule, activeRuleMaxParam); - - dbSession.commit(); - - // verify db - List persistedDtos = db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(dbSession, activeRule.getKey()); - assertThat(persistedDtos).hasSize(2); - - // verify es - ActiveRule rule = index.get(ActiveRuleIndex.class).getByKey(activeRule.getKey()); - assertThat(rule).isNotNull(); - assertThat(rule.params()).hasSize(2); - assertThat(rule.params().keySet()).containsOnly("min", "max"); - assertThat(rule.params().values()).containsOnly("minimum", "maximum"); - assertThat(rule.params().get("min")).isEqualTo("minimum"); - } - - @Test - public void find_active_rules() { - QualityProfileDto profile1 = QProfileTesting.newXooP1(); - QualityProfileDto profile2 = QProfileTesting.newXooP2(); - db.qualityProfileDao().insert(dbSession, profile1, profile2); - - RuleDto rule1 = RuleTesting.newXooX1().setSeverity(Severity.MAJOR); - RuleDto rule2 = RuleTesting.newXooX2().setSeverity(Severity.MAJOR); - RuleDto removedRule = RuleTesting.newDto(RuleKey.of("xoo", "removed")).setSeverity(Severity.MAJOR).setStatus(RuleStatus.REMOVED); - db.deprecatedRuleDao().insert(dbSession, rule1, rule2, removedRule); - - db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR)); - db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER)); - db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL)); - // Removed rule can still be activated for instance when removing the checkstyle plugin, active rules related on checkstyle are not - // removed - // because if the plugin is re-install, quality profiles using these rule are not changed. - db.deprecatedActiveRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, removedRule).setSeverity(Severity.MAJOR)); - dbSession.commit(); - - // 1. find by rule key - - // in db - dbSession.clearCache(); - assertThat(db.deprecatedActiveRuleDao().selectByRule(dbSession, rule1)).hasSize(1); - assertThat(db.deprecatedActiveRuleDao().selectByRule(dbSession, rule2)).hasSize(2); - - // in es - List activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X1); - assertThat(activeRules).hasSize(1); - assertThat(activeRules.get(0).key().ruleKey()).isEqualTo(RuleTesting.XOO_X1); - - activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X2); - assertThat(activeRules).hasSize(2); - assertThat(activeRules.get(0).key().ruleKey()).isEqualTo(RuleTesting.XOO_X2); - - activeRules = index.get(ActiveRuleIndex.class).findByRule(RuleTesting.XOO_X3); - assertThat(activeRules).isEmpty(); - - // 2. find by profile - activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profile1.getKey())); - assertThat(activeRules).hasSize(2); - assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile1.getKey()); - assertThat(activeRules.get(1).key().qProfile()).isEqualTo(profile1.getKey()); - - activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profile2.getKey())); - assertThat(activeRules).hasSize(1); - assertThat(activeRules.get(0).key().qProfile()).isEqualTo(profile2.getKey()); - - activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile("unknown")); - assertThat(activeRules).isEmpty(); - } - - @Test - public void find_many_active_rules_by_profile() { - // insert and index - QualityProfileDto profileDto = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profileDto); - int nb = 100; - for (int i = 0; i < nb; i++) { - RuleDto rule = newRuleDto(RuleKey.of("xoo", "S00" + i)); - db.deprecatedRuleDao().insert(dbSession, rule); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, rule).setSeverity(Severity.MAJOR); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - } - dbSession.commit(); - dbSession.clearCache(); - - // verify index - Collection activeRules = Lists.newArrayList(index.get(ActiveRuleIndex.class).findByProfile(profileDto.getKey())); - assertThat(activeRules).hasSize(nb); - } - - @Test - public void count_by_profile() { - QualityProfileDto profileDto1 = QProfileTesting.newXooP1(); - QualityProfileDto profileDto2 = QProfileTesting.newXooP2(); - db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2); - - RuleKey ruleKey = RuleTesting.XOO_X1; - RuleDto ruleDto = newRuleDto(ruleKey); - db.deprecatedRuleDao().insert(dbSession, ruleDto); - - ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR); - ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule1, activeRule2); - dbSession.commit(); - - // 0. Test base case - assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(2); - - // 1. Assert by profileKey - assertThat(index.get(ActiveRuleIndex.class).countByQualityProfileKey(profileDto1.getKey())).isEqualTo(1); - - // 2. Assert by term aggregation; - Map counts = index.get(ActiveRuleIndex.class).countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY); - assertThat(counts).hasSize(2); - assertThat(counts.values()).containsOnly(1L, 1L); - assertThat(counts.keySet()).containsOnly(profileDto1.getKey().toString(), profileDto2.getKey().toString()); - } - - @Test - public void count_all_by_index_field() { - QualityProfileDto profileDto1 = QProfileTesting.newXooP1(); - QualityProfileDto profileDto2 = QProfileTesting.newXooP2(); - db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2); - - RuleKey ruleKey = RuleTesting.XOO_X1; - RuleDto ruleDto = newRuleDto(ruleKey); - db.deprecatedRuleDao().insert(dbSession, ruleDto); - - ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(profileDto1, ruleDto).setSeverity(Severity.MAJOR); - ActiveRuleDto activeRule2 = ActiveRuleDto.createFor(profileDto2, ruleDto).setSeverity(Severity.MAJOR); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule1, activeRule2); - dbSession.commit(); - - // 0. Test base case - assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(2); - - // 1. Assert by term aggregation; - Map counts = index.get(ActiveRuleIndex.class).countByField(ActiveRuleNormalizer.ActiveRuleField.PROFILE_KEY); - assertThat(counts).hasSize(2); - assertThat(counts.values()).containsOnly(1L, 1L); - assertThat(counts.keySet()).containsOnly(profileDto1.getKey(), profileDto2.getKey()); - } - - @Test - public void stats_for_all() { - QualityProfileDto profileDto1 = QProfileTesting.newXooP1(); - QualityProfileDto profileDto2 = QProfileTesting.newXooP2(); - db.qualityProfileDao().insert(dbSession, profileDto1, profileDto2); - - RuleDto ruleDto1 = newRuleDto(RuleTesting.XOO_X1); - RuleDto ruleDto2 = newRuleDto(RuleTesting.XOO_X2); - db.deprecatedRuleDao().insert(dbSession, ruleDto1, ruleDto2); - - db.deprecatedActiveRuleDao().insert(dbSession, - ActiveRuleDto.createFor(profileDto1, ruleDto1) - .setInheritance(ActiveRule.Inheritance.INHERITED.name()) - .setSeverity(Severity.BLOCKER), - ActiveRuleDto.createFor(profileDto2, ruleDto1) - .setInheritance(ActiveRule.Inheritance.INHERITED.name()) - .setSeverity(Severity.MINOR), - ActiveRuleDto.createFor(profileDto1, ruleDto2) - .setInheritance(ActiveRule.Inheritance.OVERRIDES.name()) - .setSeverity(Severity.MAJOR), - ActiveRuleDto.createFor(profileDto2, ruleDto2) - .setInheritance(ActiveRule.Inheritance.INHERITED.name()) - .setSeverity(Severity.BLOCKER)); - dbSession.commit(); - dbSession.clearCache(); - - // 0. Test base case - assertThat(index.get(ActiveRuleIndex.class).countAll()).isEqualTo(4); - - // 1. Assert by term aggregation; - Map> stats = index.get(ActiveRuleIndex.class).getStatsByProfileKeys( - ImmutableList.of(profileDto1.getKey(), - profileDto2.getKey())); - - assertThat(stats).hasSize(2); - } - - /** - * SONAR-5844 - */ - @Test - public void stats_for_all_with_lof_of_profiles() { - RuleDto ruleDto1 = newRuleDto(RuleTesting.XOO_X1); - RuleDto ruleDto2 = newRuleDto(RuleTesting.XOO_X2); - db.deprecatedRuleDao().insert(dbSession, ruleDto1, ruleDto2); - - List profileKeys = newArrayList(); - for (int i = 0; i < 30; i++) { - QualityProfileDto profileDto = QProfileTesting.newQProfileDto(QProfileName.createFor("xoo", "profile-" + i), "profile-" + i); - profileKeys.add(profileDto.getKey()); - db.qualityProfileDao().insert(dbSession, profileDto); - - db.deprecatedActiveRuleDao().insert(dbSession, - ActiveRuleDto.createFor(profileDto, ruleDto1) - .setSeverity(Severity.BLOCKER), - ActiveRuleDto.createFor(profileDto, ruleDto2) - .setSeverity(Severity.MAJOR)); - } - dbSession.commit(); - dbSession.clearCache(); - - Map> stats = index.get(ActiveRuleIndex.class).getStatsByProfileKeys(profileKeys); - assertThat(stats).hasSize(30); - } - - @Test - public void select_by_id() throws Exception { - QualityProfileDto profile = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profile); - - RuleDto rule = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR); - db.deprecatedRuleDao().insert(dbSession, rule); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER"); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - assertThat(db.deprecatedActiveRuleDao().selectById(dbSession, activeRule.getId()).getId()).isEqualTo(activeRule.getId()); - } - - @Test - public void select_by_id_return_nothing_when_rule_does_not_exist() throws Exception { - QualityProfileDto profile = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profile); - - RuleDto rule = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR); - db.deprecatedRuleDao().insert(dbSession, rule); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER"); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - // Remove rule -> Active rule is now linked to a not existing rule - executeSql(String.format("DELETE FROM rules WHERE id=%s", rule.getId())); - dbSession.commit(); - - assertThat(db.deprecatedActiveRuleDao().selectById(dbSession, activeRule.getId())).isNull(); - } - - @Test - public void select_by_id_return_nothing_when_profile_does_not_exist() throws Exception { - QualityProfileDto profile = QProfileTesting.newXooP1(); - db.qualityProfileDao().insert(dbSession, profile); - - RuleDto rule = RuleDto.createFor(RuleTesting.XOO_X1).setSeverity(Severity.MAJOR); - db.deprecatedRuleDao().insert(dbSession, rule); - - ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER"); - db.deprecatedActiveRuleDao().insert(dbSession, activeRule); - dbSession.commit(); - - // Remove quality profile -> active rule is now linked to a not existing quality profile - executeSql(String.format("DELETE FROM rules_profiles WHERE id=%s", profile.getId())); - dbSession.commit(); - - assertThat(db.deprecatedActiveRuleDao().selectById(dbSession, activeRule.getId())).isNull(); - } - - private RuleDto newRuleDto(RuleKey ruleKey) { - return new RuleDto() - .setRuleKey(ruleKey.rule()) - .setRepositoryKey(ruleKey.repository()) - .setName("Rule " + ruleKey.rule()) - .setDescription("Description " + ruleKey.rule()) - .setStatus(RuleStatus.READY) - .setConfigKey("InternalKey" + ruleKey.rule()) - .setSeverity(Severity.INFO) - .setIsTemplate(false) - .setLanguage("js") - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) - .setRemediationCoefficient("1h") - .setDefaultRemediationCoefficient("5d") - .setRemediationOffset("5min") - .setDefaultRemediationOffset("10h") - .setEffortToFixDescription(ruleKey.repository() + "." + ruleKey.rule() + ".effortToFix"); - } - - private void executeSql(String sql) throws SQLException { - PreparedStatement stmt = db.getDatabase().getDataSource().getConnection().prepareStatement(sql); - stmt.executeUpdate(); - } - -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java index a91fd5ff8ed..57048a50f58 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ChangelogActionTest.java @@ -23,7 +23,6 @@ import com.google.common.collect.Maps; import java.util.Date; import java.util.Map; import org.joda.time.DateTime; -import org.junit.After; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; @@ -34,10 +33,10 @@ import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.util.Uuids; +import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.qualityprofile.ActiveRuleKey; -import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.db.user.UserDto; @@ -45,7 +44,6 @@ import org.sonar.server.activity.Activity; import org.sonar.server.activity.index.ActivityDoc; import org.sonar.server.activity.index.ActivityIndex; import org.sonar.server.activity.index.ActivityIndexDefinition; -import org.sonar.server.db.DbClient; import org.sonar.server.es.EsTester; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.language.LanguageTesting; @@ -53,8 +51,6 @@ import org.sonar.server.qualityprofile.ActiveRuleChange; import org.sonar.server.qualityprofile.ActiveRuleChange.Type; import org.sonar.server.qualityprofile.QProfileFactory; import org.sonar.server.qualityprofile.QProfileTesting; -import org.sonar.server.rule.db.RuleDao; -import org.sonar.db.user.UserDao; import org.sonar.server.ws.WsTester; import static org.mockito.Mockito.mock; @@ -68,8 +64,8 @@ public class ChangelogActionTest { @ClassRule public static EsTester esTester = new EsTester().addDefinitions(new ActivityIndexDefinition(new Settings())); - private DbClient db; - private DbSession dbSession; + private DbClient db = dbTester.getDbClient(); + private DbSession dbSession = dbTester.getSession(); private WsTester wsTester; private String login; @@ -80,12 +76,9 @@ public class ChangelogActionTest { System2 system = mock(System2.class); - db = new DbClient(dbTester.database(), dbTester.myBatis(), new RuleDao(system), new QualityProfileDao(dbTester.myBatis(), system), new UserDao(dbTester.myBatis(), system)); - dbSession = db.openSession(false); - // create pre-defined rules RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR"); - db.deprecatedRuleDao().insert(dbSession, xooRule1); + db.ruleDao().insert(dbSession, xooRule1); // create pre-defined profiles P1 and P2 db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1(), QProfileTesting.newXooP2()); @@ -101,11 +94,6 @@ public class ChangelogActionTest { new ChangelogAction(db, new ActivityIndex(esTester.client()), new QProfileFactory(db), LanguageTesting.newLanguages("xoo")))); } - @After - public void after() { - dbSession.close(); - } - @Test public void changelog_empty() throws Exception { wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY) diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java deleted file mode 100644 index 11b806533ad..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/db/RuleDaoTest.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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 this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule.db; - -import com.google.common.collect.Iterables; -import java.util.List; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.RuleStatus; -import org.sonar.api.rule.Severity; -import org.sonar.api.server.debt.DebtRemediationFunction; -import org.sonar.api.utils.DateUtils; -import org.sonar.api.utils.System2; -import org.sonar.db.DbTester; -import org.sonar.db.rule.RuleDto; -import org.sonar.db.rule.RuleDto.Format; -import org.sonar.db.rule.RuleParamDto; -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; - -@Category(DbTests.class) -public class RuleDaoTest { - - private System2 system2 = mock(System2.class); - - @org.junit.Rule - public DbTester dbTester = DbTester.create(system2); - - private RuleDao dao = new RuleDao(system2); - - @Test - public void select_all() { - dbTester.prepareDbUnit(getClass(), "selectAll.xml"); - List ruleDtos = dao.selectAll(dbTester.getSession()); - - assertThat(ruleDtos).hasSize(1); - - RuleDto ruleDto = ruleDtos.get(0); - assertThat(ruleDto.getId()).isEqualTo(1); - assertThat(ruleDto.getName()).isEqualTo("Avoid Null"); - assertThat(ruleDto.getDescription()).isEqualTo("Should avoid NULL"); - assertThat(ruleDto.getDescriptionFormat()).isEqualTo(Format.HTML); - assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.READY); - assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle"); - assertThat(ruleDto.getNoteData()).isEqualTo("Rule note with accents \u00e9\u00e8\u00e0"); - assertThat(ruleDto.getSubCharacteristicId()).isEqualTo(100); - assertThat(ruleDto.getDefaultSubCharacteristicId()).isEqualTo(101); - assertThat(ruleDto.getRemediationFunction()).isEqualTo("linear"); - assertThat(ruleDto.getDefaultRemediationFunction()).isEqualTo("linear_offset"); - assertThat(ruleDto.getRemediationCoefficient()).isEqualTo("1h"); - assertThat(ruleDto.getDefaultRemediationCoefficient()).isEqualTo("5d"); - assertThat(ruleDto.getRemediationOffset()).isEqualTo("5min"); - assertThat(ruleDto.getDefaultRemediationOffset()).isEqualTo("10h"); - assertThat(ruleDto.getEffortToFixDescription()).isEqualTo("squid.S115.effortToFix"); - } - - @Test - public void select_by_id() { - dbTester.prepareDbUnit(getClass(), "selectById.xml"); - RuleDto ruleDto = dao.selectById(dbTester.getSession(), 2); - - assertThat(ruleDto.getId()).isEqualTo(2); - assertThat(ruleDto.getName()).isEqualTo("Avoid Null"); - assertThat(ruleDto.getDescription()).isEqualTo("Should avoid NULL"); - assertThat(ruleDto.getDescriptionFormat()).isEqualTo(Format.HTML); - assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.READY); - assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle"); - } - - @Test - public void select_by_rule_key() { - dbTester.prepareDbUnit(getClass(), "select_by_rule_key.xml"); - assertThat(dao.getNullableByKey(dbTester.getSession(), RuleKey.of("checkstyle", "AvoidComparison"))).isNotNull(); - assertThat(dao.getNullableByKey(dbTester.getSession(), RuleKey.of("checkstyle", "Unknown"))).isNull(); - assertThat(dao.getNullableByKey(dbTester.getSession(), RuleKey.of("Unknown", "AvoidComparison"))).isNull(); - } - - @Test - public void select_by_name() { - dbTester.prepareDbUnit(getClass(), "select_by_name.xml"); - RuleDto ruleDto = dao.getByName("Avoid Null", dbTester.getSession()); - - assertThat(ruleDto).isNotNull(); - - assertThat(ruleDto.getId()).isEqualTo(2); - assertThat(ruleDto.getName()).isEqualTo("Avoid Null"); - assertThat(ruleDto.getDescription()).isEqualTo("Should avoid NULL"); - assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.READY); - assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle"); - } - - @Test - public void select_non_manual() { - dbTester.prepareDbUnit(getClass(), "selectNonManual.xml"); - List ruleDtos = dao.selectByNonManual(dbTester.getSession()); - dbTester.getSession().commit(); - dbTester.getSession().close(); - - assertThat(ruleDtos.size()).isEqualTo(1); - RuleDto ruleDto = ruleDtos.get(0); - assertThat(ruleDto.getId()).isEqualTo(1); - assertThat(ruleDto.getName()).isEqualTo("Avoid Null"); - assertThat(ruleDto.getDescription()).isEqualTo("Should avoid NULL"); - assertThat(ruleDto.getStatus()).isEqualTo(RuleStatus.READY); - assertThat(ruleDto.getRepositoryKey()).isEqualTo("checkstyle"); - } - - @Test - public void update() { - when(system2.now()).thenReturn(DateUtils.parseDate("2014-01-01").getTime()); - - dbTester.prepareDbUnit(getClass(), "update.xml"); - - RuleDto ruleToUpdate = new RuleDto() - .setId(1) - .setRuleKey("NewRuleKey") - .setRepositoryKey("plugin") - .setName("new name") - .setDescription("new description") - .setDescriptionFormat(Format.MARKDOWN) - .setStatus(RuleStatus.DEPRECATED) - .setConfigKey("NewConfigKey") - .setSeverity(Severity.INFO) - .setIsTemplate(true) - .setLanguage("dart") - .setTemplateId(3) - .setNoteData("My note") - .setNoteUserLogin("admin") - .setNoteCreatedAt(DateUtils.parseDate("2013-12-19")) - .setNoteUpdatedAt(DateUtils.parseDate("2013-12-20")) - .setSubCharacteristicId(100) - .setDefaultSubCharacteristicId(101) - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) - .setRemediationCoefficient("1h") - .setDefaultRemediationCoefficient("5d") - .setRemediationOffset("5min") - .setDefaultRemediationOffset("10h") - .setEffortToFixDescription("squid.S115.effortToFix"); - - - dao.update(dbTester.getSession(), ruleToUpdate); - dbTester.getSession().commit(); - - dbTester.assertDbUnit(getClass(), "update-result.xml", "rules"); - } - - @Test - public void insert() { - when(system2.now()).thenReturn(DateUtils.parseDate("2013-12-16").getTime()); - - dbTester.prepareDbUnit(getClass(), "empty.xml"); - - RuleDto ruleToInsert = new RuleDto() - .setId(1) - .setRuleKey("NewRuleKey") - .setRepositoryKey("plugin") - .setName("new name") - .setDescription("new description") - .setDescriptionFormat(Format.MARKDOWN) - .setStatus(RuleStatus.DEPRECATED) - .setConfigKey("NewConfigKey") - .setSeverity(Severity.INFO) - .setIsTemplate(true) - .setLanguage("dart") - .setTemplateId(3) - .setSubCharacteristicId(100) - .setDefaultSubCharacteristicId(101) - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) - .setRemediationCoefficient("1h") - .setDefaultRemediationCoefficient("5d") - .setRemediationOffset("5min") - .setDefaultRemediationOffset("10h") - .setEffortToFixDescription("squid.S115.effortToFix"); - - dao.insert(dbTester.getSession(), ruleToInsert); - dbTester.getSession().commit(); - - dbTester.assertDbUnit(getClass(), "insert-result.xml", "rules"); - } - - @Test - public void insert_all() { - when(system2.now()).thenReturn(DateUtils.parseDate("2013-12-16").getTime()); - - dbTester.prepareDbUnit(getClass(), "empty.xml"); - - RuleDto ruleToInsert1 = new RuleDto() - .setId(1) - .setRuleKey("NewRuleKey") - .setRepositoryKey("plugin") - .setName("new name") - .setDescription("new description") - .setDescriptionFormat(Format.HTML) - .setStatus(RuleStatus.DEPRECATED) - .setConfigKey("NewConfigKey") - .setSeverity(Severity.INFO) - .setIsTemplate(true) - .setLanguage("dart") - .setTemplateId(3) - .setSubCharacteristicId(100) - .setDefaultSubCharacteristicId(101) - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) - .setRemediationCoefficient("1h") - .setDefaultRemediationCoefficient("5d") - .setRemediationOffset("5min") - .setDefaultRemediationOffset("10h") - .setEffortToFixDescription("squid.S115.effortToFix"); - - RuleDto ruleToInsert2 = new RuleDto() - .setId(2) - .setRuleKey("NewRuleKey2") - .setRepositoryKey("plugin2") - .setName("new name2") - .setDescription("new description2") - .setDescriptionFormat(Format.MARKDOWN) - .setStatus(RuleStatus.BETA) - .setConfigKey("NewConfigKey2") - .setSeverity(Severity.MAJOR) - .setIsTemplate(false) - .setLanguage("js") - .setTemplateId(null) - .setSubCharacteristicId(102) - .setDefaultSubCharacteristicId(103) - .setRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) - .setDefaultRemediationFunction(DebtRemediationFunction.Type.LINEAR.toString()) - .setRemediationCoefficient("5d") - .setDefaultRemediationCoefficient("1h") - .setRemediationOffset("10h") - .setDefaultRemediationOffset("5min") - .setEffortToFixDescription("squid.S115.effortToFix2"); - - dao.insert(dbTester.getSession(), ruleToInsert1, ruleToInsert2); - dbTester.getSession().commit(); - - dbTester.assertDbUnit(getClass(), "insert_all-result.xml", "rules"); - } - - @Test - public void select_parameters() { - dbTester.prepareDbUnit(getClass(), "selectParameters.xml"); - List ruleDtos = dao.selectAllRuleParams(dbTester.getSession()); - - assertThat(ruleDtos.size()).isEqualTo(1); - RuleParamDto ruleDto = ruleDtos.get(0); - assertThat(ruleDto.getId()).isEqualTo(1); - assertThat(ruleDto.getName()).isEqualTo("myParameter"); - assertThat(ruleDto.getDescription()).isEqualTo("My Parameter"); - assertThat(ruleDto.getType()).isEqualTo("plop"); - assertThat(ruleDto.getDefaultValue()).isEqualTo("plouf"); - } - - @Test - public void select_parameters_by_rule_id() { - dbTester.prepareDbUnit(getClass(), "select_parameters_by_rule_id.xml"); - RuleDto rule = dao.selectById(dbTester.getSession(), 1); - List ruleDtos = dao.selectRuleParamsByRuleKey(dbTester.getSession(), rule.getKey()); - - assertThat(ruleDtos.size()).isEqualTo(1); - RuleParamDto ruleDto = ruleDtos.get(0); - assertThat(ruleDto.getId()).isEqualTo(1); - assertThat(ruleDto.getName()).isEqualTo("myParameter"); - assertThat(ruleDto.getDescription()).isEqualTo("My Parameter"); - assertThat(ruleDto.getType()).isEqualTo("plop"); - assertThat(ruleDto.getRuleId()).isEqualTo(1); - } - - @Test - public void insert_parameter() { - dbTester.prepareDbUnit(getClass(), "insert_parameter.xml"); - - RuleDto rule1 = dao.selectById(dbTester.getSession(), 1); - - RuleParamDto param = RuleParamDto.createFor(rule1) - .setName("max") - .setType("INTEGER") - .setDefaultValue("30") - .setDescription("My Parameter"); - - dao.insertRuleParam(dbTester.getSession(), rule1, param); - dbTester.getSession().commit(); - - dbTester.assertDbUnit(getClass(), "insert_parameter-result.xml", "rules_parameters"); - } - - @Test - public void update_parameter() { - dbTester.prepareDbUnit(getClass(), "update_parameter.xml"); - - RuleDto rule1 = dao.selectById(dbTester.getSession(), 1); - - List params = dao.selectRuleParamsByRuleKey(dbTester.getSession(), rule1.getKey()); - assertThat(params).hasSize(1); - - RuleParamDto param = Iterables.getFirst(params, null); - - param - // Name will not be changed - .setName("format") - .setType("STRING") - .setDefaultValue("^[a-z]+(\\.[a-z][a-z0-9]*)*$") - .setDescription("Regular expression used to check the package names against."); - - dao.updateRuleParam(dbTester.getSession(), rule1, param); - dbTester.getSession().commit(); - - dbTester.assertDbUnit(getClass(), "update_parameter-result.xml", "rules_parameters"); - } -} diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java index b084bd63be1..1837c789357 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/CreateActionMediumTest.java @@ -32,11 +32,11 @@ import org.sonar.api.rule.Severity; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.exceptions.BadRequestException; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; @@ -52,7 +52,7 @@ public class CreateActionMediumTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login() - .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); + .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); WsTester wsTester; RuleDao ruleDao; @@ -74,7 +74,8 @@ public class CreateActionMediumTest { @Test public void create_custom_rule() throws Exception { // Template rule - RuleDto templateRule = ruleDao.insert(session, RuleTesting.newTemplateRule(RuleKey.of("java", "S001"))); + RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); + ruleDao.insert(session, templateRule); RuleParamDto param = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*"); ruleDao.insertRuleParam(session, templateRule, param); session.commit(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java index 6c74a0fdd1e..b2363717888 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java @@ -33,11 +33,11 @@ import org.sonar.db.qualityprofile.ActiveRuleDao; import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.qualityprofile.QualityProfileDto; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.qualityprofile.QProfileTesting; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.rule.index.RuleIndexer; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java index 989a5e311ef..a50e3f95643 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java @@ -41,12 +41,12 @@ import org.sonar.db.qualityprofile.ActiveRuleDto; import org.sonar.db.qualityprofile.ActiveRuleParamDto; import org.sonar.db.qualityprofile.QualityProfileDao; import org.sonar.db.qualityprofile.QualityProfileDto; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.qualityprofile.QProfileTesting; import org.sonar.server.qualityprofile.index.ActiveRuleIndexer; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.rule.index.RuleIndexDefinition; import org.sonar.server.rule.index.RuleIndexer; import org.sonar.server.rule.index.RuleNormalizer; @@ -247,7 +247,9 @@ public class SearchActionMediumTest { public void search_template_rules() throws Exception { RuleDto templateRule = RuleTesting.newXooX1().setIsTemplate(true); ruleDao.insert(dbSession, templateRule); - ruleDao.insert(dbSession, RuleTesting.newXooX2()).setTemplateId(templateRule.getId()); + RuleDto rule = RuleTesting.newXooX2(); + rule.setTemplateId(templateRule.getId()); + ruleDao.insert(dbSession, rule); dbSession.commit(); ruleIndexer.index(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java index 45bbd1b7aa9..371c7b172fb 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/ShowActionMediumTest.java @@ -30,13 +30,13 @@ import org.sonar.api.rule.Severity; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Format; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.rule.NewRule; import org.sonar.server.rule.RuleService; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; @@ -74,18 +74,17 @@ public class ShowActionMediumTest { @Test public void show_rule() throws Exception { - RuleDto ruleDto = ruleDao.insert(session, - RuleTesting.newDto(RuleKey.of("java", "S001")) - .setName("Rule S001") - .setDescription("Rule S001 description") - .setDescriptionFormat(Format.HTML) - .setSeverity(Severity.MINOR) - .setStatus(RuleStatus.BETA) - .setConfigKey("InternalKeyS001") - .setLanguage("xoo") - .setTags(newHashSet("tag1", "tag2")) - .setSystemTags(newHashSet("systag1", "systag2")) - ); + RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")) + .setName("Rule S001") + .setDescription("Rule S001 description") + .setDescriptionFormat(Format.HTML) + .setSeverity(Severity.MINOR) + .setStatus(RuleStatus.BETA) + .setConfigKey("InternalKeyS001") + .setLanguage("xoo") + .setTags(newHashSet("tag1", "tag2")) + .setSystemTags(newHashSet("systag1", "systag2")); + ruleDao.insert(session, ruleDto); RuleParamDto param = RuleParamDto.createFor(ruleDto).setName("regex").setType("STRING").setDescription("Reg *exp*").setDefaultValue(".*"); ruleDao.insertRuleParam(session, ruleDto, param); session.commit(); @@ -98,21 +97,20 @@ public class ShowActionMediumTest { @Test public void show_rule_with_default_debt_infos() throws Exception { - RuleDto ruleDto = ruleDao.insert(session, - RuleTesting.newDto(RuleKey.of("java", "S001")) - .setName("Rule S001") - .setDescription("Rule S001 description") - .setSeverity(Severity.MINOR) - .setStatus(RuleStatus.BETA) - .setConfigKey("InternalKeyS001") - .setLanguage("xoo") - .setDefaultRemediationFunction("LINEAR_OFFSET") - .setDefaultRemediationCoefficient("5d") - .setDefaultRemediationOffset("10h") - .setRemediationFunction(null) - .setRemediationCoefficient(null) - .setRemediationOffset(null) - ); + RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")) + .setName("Rule S001") + .setDescription("Rule S001 description") + .setSeverity(Severity.MINOR) + .setStatus(RuleStatus.BETA) + .setConfigKey("InternalKeyS001") + .setLanguage("xoo") + .setDefaultRemediationFunction("LINEAR_OFFSET") + .setDefaultRemediationCoefficient("5d") + .setDefaultRemediationOffset("10h") + .setRemediationFunction(null) + .setRemediationCoefficient(null) + .setRemediationOffset(null); + ruleDao.insert(session, ruleDto); session.commit(); session.clearCache(); @@ -125,7 +123,7 @@ public class ShowActionMediumTest { @Test public void show_rule_with_overridden_debt() throws Exception { - RuleDto ruleDto = ruleDao.insert(session, + RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")) .setName("Rule S001") .setDescription("Rule S001 description") @@ -138,8 +136,8 @@ public class ShowActionMediumTest { .setDefaultRemediationOffset(null) .setRemediationFunction("LINEAR_OFFSET") .setRemediationCoefficient("5d") - .setRemediationOffset("10h") - ); + .setRemediationOffset("10h"); + ruleDao.insert(session, ruleDto); session.commit(); session.clearCache(); @@ -150,21 +148,20 @@ public class ShowActionMediumTest { @Test public void show_rule_with_default_and_overridden_debt_infos() throws Exception { - RuleDto ruleDto = ruleDao.insert(session, - RuleTesting.newDto(RuleKey.of("java", "S001")) - .setName("Rule S001") - .setDescription("Rule S001 description") - .setSeverity(Severity.MINOR) - .setStatus(RuleStatus.BETA) - .setConfigKey("InternalKeyS001") - .setLanguage("xoo") - .setDefaultRemediationFunction("LINEAR") - .setDefaultRemediationCoefficient("5min") - .setDefaultRemediationOffset(null) - .setRemediationFunction("LINEAR_OFFSET") - .setRemediationCoefficient("5d") - .setRemediationOffset("10h") - ); + RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")) + .setName("Rule S001") + .setDescription("Rule S001 description") + .setSeverity(Severity.MINOR) + .setStatus(RuleStatus.BETA) + .setConfigKey("InternalKeyS001") + .setLanguage("xoo") + .setDefaultRemediationFunction("LINEAR") + .setDefaultRemediationCoefficient("5min") + .setDefaultRemediationOffset(null) + .setRemediationFunction("LINEAR_OFFSET") + .setRemediationCoefficient("5d") + .setRemediationOffset("10h"); + ruleDao.insert(session, ruleDto); session.commit(); session.clearCache(); @@ -175,22 +172,21 @@ public class ShowActionMediumTest { @Test public void show_rule_with_no_default_and_no_overridden_debt() throws Exception { - RuleDto ruleDto = ruleDao.insert(session, - RuleTesting.newDto(RuleKey.of("java", "S001")) - .setName("Rule S001") - .setDescription("Rule S001 description") - .setDescriptionFormat(Format.HTML) - .setSeverity(Severity.MINOR) - .setStatus(RuleStatus.BETA) - .setConfigKey("InternalKeyS001") - .setLanguage("xoo") - .setDefaultRemediationFunction(null) - .setDefaultRemediationCoefficient(null) - .setDefaultRemediationOffset(null) - .setRemediationFunction(null) - .setRemediationCoefficient(null) - .setRemediationOffset(null) - ); + RuleDto ruleDto = RuleTesting.newDto(RuleKey.of("java", "S001")) + .setName("Rule S001") + .setDescription("Rule S001 description") + .setDescriptionFormat(Format.HTML) + .setSeverity(Severity.MINOR) + .setStatus(RuleStatus.BETA) + .setConfigKey("InternalKeyS001") + .setLanguage("xoo") + .setDefaultRemediationFunction(null) + .setDefaultRemediationCoefficient(null) + .setDefaultRemediationOffset(null) + .setRemediationFunction(null) + .setRemediationCoefficient(null) + .setRemediationOffset(null); + ruleDao.insert(session, ruleDto); session.commit(); session.clearCache(); @@ -202,7 +198,8 @@ public class ShowActionMediumTest { @Test public void encode_html_description_of_custom_rule() throws Exception { // Template rule - RuleDto templateRule = ruleDao.insert(session, RuleTesting.newTemplateRule(RuleKey.of("java", "S001"))); + RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); + ruleDao.insert(session, templateRule); session.commit(); // Custom rule diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java index 7cd7fbbecff..d5a7c481057 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/ws/UpdateActionMediumTest.java @@ -31,12 +31,12 @@ import org.sonar.api.rule.Severity; import org.sonar.core.permission.GlobalPermissions; import org.sonar.db.DbClient; import org.sonar.db.DbSession; +import org.sonar.db.rule.RuleDao; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleParamDto; import org.sonar.db.rule.RuleTesting; import org.sonar.server.rule.NewRule; import org.sonar.server.rule.RuleService; -import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.ServerTester; import org.sonar.server.tester.UserSessionRule; import org.sonar.server.ws.WsTester; @@ -51,7 +51,7 @@ public class UpdateActionMediumTest { @Rule public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester). - login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); + login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); WsTester wsTester; @@ -76,7 +76,8 @@ public class UpdateActionMediumTest { @Test public void update_custom_rule() throws Exception { // Template rule - RuleDto templateRule = ruleDao.insert(session, RuleTesting.newTemplateRule(RuleKey.of("java", "S001"))); + RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); + ruleDao.insert(session, templateRule); RuleParamDto param = RuleParamDto.createFor(templateRule).setName("regex").setType("STRING").setDescription("Reg ex").setDefaultValue(".*"); ruleDao.insertRuleParam(session, templateRule, param); session.commit(); @@ -104,7 +105,8 @@ public class UpdateActionMediumTest { @Test public void fail_to_update_custom_when_description_is_empty() { // Template rule - RuleDto templateRule = ruleDao.insert(session, RuleTesting.newTemplateRule(RuleKey.of("java", "S001"))); + RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("java", "S001")); + ruleDao.insert(session, templateRule); // Custom rule RuleDto customRule = RuleTesting.newCustomRule(templateRule); @@ -112,7 +114,7 @@ public class UpdateActionMediumTest { session.commit(); session.clearCache(); - WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update") + WsTester.TestRequest request = wsTester.newPostRequest("api/rules", "update") .setParam("key", customRule.getKey().toString()) .setParam("name", "My custom rule") .setParam("markdown_description", ""); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete-result.xml deleted file mode 100644 index 1fb8fabd0b5..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete-result.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_profile-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_profile-result.xml deleted file mode 100644 index 7c678e3f49e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_profile-result.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_rule-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_rule-result.xml deleted file mode 100644 index 281f14a4daf..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_from_rule-result.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameter-result.xml deleted file mode 100644 index 2fda189a9b4..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameter-result.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters-result.xml deleted file mode 100644 index 21b52c9dad7..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters-result.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml deleted file mode 100644 index 843e2452204..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml deleted file mode 100644 index 8e12efd7f25..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/empty.xml deleted file mode 100644 index af2060c5dcd..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/empty.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert-result.xml deleted file mode 100644 index b2e08355fe3..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert-result.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter-result.xml deleted file mode 100644 index ed2e17d48d3..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter-result.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter.xml deleted file mode 100644 index 780a93bd3dc..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/insert_parameter.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/shared.xml deleted file mode 100644 index 67a66c3adda..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/shared.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update-result.xml deleted file mode 100644 index 99f81d6251c..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update-result.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update_parameter-result.xml deleted file mode 100644 index 289da2f39f2..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/db/ActiveRuleDaoTest/update_parameter-result.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/empty.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/empty.xml deleted file mode 100644 index 871dedcb5e9..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/empty.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert-result.xml deleted file mode 100644 index 4baf0a8327f..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert-result.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_all-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_all-result.xml deleted file mode 100644 index ce6e8da3e4a..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_all-result.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter-result.xml deleted file mode 100644 index 423fc21f0c0..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter-result.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter.xml deleted file mode 100644 index de4e4e969ca..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/insert_parameter.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectAll.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectAll.xml deleted file mode 100644 index 7d870c0d234..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectAll.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectById.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectById.xml deleted file mode 100644 index 90c57a60a71..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectById.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectNonManual.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectNonManual.xml deleted file mode 100644 index f76ce5c6545..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectNonManual.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectParameters.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectParameters.xml deleted file mode 100644 index 6e32ecd7020..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/selectParameters.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_name.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_name.xml deleted file mode 100644 index 90c57a60a71..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_name.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_rule_key.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_rule_key.xml deleted file mode 100644 index 90c57a60a71..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_rule_key.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_sub_characteristic_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_sub_characteristic_id.xml deleted file mode 100644 index e897bb66dad..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_by_sub_characteristic_id.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_language.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_language.xml deleted file mode 100644 index 1514ed39a9e..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_language.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_id.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_id.xml deleted file mode 100644 index 079e238d48c..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_id.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_ids.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_ids.xml deleted file mode 100644 index daa28d75172..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/select_parameters_by_rule_ids.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update-result.xml deleted file mode 100644 index 11fadab518f..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update-result.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update.xml deleted file mode 100644 index 95e5f4c23ff..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter-result.xml deleted file mode 100644 index e60f87e31b3..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter-result.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter.xml b/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter.xml deleted file mode 100644 index 8ac19218587..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/rule/db/RuleDaoTest/update_parameter.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - -- 2.39.5