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
@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<Class, Dao> 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;
- }
}
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;
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);
}
}
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;
// Elasticsearch
EsSearchModule.class,
- // DAOs to be moved to sonar-db
- RuleDao.class,
- ActiveRuleDao.class,
-
// rules/qprofiles
RuleIndex2.class,
ActiveRuleIndex2.class,
}
private RuleDto initRule(RuleKey ruleKey, RuleActivatorContext context, DbSession dbSession) {
- RuleDto rule = db.deprecatedRuleDao().getNullableByKey(dbSession, ruleKey);
- if (rule == null) {
+ Optional<RuleDto> 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) {
+++ /dev/null
-/*
- * 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<ActiveRuleMapper, ActiveRuleDto, ActiveRuleKey> {
-
- 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<ActiveRuleDto> selectByRule(DbSession dbSession, RuleDto rule) {
- Preconditions.checkNotNull(rule.getId(), RULE_IS_NOT_PERSISTED);
- return mapper(dbSession).selectByRuleId(rule.getId());
- }
-
- public List<ActiveRuleDto> selectAll(DbSession dbSession) {
- return mapper(dbSession).selectAll();
- }
-
- public List<ActiveRuleParamDto> selectAllParams(DbSession dbSession) {
- return mapper(dbSession).selectAllParams();
- }
-
- public Optional<ActiveRuleDto> selectByActiveRuleKey(DbSession dbSession, ActiveRuleKey key) {
- return Optional.fromNullable(mapper(dbSession).selectByKey(key.qProfile(), key.ruleKey().repository(), key.ruleKey().rule()));
- }
-
- public List<ActiveRuleDto> selectByActiveRuleKeys(final DbSession dbSession, final List<ActiveRuleKey> keys) {
- if (keys.isEmpty()) {
- return emptyList();
- }
-
- List<SqlActiveRuleKey> sqlKeys = new ArrayList<>();
- for (ActiveRuleKey key : keys) {
- sqlKeys.add(new SqlActiveRuleKey(key));
- }
-
- return DatabaseUtils.executeLargeInputs(sqlKeys, new Function<List<SqlActiveRuleKey>, List<ActiveRuleDto>>() {
- @Override
- public List<ActiveRuleDto> apply(@Nonnull List<SqlActiveRuleKey> 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<ActiveRuleDto> selectByProfileKey(DbSession session, String profileKey) {
- return mapper(session).selectByProfileKey(profileKey);
- }
-
- /**
- * Finder methods for ActiveRuleParams
- */
-
- public List<ActiveRuleParamDto> 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<ActiveRuleParamDto> selectParamsByActiveRuleId(DbSession dbSession, Integer activeRuleId) {
- return mapper(dbSession).selectParamsByActiveRuleId(activeRuleId);
- }
-
- public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(final DbSession dbSession, List<Integer> activeRuleIds) {
- if (activeRuleIds.isEmpty()) {
- return emptyList();
- }
-
- return DatabaseUtils.executeLargeInputs(activeRuleIds, new Function<List<Integer>, List<ActiveRuleParamDto>>() {
- @Override
- public List<ActiveRuleParamDto> apply(@Nullable List<Integer> 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<ActiveRuleDto> activeRules = selectByRule(dbSession, rule);
- for (ActiveRuleDto activeRule : activeRules) {
- for (ActiveRuleParamDto activeParam : selectParamsByActiveRuleKey(dbSession, activeRule.getKey())) {
- if (activeParam.getKey().equals(paramKey)) {
- deleteParam(dbSession, activeRule, activeParam);
- }
- }
- }
- }
-}
+++ /dev/null
-/*
- * 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;
String parentKey = null;
Integer parentId = activeRuleDto.getParentId();
if (parentId != null) {
- ActiveRuleDto parentDto = db.deprecatedActiveRuleDao().selectById(session, parentId);
- if (parentDto != null) {
- parentKey = parentDto.getKey().toString();
- }
+
}
/* Creating updateRequest */
.upsert(getUpsertFor(ActiveRuleField.ALL_FIELDS, newRule)));
// Get the RuleParameters
- for (ActiveRuleParamDto param : db.deprecatedActiveRuleDao().selectParamsByActiveRuleKey(session, key)) {
+ for (ActiveRuleParamDto param : db.activeRuleDao().selectParamsByActiveRuleKey(session, key)) {
requests.addAll(normalizeNested(param, key));
}
*/
package org.sonar.server.qualityprofile.ws;
+import com.google.common.base.Optional;
import java.util.Date;
import java.util.Map.Entry;
import org.elasticsearch.action.search.SearchResponse;
import org.sonar.api.utils.DateUtils;
import org.sonar.api.utils.Paging;
import org.sonar.api.utils.text.JsonWriter;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.user.UserDto;
import org.sonar.server.activity.index.ActivityIndex;
-import org.sonar.server.db.DbClient;
import org.sonar.server.es.SearchOptions;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.qualityprofile.QProfileActivity;
Result<QProfileActivity> 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> ruleDto = dbClient.ruleDao().selectByKey(session, profileActivity.ruleKey());
+ profileActivity.ruleName(ruleDto.isPresent() ? ruleDto.get().getName() : null);
String login = profileActivity.getLogin();
if (login != null) {
+++ /dev/null
-/*
- * 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<RuleMapper, RuleDto, RuleKey> {
-
- 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<RuleDto> selectByNonManual(DbSession session) {
- return mapper(session).selectNonManual();
- }
-
- public List<RuleDto> 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<RuleParamDto> selectAllRuleParams(DbSession session) {
- return mapper(session).selectAllParams();
- }
-
- public List<RuleParamDto> selectRuleParamsByRuleKey(DbSession session, RuleKey key) {
- return mapper(session).selectParamsByRuleKey(key);
- }
-
- public List<RuleDto> selectRulesByDebtSubCharacteristicId(DbSession session, int id) {
- return mapper(session).selectBySubCharacteristicId(id);
- }
-
- public List<RuleDto> selectEnabledAndNonManual(DbSession session) {
- return mapper(session).selectEnabledAndNonManual();
- }
-}
+++ /dev/null
-/*
- * 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;
*/
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;
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<RuleDto> templateRule = db.ruleDao().selectById(templateId, session);
+ if (templateRule.isPresent()) {
+ RuleKey templateKey = templateRule.get().getKey();
templateKeyFieldValue = templateKey != null ? templateKey.toString() : null;
}
}
.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()));
}
+++ /dev/null
-/*
- * 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);
- }
-}
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;
@Mock
RuleDao ruleDao;
@Mock
- org.sonar.server.rule.db.RuleDao deprecatedRuleDao;
- @Mock
RuleOperations ruleOperations;
@Mock
DebtRulesXMLImporter rulesXMLImporter;
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);
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();
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
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();
assertThat(rule.getDefaultRemediationFunction()).isNull();
assertThat(rule.getDefaultRemediationCoefficient()).isNull();
assertThat(rule.getDefaultRemediationOffset()).isNull();
- assertThat(rule.getUpdatedAt()).isEqualTo(now);
+ assertThat(rule.getUpdatedAtInMs()).isEqualTo(now.getTime());
}
@Test
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();
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
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();
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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);
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);
.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));
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;
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;
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);
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);
.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));
+++ /dev/null
-/*
- * 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<ActiveRuleDto> 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<ActiveRuleParamDto> 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<ActiveRule> 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<ActiveRule> 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<String, Long> 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<String, Long> 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<String, Multimap<String, FacetValue>> 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<String> 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<String, Multimap<String, FacetValue>> 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();
- }
-
-}
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;
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;
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;
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;
@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;
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());
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)
+++ /dev/null
-/*
- * 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<RuleDto> 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<RuleDto> 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<RuleParamDto> 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<RuleParamDto> 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<RuleParamDto> 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");
- }
-}
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;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login()
- .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ .setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
WsTester wsTester;
RuleDao ruleDao;
@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();
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;
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;
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();
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;
@Test
public void show_rule() throws Exception {
- RuleDto ruleDto = ruleDao.insert(session,
- RuleTesting.newDto(RuleKey.of("java", "S001"))
- .setName("Rule S001")
- .setDescription("Rule S001 <b>description</b>")
- .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 <b>description</b>")
+ .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();
@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 <b>description</b>")
- .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 <b>description</b>")
+ .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();
@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 <b>description</b>")
.setDefaultRemediationOffset(null)
.setRemediationFunction("LINEAR_OFFSET")
.setRemediationCoefficient("5d")
- .setRemediationOffset("10h")
- );
+ .setRemediationOffset("10h");
+ ruleDao.insert(session, ruleDto);
session.commit();
session.clearCache();
@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 <b>description</b>")
- .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 <b>description</b>")
+ .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();
@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 <b>description</b>")
- .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 <b>description</b>")
+ .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();
@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
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;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).
- login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
WsTester wsTester;
@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();
@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);
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", "");
+++ /dev/null
-<dataset>
-
- <!--<active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"-->
-
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" />
-
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <!--<active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"-->
-
- <!--<active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"-->
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <!--<active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"-->
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <!--<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>-->
- <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <!--<active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>-->
- <!--<active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>-->
-
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <!-- Parent of Active rule 1 -->
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"/>
-
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
- <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
- <!--<active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>-->
- <!--<active_rule_parameters id="4" active_rule_id="3" rules_parameter_id="2" rules_parameter_key="format" value="text"/>-->
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <!-- Parent of Active rule 1 -->
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"/>
-
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
- <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
- <active_rule_parameters id="4" active_rule_id="3" rules_parameter_id="2" rules_parameter_key="format" value="text"/>
-
-</dataset>
+++ /dev/null
-<dataset>
- <rules_parameters id="1" rule_id="10" name="max" param_type="INTEGER" default_value="30" description="My Parameter"/>
-
- <rules tags="[null]" system_tags="[null]" id="10" plugin_rule_key="Parent1" plugin_name="checkstyle" name="Parent Rule 1" description="Parent Rule 1" status="READY"
- plugin_config_key="Parent1" priority="2" is_template="[false]" language="golo" created_at="1981-10-24 15:20:00" />
-
- <rules_profiles id="1" name="Child" language="java" parent_name="Parent" version="1"
- used_profile="[false]" is_default="[false]"/>
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
-
-</dataset>
+++ /dev/null
-<dataset>
- <rules_parameters id="1" rule_id="10" name="max" param_type="INTEGER" default_value="30" description="My Parameter"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <rules tags="[null]" system_tags="[null]" id="10" plugin_rule_key="Parent1" plugin_name="checkstyle" name="Parent Rule 1" description="Parent Rule 1" status="READY"
- plugin_config_key="Parent1" priority="2" is_template="[false]" language="golo" created_at="1981-10-24 15:20:00" />
-
- <rules_profiles id="1" name="Child" language="java" parent_name="Parent" version="1"
- used_profile="[false]" is_default="[false]"/>
-</dataset>
+++ /dev/null
-<dataset>
- <rules tags="[null]" system_tags="[null]" id="10" plugin_rule_key="Parent1" plugin_name="checkstyle" name="Parent Rule 1" description="Parent Rule 1" status="READY"
- plugin_config_key="Parent1" priority="2" is_template="[false]" language="golo" created_at="1981-10-24 15:20:00" />
-
- <rules tags="[null]" system_tags="[null]" id="11" plugin_rule_key="Parent2" plugin_name="checkstyle" name="Parent Rule 2" description="Parent Rule 2" status="READY"
- plugin_config_key="Parent1" priority="2" is_template="[false]" language="golo" created_at="1981-10-24 15:20:00" />
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"/>
-
- <!-- Parent of Active rule 1 -->
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"/>
-
- <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/>
- <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
- <rules_profiles id="1" name="Child" language="java" parent_name="Parent" version="1"
- used_profile="[false]" is_default="[false]"/>
-
- <rules_profiles id="2" name="Parent" language="java" parent_name="[null]" version="1"
- used_profile="[false]" is_default="[false]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rules created_at="[null]" updated_at="[null]" id="1" profile_id="1" rule_id="10" failure_level="4" inheritance="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"/>
-
- <active_rules created_at="[null]" updated_at="[null]" id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <active_rule_parameters id="1" active_rule_id="2" rules_parameter_id="3" rules_parameter_key="newMax" value="30"/>
- <active_rule_parameters id="2" active_rule_id="1" rules_parameter_id="2" rules_parameter_key="format" value="html"/>
-
- <active_rule_parameters id="3" active_rule_id="2" rules_parameter_id="1" rules_parameter_key="max" value="15"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
- plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart" template_id="3"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix" description_format="MARKDOWN"
- created_at="2013-12-16" updated_at="2013-12-16"
- created_at_ms="0" updated_at_ms="0"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
- plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart" created_at="2013-12-16" updated_at="2013-12-16" template_id="3"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix" description_format="HTML"
- created_at_ms="0" updated_at_ms="0"
- />
-
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="NewRuleKey2" plugin_name="plugin2" name="new name2" description="new description2" status="BETA"
- plugin_config_key="NewConfigKey2" priority="2" is_template="[false]" language="js" created_at="2013-12-16" updated_at="2013-12-16" template_id="[null]"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
- characteristic_id="102" default_characteristic_id="103"
- remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR"
- remediation_coeff="5d" default_remediation_coeff="1h"
- remediation_offset="10h" default_remediation_offset="5min"
- effort_to_fix_description="squid.S115.effortToFix2" description_format="MARKDOWN"
- created_at_ms="0" updated_at_ms="0"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
- plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart" created_at="2013-12-16" updated_at="2013-12-17" template_id="3"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="linear" default_remediation_function="linear_offset"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix"
- created_at_ms="[null]" updated_at_ms="[null]"
- />
- <rules_parameters id="1" rule_id="1" name="max" param_type="INTEGER" default_value="30" description="My Parameter"/>
-</dataset>
+++ /dev/null
-<dataset>
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name" description="new description" status="DEPRECATED"
- plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart" created_at="2013-12-16" updated_at="2013-12-17" template_id="3"
- note_data="[null]" note_user_login="[null]" note_created_at="[null]" note_updated_at="[null]"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="linear" default_remediation_function="linear_offset"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix"
- created_at_ms="[null]" updated_at_ms="[null]"
- />
-</dataset>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle" name="Avoid Null" description="Should avoid NULL" status="READY"
- note_data="Rule note with accents éèà" note_user_login="polop.palap" note_created_at="2013-12-25" description_format="HTML"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="linear" default_remediation_function="linear_offset"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"
- />
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidComparison" plugin_name="checkstyle"
- name="Avoid Comparison" description="Should avoid ==" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="AvoidNull" plugin_name="manual" name="Manual Rule"
- description="Should not appear" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules_parameters id="1" rule_id="1" name="myParameter" param_type="plop" default_value="plouf"
- description="My Parameter"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidComparison" plugin_name="checkstyle"
- name="Avoid Comparison" description="Should avoid ==" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidComparison" plugin_name="checkstyle"
- name="Avoid Comparison" description="Should avoid ==" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <!-- Rule linked to a sub characteristic -->
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="UselessImportCheck" plugin_name="squid" name="UselessImportCheck" description="Useless imports should be removed" status="READY"
- characteristic_id="2" default_characteristic_id="50"
- remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="5d" default_remediation_coeff="5d"
- remediation_offset="10h" default_remediation_offset="10h" updated_at="2014-02-19"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <!-- Rule linked to a sub characteristic -->
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="LeftCurlyBraceStartLineCheck" plugin_name="squid" name="LeftCurlyBraceStartLineCheck" description="Left curly braces should be located at the beginning of lines of code" status="READY"
- characteristic_id="3" default_characteristic_id="50"
- remediation_function="LINEAR_OFFSET" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="5d" default_remediation_coeff="5d"
- remediation_offset="10h" default_remediation_offset="10h" updated_at="2014-02-19"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <!-- Rule linked to a disabled sub characteristic -> should never be returned -->
- <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="CallToFileDeleteOnExitMethod" plugin_name="squid" name="CallToFileDeleteOnExitMethod" description="CallToFileDeleteOnExitMethod" status="READY"
- characteristic_id="11" default_characteristic_id="50"
- remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="5d" default_remediation_coeff="5d"
- remediation_offset="[null]" default_remediation_offset="10h" updated_at="2014-02-19"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <!-- Removed rule linked to one enable sub characteristic -->
- <rules tags="[null]" system_tags="[null]" id="4" plugin_rule_key="ObjectFinalizeOverridenCallsSuperFinalizeCheck" plugin_name="squid" name="ObjectFinalizeOverridenCallsSuperFinalizeCheck" description="super.finalize() should be called at the end of Object.finalize() implementations" status="REMOVED"
- characteristic_id="3" default_characteristic_id="50"
- remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="5d" default_remediation_coeff="5min"
- remediation_offset="[null]" default_remediation_offset="10h" updated_at="2014-02-19"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <!-- Rule linked to a sub characteristic, but only default characteristic is linked -->
- <rules tags="[null]" system_tags="[null]" id="5" plugin_rule_key="RightCurlyBraceStartLineCheck" plugin_name="squid" name="RightCurlyBraceStartLineCheck" description="Right curly braces should be located at the beginning of lines of code" status="READY"
- characteristic_id="[null]" default_characteristic_id="3"
- remediation_function="[null]" default_remediation_function="LINEAR"
- remediation_coeff="[null]" default_remediation_coeff="5d"
- remediation_offset="[null]" default_remediation_offset="[null]" updated_at="2014-02-19"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- language="xoo"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"
- />
- <rules_parameters id="1" rule_id="1" name="myParameter" param_type="plop" default_value="plouf"
- description="My Parameter"/>
-
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="Unused" plugin_name="unused" name="Unused Rule"
- description="Not used" status="READY" language="java"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"
- />
- <rules_parameters id="2" rule_id="2" name="otherParam" param_type="plop" default_value="plouf"
- description="Other Parameter"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules_parameters id="1" rule_id="1" name="myParameter" param_type="plop" default_value="plouf"
- description="My Parameter"/>
-
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="Unused" plugin_name="unused" name="Unused Rule"
- description="Not used" status="REMOVED"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules_parameters id="2" rule_id="2" name="otherParam" param_type="plop" default_value="plouf"
- description="Other Parameter"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="Unused" plugin_name="unused" name="Unused Rule"
- description="Not used" status="REMOVED"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <rules_parameters id="1" rule_id="1" name="myParameter" param_type="plop" default_value="plouf"
- description="My Parameter"/>
-
- <rules_parameters id="2" rule_id="2" name="otherParam" param_type="plop" default_value="plouf"
- description="Other Parameter"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="NewRuleKey" plugin_name="plugin" name="new name"
- description="new description" status="DEPRECATED"
- plugin_config_key="NewConfigKey" priority="0" is_template="[true]" language="dart"
- created_at="2011-04-25 01:05:00" updated_at="2014-01-01" template_id="3"
- note_data="My note" note_user_login="admin" note_created_at="2013-12-19" note_updated_at="2013-12-20"
- characteristic_id="100" default_characteristic_id="101"
- remediation_function="LINEAR" default_remediation_function="LINEAR_OFFSET"
- remediation_coeff="1h" default_remediation_coeff="5d"
- remediation_offset="5min" default_remediation_offset="10h"
- effort_to_fix_description="squid.S115.effortToFix" description_format="MARKDOWN"
- created_at_ms="1500000000000" updated_at_ms="0"
- />
-
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="Parent1" plugin_name="checkstyle"
- name="Parent Rule 1" description="Parent Rule 1" status="READY"
- plugin_config_key="Parent1" priority="2" is_template="[false]" language="golo" created_at="1981-10-24 15:20:00"
- updated_at="[null]" template_id="[null]"
- note_created_at="[null]" note_data="[null]" note_updated_at="[null]" note_user_login="[null]"
- description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="Parent2" plugin_name="checkstyle"
- name="Parent Rule 2" description="Parent Rule 2" status="READY"
- plugin_config_key="Parent2" priority="2" is_template="[false]" language="dart" created_at="1982-12-14 03:15:00"
- updated_at="[null]" template_id="[null]"
- note_created_at="[null]" note_data="[null]" note_updated_at="[null]" note_user_login="[null]"
- description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
-
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- plugin_config_key="AvoidNull" priority="2" is_template="[false]" language="golo"
- created_at="2011-04-25 01:05:00" template_id="2" description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <rules tags="[null]" system_tags="[null]" id="2" plugin_rule_key="Parent1" plugin_name="checkstyle"
- name="Parent Rule 1" description="Parent Rule 1" status="READY"
- plugin_config_key="Parent1" priority="2" is_template="[false]" language="golo" created_at="1981-10-24 15:20:00"
- description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <rules tags="[null]" system_tags="[null]" id="3" plugin_rule_key="Parent2" plugin_name="checkstyle"
- name="Parent Rule 2" description="Parent Rule 2" status="READY"
- plugin_config_key="Parent2" priority="2" is_template="[false]" language="dart" created_at="1982-12-14 03:15:00"
- description_format="HTML"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
-</dataset>
+++ /dev/null
-<dataset>
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <rules_parameters id="1" rule_id="1" name="max" param_type="STRING" default_value="^[a-z]+(\.[a-z][a-z0-9]*)*$"
- description="Regular expression used to check the package names against."/>
-</dataset>
+++ /dev/null
-<dataset>
- <rules tags="[null]" system_tags="[null]" id="1" plugin_rule_key="AvoidNull" plugin_name="checkstyle"
- name="Avoid Null" description="Should avoid NULL" status="READY"
- created_at_ms="1500000000000" updated_at_ms="1600000000000"/>
-
- <rules_parameters id="1" rule_id="1" name="max" param_type="INTEGER" default_value="30" description="My Parameter"/>
-</dataset>