diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-05-05 10:33:18 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-05-05 10:50:19 +0200 |
commit | cab17f133fb105496dc95c5f8a445b4c09d1ed4c (patch) | |
tree | 2dfc07aa6ad63e22259ac3be693bcb3e861f5bba | |
parent | 7afa75cf2ad87fa214502bf93c85d4a150bea5e4 (diff) | |
download | sonarqube-cab17f133fb105496dc95c5f8a445b4c09d1ed4c.tar.gz sonarqube-cab17f133fb105496dc95c5f8a445b4c09d1ed4c.zip |
Moving AcgiveRuleDao to BaseDao Impl
23 files changed, 1078 insertions, 57 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java index 7971d7dde94..6373445f225 100644 --- a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleDto.java @@ -20,17 +20,17 @@ package org.sonar.core.qualityprofile.db; -import org.sonar.core.rule.SeverityUtil; - import org.apache.commons.lang.StringUtils; +import org.sonar.api.rule.RuleKey; +import org.sonar.core.db.Dto; +import org.sonar.core.rule.SeverityUtil; import javax.annotation.CheckForNull; import javax.annotation.Nullable; import javax.persistence.Transient; - import java.util.Date; -public class ActiveRuleDto { +public class ActiveRuleDto implements Dto<ActiveRuleKey> { public static final String INHERITED = "INHERITED"; public static final String OVERRIDES = "OVERRIDES"; @@ -45,6 +45,13 @@ public class ActiveRuleDto { private String noteUserLogin; private String noteData; + private RuleKey ruleKey; + private QProfileKey qProfileKey; + + public ActiveRuleKey getKey(){ + return ActiveRuleKey.of(qProfileKey, ruleKey); + } + // This field do not exists in db, it's only retrieve by joins @Transient private Integer parentId; diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java new file mode 100644 index 00000000000..b1de4ae515a --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/ActiveRuleKey.java @@ -0,0 +1,92 @@ +package org.sonar.core.qualityprofile.db; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import org.sonar.api.rule.RuleKey; + +import java.io.Serializable; + +/** + * Created by gamars on 05/05/14. + * + * @since 4.4 + */ +public class ActiveRuleKey implements Serializable{ + private final QProfileKey qProfileKey; + private final RuleKey ruleKey; + + protected ActiveRuleKey(QProfileKey qProfileKey, RuleKey ruleKey) { + this.qProfileKey = qProfileKey; + this.ruleKey = ruleKey; + } + + /** + * Create a key. Parameters are NOT null. + */ + public static ActiveRuleKey of(QProfileKey qProfileKey, RuleKey ruleKey) { + Preconditions.checkArgument(!Strings.isNullOrEmpty(qProfileKey.qProfile()), "QProfile is missing key"); + Preconditions.checkArgument(!Strings.isNullOrEmpty(qProfileKey.lang()), "QProfile is missing lang"); + Preconditions.checkArgument(!Strings.isNullOrEmpty(ruleKey.repository()), "RuleKey is missing repository"); + Preconditions.checkArgument(!Strings.isNullOrEmpty(ruleKey.rule()), "RuleKey is missing key"); + return new ActiveRuleKey(qProfileKey, ruleKey); + } + + /** + * Create a key from a string representation (see {@link #toString()}. An {@link IllegalArgumentException} is raised + * if the format is not valid. + */ + public static ActiveRuleKey parse(String s) { + String[] split = s.split(":"); + Preconditions.checkArgument(split.length == 4, "Bad format of activeRule key: " + s); + return ActiveRuleKey.of(QProfileKey.of(split[0], split[1]), + RuleKey.of(split[2], split[3])); + } + + /** + * Never null + */ + public RuleKey ruleKey() { + return ruleKey; + } + + /** + * Never null + */ + public QProfileKey qProfile() { + return qProfileKey; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ActiveRuleKey activeRuleKey = (ActiveRuleKey) o; + if (!qProfileKey.equals(activeRuleKey.qProfileKey)) { + return false; + } + if (!ruleKey.equals(activeRuleKey.ruleKey)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = qProfileKey.hashCode(); + result = 31 * result + ruleKey.hashCode(); + return result; + } + + /** + * Format is "qprofile:rule", for example "Java:squid:AvoidCycle:xpxp" + */ + @Override + public String toString() { + return String.format("%s:%s", ruleKey.toString(), qProfileKey.toString()); + } +} + diff --git a/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QProfileKey.java b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QProfileKey.java new file mode 100644 index 00000000000..995984968f7 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/qualityprofile/db/QProfileKey.java @@ -0,0 +1,87 @@ +package org.sonar.core.qualityprofile.db; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + +import java.io.Serializable; + +/** + * Created by gamars on 05/05/14. + * + * @since 4.4 + */ +public class QProfileKey implements Serializable{ + private final String qProfile, lang; + + protected QProfileKey(String qProfile, String lang) { + this.lang = lang; + this.qProfile = qProfile; + } + + /** + * Create a key. Parameters are NOT null. + */ + public static QProfileKey of(String qProfile, String lang) { + Preconditions.checkArgument(!Strings.isNullOrEmpty(qProfile), "QProfile must be set"); + Preconditions.checkArgument(!Strings.isNullOrEmpty(lang), "Lang must be set"); + return new QProfileKey(qProfile, lang); + } + + /** + * Create a key from a string representation (see {@link #toString()}. An {@link IllegalArgumentException} is raised + * if the format is not valid. + */ + public static QProfileKey parse(String s) { + String[] split = s.split(":"); + Preconditions.checkArgument(split.length == 3, "Bad format of activeRule key: " + s); + return QProfileKey.of(split[0], split[1]); + } + + /** + * Never null + */ + public String lang() { + return lang; + } + + /** + * Never null + */ + public String qProfile() { + return qProfile; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + QProfileKey qProfileKey = (QProfileKey) o; + if (!lang.equals(qProfileKey.lang)) { + return false; + } + if (!qProfile.equals(qProfileKey.qProfile)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = qProfile.hashCode(); + result = 31 * result + lang.hashCode(); + return result; + } + + /** + * Format is "qProfile:lang", for example "Java:javascript" + */ + @Override + public String toString() { + return String.format("%s:%s", qProfile, lang); + } +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java index 1d9b463fdc2..73a41ce1f06 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/rule/RuleKey.java @@ -32,9 +32,9 @@ import java.io.Serializable; public class RuleKey implements Serializable { private final String repository, rule; - private RuleKey(String repository, String rule) { - this.repository = repository; - this.rule = rule; + protected RuleKey(String repositoryKey, String ruleKey) { + this.repository = repositoryKey; + this.rule = ruleKey; } /** diff --git a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java index 94eb313456a..7e0ba1286bf 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java @@ -19,7 +19,6 @@ */ package org.sonar.server.db; -import org.apache.ibatis.session.SqlSession; import org.sonar.core.db.Dao; import org.sonar.core.db.Dto; import org.sonar.core.persistence.DbSession; @@ -30,27 +29,32 @@ import org.sonar.server.search.KeyIndexAction; import java.io.Serializable; -public abstract class BaseDao<E extends Dto<K>, K extends Serializable> +public abstract class BaseDao<T, E extends Dto<K>, K extends Serializable> implements Dao<E, K> { protected final MyBatis mybatis; + private Class<T> mapperClass; - protected BaseDao(MyBatis myBatis) { + protected BaseDao(Class<T> mapperClass, MyBatis myBatis) { + this.mapperClass = mapperClass; this.mybatis = myBatis; } protected abstract String getIndexName(); - protected abstract E doGetByKey(K key, SqlSession session); + protected abstract E doGetByKey(K key, DbSession session); - protected abstract E doInsert(E item, SqlSession session); + protected abstract E doInsert(E item, DbSession session); - protected abstract E doUpdate(E item, SqlSession session); + protected abstract E doUpdate(E item, DbSession session); - protected abstract void doDelete(E item, SqlSession session); + protected abstract void doDelete(E item, DbSession session); - protected abstract void doDeleteByKey(K key, SqlSession session); + protected abstract void doDeleteByKey(K key, DbSession session); + protected T getMapper(DbSession session) { + return session.getMapper(mapperClass); + } protected MyBatis getMyBatis() { return this.mybatis; } diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java b/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java new file mode 100644 index 00000000000..b4c9df5f7f8 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/rule2/ActiveRuleDao.java @@ -0,0 +1,377 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.rule2; + +import com.google.common.collect.Lists; +import org.apache.ibatis.session.SqlSession; +import org.hibernate.cfg.NotYetImplementedException; +import org.sonar.api.ServerComponent; +import org.sonar.core.persistence.DbSession; +import org.sonar.core.persistence.MyBatis; +import org.sonar.core.qualityprofile.db.ActiveRuleDto; +import org.sonar.core.qualityprofile.db.ActiveRuleKey; +import org.sonar.core.qualityprofile.db.ActiveRuleMapper; +import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; +import org.sonar.core.rule.RuleConstants; +import org.sonar.server.db.BaseDao; + +import javax.annotation.CheckForNull; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static com.google.common.collect.Lists.newArrayList; + +public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, ActiveRuleKey> + implements ServerComponent { + + public ActiveRuleDao(MyBatis mybatis) { + super(ActiveRuleMapper.class, mybatis); + } + + @Override + protected String getIndexName() { + return RuleConstants.INDEX_NAME; + } + + @Override + public Iterable<ActiveRuleKey> keysOfRowsUpdatedAfter(long timestamp) { + throw new NotYetImplementedException("Need to implement ActiveRuleDto.doGetByKey() method"); + } + + @Override + protected ActiveRuleDto doGetByKey(ActiveRuleKey key, DbSession session) { + //return getMapper(session).selectByKey(key); + throw new NotYetImplementedException("Need to implement ActiveRuleDto.doGetByKey() method"); + } + + @Override + protected ActiveRuleDto doInsert(ActiveRuleDto item, DbSession session) { + getMapper(session).insert(item); + return item; + } + + @Override + protected ActiveRuleDto doUpdate(ActiveRuleDto item, DbSession session) { + getMapper(session).update(item); + return item; + } + + @Override + protected void doDelete(ActiveRuleDto item, DbSession session) { + getMapper(session).delete(item.getId()); + } + + @Override + protected void doDeleteByKey(ActiveRuleKey key, DbSession session) { + throw new NotYetImplementedException("Need to implement ActiveRuleDto.doDeleteByKey() method"); + } + + + + public void delete(int activeRuleId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).delete(activeRuleId); + } + + public void delete(int activeRuleId) { + SqlSession session = mybatis.openSession(false); + try { + delete(activeRuleId, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void deleteFromRule(int ruleId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteFromRule(ruleId); + } + + public void deleteFromRule(int ruleId) { + SqlSession session = mybatis.openSession(false); + try { + deleteFromRule(ruleId, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void deleteFromProfile(int profileId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteFromProfile(profileId); + } + + public void deleteFromProfile(int profileId) { + SqlSession session = mybatis.openSession(false); + try { + deleteFromProfile(profileId, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByIds(List<Integer> ids) { + SqlSession session = mybatis.openSession(false); + try { + return selectByIds(ids, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByIds(Collection<Integer> ids, SqlSession session) { + if (ids.isEmpty()) { + return Collections.emptyList(); + } + List<ActiveRuleDto> dtosList = newArrayList(); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(ids), 1000); + for (List<Integer> idsPartition : idsPartitionList) { + List<ActiveRuleDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectByIds", newArrayList(idsPartition)); + dtosList.addAll(dtos); + } + return dtosList; + } + + public List<ActiveRuleDto> selectAll() { + SqlSession session = mybatis.openSession(false); + try { + return selectAll(session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectAll(SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectAll(); + } + + public List<ActiveRuleDto> selectByRuleId(int ruleId) { + SqlSession session = mybatis.openSession(false); + try { + return selectByRuleId(ruleId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByRuleId(int ruleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectByRuleId(ruleId); + } + + public List<ActiveRuleDto> selectByProfileId(int profileId) { + SqlSession session = mybatis.openSession(false); + try { + return selectByProfileId(profileId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleDto> selectByProfileId(int profileId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectByProfileId(profileId); + } + + + @CheckForNull + public ActiveRuleDto selectById(int id) { + SqlSession session = mybatis.openSession(false); + try { + return selectById(id, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + @CheckForNull + public ActiveRuleDto selectById(int id, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectById(id); + } + + @CheckForNull + public ActiveRuleDto selectByProfileAndRule(int profileId, int ruleId) { + SqlSession session = mybatis.openSession(false); + try { + return selectByProfileAndRule(profileId, ruleId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + @CheckForNull + public ActiveRuleDto selectByProfileAndRule(int profileId, int ruleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectByProfileAndRule(profileId, ruleId); + } + + public void insert(ActiveRuleParamDto dto, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).insertParameter(dto); + } + + public void insert(ActiveRuleParamDto dto) { + SqlSession session = mybatis.openSession(false); + try { + insert(dto, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void update(ActiveRuleParamDto dto, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).updateParameter(dto); + } + + public void update(ActiveRuleParamDto dto) { + SqlSession session = mybatis.openSession(false); + try { + update(dto, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + + public void deleteParameter(int activeRuleParamId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteParameter(activeRuleParamId); + } + + public void deleteParameter(int activeRuleParamId) { + SqlSession session = mybatis.openSession(false); + try { + deleteParameter(activeRuleParamId, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void deleteParameters(int activeRuleId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteParameters(activeRuleId); + } + + public void deleteParameters(int activeRuleId) { + SqlSession session = mybatis.openSession(false); + try { + deleteParameters(activeRuleId, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void deleteParametersWithParamId(int id, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteParametersWithParamId(id); + } + + public void deleteParametersFromProfile(int profileId) { + SqlSession session = mybatis.openSession(false); + try { + deleteParametersFromProfile(profileId, session); + session.commit(); + } finally { + MyBatis.closeQuietly(session); + } + } + + public void deleteParametersFromProfile(int profileId, SqlSession session) { + session.getMapper(ActiveRuleMapper.class).deleteParametersFromProfile(profileId); + } + + public ActiveRuleParamDto selectParamById(Integer activeRuleParamId) { + SqlSession session = mybatis.openSession(false); + try { + return session.getMapper(ActiveRuleMapper.class).selectParamById(activeRuleParamId); + } finally { + MyBatis.closeQuietly(session); + } + } + + public ActiveRuleParamDto selectParamByActiveRuleAndKey(int activeRuleId, String key) { + SqlSession session = mybatis.openSession(false); + try { + return selectParamByActiveRuleAndKey(activeRuleId, key, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public ActiveRuleParamDto selectParamByActiveRuleAndKey(int activeRuleId, String key, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectParamByActiveRuleAndKey(activeRuleId, key); + } + + public List<ActiveRuleParamDto> selectParamsByActiveRuleId(int activeRuleId) { + SqlSession session = mybatis.openSession(false); + try { + return selectParamsByActiveRuleId(activeRuleId, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleParamDto> selectParamsByActiveRuleId(int activeRuleId, SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectParamsByActiveRuleId(activeRuleId); + } + + public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(List<Integer> activeRuleIds) { + SqlSession session = mybatis.openSession(false); + try { + return selectParamsByActiveRuleIds(activeRuleIds, session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleParamDto> selectParamsByActiveRuleIds(Collection<Integer> activeRuleIds, SqlSession session) { + if (activeRuleIds.isEmpty()) { + return Collections.emptyList(); + } + List<ActiveRuleParamDto> dtosList = newArrayList(); + List<List<Integer>> idsPartitionList = Lists.partition(newArrayList(activeRuleIds), 1000); + for (List<Integer> idsPartition : idsPartitionList) { + List<ActiveRuleParamDto> dtos = session.selectList("org.sonar.core.qualityprofile.db.ActiveRuleMapper.selectParamsByActiveRuleIds", newArrayList(idsPartition)); + dtosList.addAll(dtos); + } + return dtosList; + } + + public List<ActiveRuleParamDto> selectAllParams() { + SqlSession session = mybatis.openSession(false); + try { + return selectAllParams(session); + } finally { + MyBatis.closeQuietly(session); + } + } + + public List<ActiveRuleParamDto> selectAllParams(SqlSession session) { + return session.getMapper(ActiveRuleMapper.class).selectAllParams(); + } + + public List<ActiveRuleParamDto> selectParamsByProfileId(int profileId) { + SqlSession session = mybatis.openSession(false); + try { + return session.getMapper(ActiveRuleMapper.class).selectParamsByProfileId(profileId); + } finally { + MyBatis.closeQuietly(session); + } + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java index aa924cd1e3f..3929c6cdcd8 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java +++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java @@ -22,7 +22,6 @@ package org.sonar.server.rule2; import com.google.common.collect.Lists; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; -import org.apache.ibatis.session.SqlSession; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; import org.sonar.api.rule.RuleKey; @@ -46,11 +45,11 @@ import java.util.Map; import static com.google.common.collect.Lists.newArrayList; -public class RuleDao extends BaseDao<RuleDto, RuleKey> +public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> implements BatchComponent, ServerComponent { public RuleDao(MyBatis mybatis) { - super(mybatis); + super(RuleMapper.class, mybatis); } @Override @@ -60,34 +59,34 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> @Override @CheckForNull - protected RuleDto doGetByKey(RuleKey key, SqlSession session) { + protected RuleDto doGetByKey(RuleKey key, DbSession session) { return getMapper(session).selectByKey(key); } @Override - protected RuleDto doInsert(RuleDto item, SqlSession session) { - session.getMapper(RuleMapper.class).insert(item); + protected RuleDto doInsert(RuleDto item, DbSession session) { + getMapper(session).insert(item); return item; } @Override - protected RuleDto doUpdate(RuleDto item, SqlSession session) { - session.getMapper(RuleMapper.class).update(item); + protected RuleDto doUpdate(RuleDto item, DbSession session) { + getMapper(session).update(item); return item; } @Override - protected void doDelete(RuleDto item, SqlSession session) { + protected void doDelete(RuleDto item, DbSession session) { throw new UnsupportedOperationException("Rules cannot be deleted"); } @Override - protected void doDeleteByKey(RuleKey key, SqlSession session) { + protected void doDeleteByKey(RuleKey key, DbSession session) { throw new UnsupportedOperationException("Rules cannot be deleted"); } public List<RuleDto> selectAll() { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectAll(session); } finally { @@ -95,12 +94,12 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleDto> selectAll(SqlSession session) { + public List<RuleDto> selectAll(DbSession session) { return getMapper(session).selectAll(); } public List<RuleDto> selectEnablesAndNonManual() { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectEnablesAndNonManual(session); } finally { @@ -108,16 +107,16 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleDto> selectEnablesAndNonManual(SqlSession session) { + public List<RuleDto> selectEnablesAndNonManual(DbSession session) { return getMapper(session).selectEnablesAndNonManual(); } - public List<RuleDto> selectNonManual(SqlSession session) { + public List<RuleDto> selectNonManual(DbSession session) { return getMapper(session).selectNonManual(); } public List<RuleDto> selectBySubCharacteristicId(Integer characteristicOrSubCharacteristicId) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectBySubCharacteristicId(characteristicOrSubCharacteristicId, session); } finally { @@ -128,18 +127,18 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> /** * Return all rules (even the REMOVED ones) linked on to a sub characteristic */ - public List<RuleDto> selectBySubCharacteristicId(Integer subCharacteristicId, SqlSession session) { + public List<RuleDto> selectBySubCharacteristicId(Integer subCharacteristicId, DbSession session) { return getMapper(session).selectBySubCharacteristicId(subCharacteristicId); } @CheckForNull - public RuleDto selectById(Integer id, SqlSession session) { + public RuleDto selectById(Integer id, DbSession session) { return getMapper(session).selectById(id); } @CheckForNull public RuleDto selectById(Integer id) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectById(id, session); } finally { @@ -148,14 +147,14 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } @CheckForNull - public RuleDto selectByKey(RuleKey ruleKey, SqlSession session) { + public RuleDto selectByKey(RuleKey ruleKey, DbSession session) { return getMapper(session).selectByKey(ruleKey); } @CheckForNull public RuleDto selectByKey(RuleKey ruleKey) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectByKey(ruleKey, session); } finally { @@ -165,7 +164,7 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> @CheckForNull public RuleDto selectByName(String name) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return getMapper(session).selectByName(name); } finally { @@ -192,7 +191,7 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> // ****************************** public List<RuleParamDto> selectParameters() { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectParameters(session); } finally { @@ -200,12 +199,12 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleParamDto> selectParameters(SqlSession session) { + public List<RuleParamDto> selectParameters(DbSession session) { return getMapper(session).selectAllParams(); } public List<RuleParamDto> selectParametersByRuleId(Integer ruleId) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectParametersByRuleId(ruleId, session); } finally { @@ -213,12 +212,12 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleParamDto> selectParametersByRuleId(Integer ruleId, SqlSession session) { + public List<RuleParamDto> selectParametersByRuleId(Integer ruleId, DbSession session) { return selectParametersByRuleIds(newArrayList(ruleId)); } public List<RuleParamDto> selectParametersByRuleIds(List<Integer> ruleIds) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectParametersByRuleIds(ruleIds, session); } finally { @@ -226,7 +225,7 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleParamDto> selectParametersByRuleIds(List<Integer> ruleIds, SqlSession session) { + public List<RuleParamDto> selectParametersByRuleIds(List<Integer> ruleIds, DbSession session) { List<RuleParamDto> dtos = newArrayList(); List<List<Integer>> partitionList = Lists.partition(newArrayList(ruleIds), 1000); for (List<Integer> partition : partitionList) { @@ -276,14 +275,10 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } @CheckForNull - public RuleParamDto selectParamByRuleAndKey(Integer ruleId, String key, SqlSession session) { + public RuleParamDto selectParamByRuleAndKey(Integer ruleId, String key, DbSession session) { return getMapper(session).selectParamByRuleAndKey(ruleId, key); } - private RuleMapper getMapper(SqlSession session) { - return session.getMapper(RuleMapper.class); - } - // *************************** // Methods for Rule Tags // *************************** @@ -317,12 +312,12 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> this.selectById(existingTag.getRuleId(), session).getKey())); } - public List<RuleRuleTagDto> selectTags(SqlSession session) { + public List<RuleRuleTagDto> selectTags(DbSession session) { return getMapper(session).selectAllTags(); } public List<RuleRuleTagDto> selectTagsByRuleId(Integer ruleId) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectTagsByRuleIds(ruleId, session); } finally { @@ -330,12 +325,12 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleRuleTagDto> selectTagsByRuleIds(Integer ruleId, SqlSession session) { + public List<RuleRuleTagDto> selectTagsByRuleIds(Integer ruleId, DbSession session) { return selectTagsByRuleIds(newArrayList(ruleId), session); } public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { return selectTagsByRuleIds(ruleIds, session); } finally { @@ -343,7 +338,7 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> } } - public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds, SqlSession session) { + public List<RuleRuleTagDto> selectTagsByRuleIds(List<Integer> ruleIds, DbSession session) { List<RuleRuleTagDto> dtos = newArrayList(); List<List<Integer>> partitionList = Lists.partition(newArrayList(ruleIds), 1000); for (List<Integer> partition : partitionList) { @@ -354,7 +349,7 @@ public class RuleDao extends BaseDao<RuleDto, RuleKey> @Override public Collection<RuleKey> keysOfRowsUpdatedAfter(long timestamp) { - SqlSession session = mybatis.openSession(false); + DbSession session = mybatis.openSession(false); try { final List<RuleKey> keys = Lists.newArrayList(); session.select("selectKeysOfRulesUpdatedSince", new Timestamp(timestamp), new ResultHandler() { diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java new file mode 100644 index 00000000000..758e1cc5e9e --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/rule2/ActiveRuleDaoTest.java @@ -0,0 +1,299 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube 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. + * + * SonarQube 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.rule2; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.rule.Severity; +import org.sonar.api.utils.DateUtils; +import org.sonar.core.persistence.AbstractDaoTestCase; +import org.sonar.core.qualityprofile.db.ActiveRuleDao; +import org.sonar.core.qualityprofile.db.ActiveRuleDto; +import org.sonar.core.qualityprofile.db.ActiveRuleParamDto; + +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; + +public class ActiveRuleDaoTest extends AbstractDaoTestCase { + + org.sonar.core.qualityprofile.db.ActiveRuleDao dao; + + @Before + public void createDao() { + dao = new ActiveRuleDao(getMyBatis()); + } + + @Test + public void insert() { + setupData("empty"); + + ActiveRuleDto dto = new ActiveRuleDto() + .setProfileId(1) + .setRuleId(10) + .setSeverity(Severity.MAJOR) + .setInheritance("INHERITED"); + + dao.insert(dto); + + checkTables("insert", "active_rules"); + } + + @Test + public void update() { + setupData("shared"); + + ActiveRuleDto dto = new ActiveRuleDto() + .setId(1) + .setProfileId(1) + .setRuleId(10) + .setSeverity(Severity.BLOCKER) + .setInheritance(null) + .setNoteData("text"); + + dao.update(dto); + + checkTables("update", "active_rules"); + } + + @Test + public void delete() { + setupData("shared"); + + dao.delete(1); + + checkTables("delete", "active_rules"); + } + + @Test + public void delete_from_rule() { + setupData("shared"); + + dao.deleteFromRule(11); + + checkTables("delete_from_rule", "active_rules"); + } + + @Test + public void delete_from_profile() { + setupData("shared"); + + dao.deleteFromProfile(2); + + checkTables("delete_from_profile", "active_rules"); + } + + @Test + public void select_by_id() { + setupData("shared"); + + ActiveRuleDto result = dao.selectById(1); + assertThat(result.getId()).isEqualTo(1); + assertThat(result.getProfileId()).isEqualTo(1); + assertThat(result.getRulId()).isEqualTo(10); + assertThat(result.getSeverityString()).isEqualTo(Severity.MAJOR); + assertThat(result.getInheritance()).isEqualTo("INHERITED"); + assertThat(result.getNoteData()).isEqualTo("some note"); + assertThat(result.getNoteUserLogin()).isEqualTo("henry"); + assertThat(result.getNoteCreatedAt()).isEqualTo(DateUtils.parseDate("2013-12-18")); + assertThat(result.getNoteUpdatedAt()).isEqualTo(DateUtils.parseDate("2013-12-18")); + } + + @Test + public void select_by_ids() { + setupData("shared"); + + List<ActiveRuleDto> result = dao.selectByIds(ImmutableList.of(1)); + assertThat(result).hasSize(1); + assertThat(result.get(0).getParentId()).isEqualTo(2); + + assertThat(dao.selectByIds(ImmutableList.of(1, 2))).hasSize(2); + } + + @Test + public void select_by_profile_and_rule() { + setupData("shared"); + + ActiveRuleDto result = dao.selectByProfileAndRule(1, 10); + assertThat(result.getId()).isEqualTo(1); + assertThat(result.getProfileId()).isEqualTo(1); + assertThat(result.getRulId()).isEqualTo(10); + assertThat(result.getSeverityString()).isEqualTo(Severity.MAJOR); + assertThat(result.getInheritance()).isEqualTo("INHERITED"); + assertThat(result.getNoteData()).isEqualTo("some note"); + assertThat(result.getNoteUserLogin()).isEqualTo("henry"); + assertThat(result.getNoteCreatedAt()).isEqualTo(DateUtils.parseDate("2013-12-18")); + assertThat(result.getNoteUpdatedAt()).isEqualTo(DateUtils.parseDate("2013-12-18")); + } + + @Test + public void select_by_rule() { + setupData("shared"); + + List<ActiveRuleDto> result = dao.selectByRuleId(10); + assertThat(result).hasSize(2); + } + + @Test + public void select_by_profile() { + setupData("shared"); + + List<ActiveRuleDto> result = dao.selectByProfileId(2); + assertThat(result).hasSize(2); + } + + @Test + public void select_all() { + setupData("shared"); + + List<ActiveRuleDto> result = dao.selectAll(); + assertThat(result).hasSize(3); + + assertThat(find(1, result).getParentId()).isEqualTo(2); + assertThat(find(2, result).getParentId()).isNull(); + } + + @Test + public void insert_parameter() { + setupData("empty"); + + ActiveRuleParamDto dto = new ActiveRuleParamDto() + .setActiveRuleId(1) + .setRulesParameterId(1) + .setKey("max") + .setValue("20"); + + dao.insert(dto); + + checkTables("insert_parameter", "active_rule_parameters"); + } + + @Test + public void update_parameter() { + setupData("shared"); + + ActiveRuleParamDto dto = new ActiveRuleParamDto() + .setId(1) + .setActiveRuleId(2) + .setRulesParameterId(3) + .setKey("newMax") + .setValue("30"); + + dao.update(dto); + + checkTables("update_parameter", "active_rule_parameters"); + } + + @Test + public void delete_parameters() { + setupData("shared"); + + dao.deleteParameters(1); + + checkTables("delete_parameters", "active_rule_parameters"); + } + + @Test + public void delete_parameter() { + setupData("shared"); + + dao.deleteParameter(1); + + checkTables("delete_parameter", "active_rule_parameters"); + } + + @Test + public void delete_parameters_from_profile_id() { + setupData("delete_parameters_from_profile_id"); + + dao.deleteParametersFromProfile(2); + + checkTables("delete_parameters_from_profile_id", "active_rule_parameters"); + } + + @Test + public void select_param_by_id() { + setupData("shared"); + + ActiveRuleParamDto result = dao.selectParamById(1); + assertThat(result.getId()).isEqualTo(1); + assertThat(result.getActiveRuleId()).isEqualTo(1); + assertThat(result.getRulesParameterId()).isEqualTo(1); + assertThat(result.getKey()).isEqualTo("max"); + assertThat(result.getValue()).isEqualTo("20"); + } + + @Test + public void select_params_by_active_rule_id() { + setupData("shared"); + + assertThat(dao.selectParamsByActiveRuleId(1)).hasSize(2); + assertThat(dao.selectParamsByActiveRuleId(2)).hasSize(1); + } + + @Test + public void select_param_by_active_rule_and_key() { + setupData("shared"); + + ActiveRuleParamDto result = dao.selectParamByActiveRuleAndKey(1, "max"); + assertThat(result.getId()).isEqualTo(1); + assertThat(result.getActiveRuleId()).isEqualTo(1); + assertThat(result.getRulesParameterId()).isEqualTo(1); + assertThat(result.getKey()).isEqualTo("max"); + assertThat(result.getValue()).isEqualTo("20"); + } + + @Test + public void select_params_by_active_rule_ids() { + setupData("shared"); + + assertThat(dao.selectParamsByActiveRuleIds(ImmutableList.of(1))).hasSize(2); + assertThat(dao.selectParamsByActiveRuleIds(ImmutableList.of(2))).hasSize(1); + assertThat(dao.selectParamsByActiveRuleIds(ImmutableList.of(1, 2))).hasSize(3); + } + + @Test + public void select_params_by_profile_id() { + setupData("shared"); + + assertThat(dao.selectParamsByProfileId(1)).hasSize(2); + } + + @Test + public void select_all_params() { + setupData("shared"); + + assertThat(dao.selectAllParams()).hasSize(3); + } + + private ActiveRuleDto find(final Integer id, List<ActiveRuleDto> dtos){ + return Iterables.find(dtos, new Predicate<ActiveRuleDto>(){ + @Override + public boolean apply(ActiveRuleDto input) { + return input.getId().equals(id); + } + }); + } + +} diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RuleDaoTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RuleDaoTest.java index 704b3c6d082..036a9976943 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule2/RuleDaoTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule2/RuleDaoTest.java @@ -22,7 +22,6 @@ package org.sonar.server.rule2; import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import org.apache.ibatis.session.SqlSession; import org.junit.Before; import org.junit.Test; import org.sonar.api.rule.RuleKey; @@ -31,6 +30,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.utils.DateUtils; import org.sonar.check.Cardinality; import org.sonar.core.persistence.AbstractDaoTestCase; +import org.sonar.core.persistence.DbSession; import org.sonar.core.rule.RuleDto; import org.sonar.core.rule.RuleParamDto; @@ -133,7 +133,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Test public void select_non_manual() throws Exception { setupData("selectNonManual"); - SqlSession session = getMyBatis().openSession(); + DbSession session = getMyBatis().openSession(false); List<RuleDto> ruleDtos = dao.selectNonManual(session); session.commit(); session.close(); diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java index 4a37b01ee6b..e3f97f9216b 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule2/RuleServiceMediumTest.java @@ -236,7 +236,7 @@ public class RuleServiceMediumTest { Map<String, String> _activeRuleParamValue = (Map<String, String>) _activeRuleParams.get(maxParam.getName()); assertThat(_activeRuleParamValue).isNotNull().hasSize(1); - assertThat(_activeRuleParamValue.get(RuleNormalizer.RuleParamField.VALUE.key())).isEqualTo("maximum"); + assertThat(_activeRuleParamValue.get(RuleNormalizer.RuleParamField.DEFAULT_VALUE.key())).isEqualTo("maximum"); } diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete-result.xml new file mode 100644 index 00000000000..39e1decb6d1 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete-result.xml @@ -0,0 +1,12 @@ +<dataset> + + <!--<active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED"--> + <!--note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/>--> + + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_from_profile-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_from_profile-result.xml new file mode 100644 index 00000000000..231e470df28 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_from_profile-result.xml @@ -0,0 +1,12 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/> + + <!--<active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]"--> + <!--note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/>--> + + <!--<active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"--> + <!--note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/>--> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_from_rule-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_from_rule-result.xml new file mode 100644 index 00000000000..4f066dfeaae --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_from_rule-result.xml @@ -0,0 +1,12 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/> + + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <!--<active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]"--> + <!--note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/>--> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameter-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameter-result.xml new file mode 100644 index 00000000000..66bf84129e4 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameter-result.xml @@ -0,0 +1,14 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="[null]" note_updated_at="[null]" note_user_login="[null]" note_data="[null]"/> + + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="[null]" note_updated_at="[null]" note_user_login="[null]" note_data="[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> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters-result.xml new file mode 100644 index 00000000000..4b0e2e7e0e2 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters-result.xml @@ -0,0 +1,14 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="[null]" note_updated_at="[null]" note_user_login="[null]" note_data="[null]"/> + + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="[null]" note_updated_at="[null]" note_user_login="[null]" note_data="[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> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml new file mode 100644 index 00000000000..a77383cece4 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters_from_profile_id-result.xml @@ -0,0 +1,19 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/> + + <!-- Parent of Active rule 1 --> + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/> + + <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> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml new file mode 100644 index 00000000000..148ce414a9a --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/delete_parameters_from_profile_id.xml @@ -0,0 +1,19 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/> + + <!-- Parent of Active rule 1 --> + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/> + + <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> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/empty.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/empty.xml new file mode 100644 index 00000000000..871dedcb5e9 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/empty.xml @@ -0,0 +1,3 @@ +<dataset> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/insert-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/insert-result.xml new file mode 100644 index 00000000000..ee595acf1d8 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/insert-result.xml @@ -0,0 +1,6 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="[null]" note_updated_at="[null]" note_user_login="[null]" note_data="[null]"/> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/insert_parameter-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/insert_parameter-result.xml new file mode 100644 index 00000000000..ed2e17d48d3 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/insert_parameter-result.xml @@ -0,0 +1,5 @@ +<dataset> + + <active_rule_parameters id="1" active_rule_id="1" rules_parameter_id="1" rules_parameter_key="max" value="20"/> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/shared.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/shared.xml new file mode 100644 index 00000000000..768b91b2046 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/shared.xml @@ -0,0 +1,24 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="2" inheritance="INHERITED" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="some note"/> + + <!-- Parent of Active rule 1 --> + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/> + + <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]"/> + + <rules_profiles id="2" name="Parent" language="java" parent_name="[null]" version="1" + used_profile="[false]"/> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/update-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/update-result.xml new file mode 100644 index 00000000000..e0c60d70e89 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/update-result.xml @@ -0,0 +1,12 @@ +<dataset> + + <active_rules id="1" profile_id="1" rule_id="10" failure_level="4" inheritance="[null]" + note_created_at="[null]" note_updated_at="[null]" note_user_login="[null]" note_data="text"/> + + <active_rules id="2" profile_id="2" rule_id="10" failure_level="0" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="john" note_data="other note"/> + + <active_rules id="3" profile_id="2" rule_id="11" failure_level="1" inheritance="[null]" + note_created_at="2013-12-18" note_updated_at="2013-12-18" note_user_login="henry" note_data="other note"/> + +</dataset> diff --git a/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/update_parameter-result.xml b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/update_parameter-result.xml new file mode 100644 index 00000000000..289da2f39f2 --- /dev/null +++ b/sonar-server/src/test/resources/org/sonar/server/rule2/ActiveRuleDaoTest/update_parameter-result.xml @@ -0,0 +1,8 @@ +<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> |