@@ -56,7 +56,7 @@ public class ComponentDao extends BaseDao<ComponentMapper, ComponentDto, String> | |||
} | |||
@Override | |||
protected ComponentDto doGetByKey(DbSession session, String key) { | |||
protected ComponentDto doGetNullableByKey(DbSession session, String key) { | |||
return getMapper(session).selectByKey(key); | |||
} | |||
@@ -105,7 +105,7 @@ public class ComponentAppAction implements RequestHandler { | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
ComponentDto component = dbClient.componentDao().getByKey(session, fileKey); | |||
ComponentDto component = dbClient.componentDao().getNullableByKey(session, fileKey); | |||
if (component == null) { | |||
throw new NotFoundException(String.format("Component '%s' does not exists.", fileKey)); | |||
} |
@@ -31,6 +31,7 @@ import org.sonar.server.search.action.EmbeddedIndexAction; | |||
import org.sonar.server.search.action.IndexAction; | |||
import org.sonar.server.search.action.KeyIndexAction; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import java.io.Serializable; | |||
import java.util.Collection; | |||
@@ -52,7 +53,7 @@ import java.util.Date; | |||
* - DTO is fully loaded (no field will return null) | |||
* - returns null (and not empty) | |||
* - examples: | |||
* - RuleDto = ruleDao.getByKey(dto.getKey()); | |||
* - RuleDto = ruleDao.getNullableByKey(dto.getKey()); | |||
* <p/> | |||
* * FIND Methods | |||
* - returns a List of DTO. | |||
@@ -128,7 +129,8 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
return indexDefinition != null ? this.indexDefinition.getIndexType() : null; | |||
} | |||
protected abstract E doGetByKey(DbSession session, K key); | |||
@CheckForNull | |||
protected abstract E doGetNullableByKey(DbSession session, K key); | |||
protected abstract E doInsert(DbSession session, E item); | |||
@@ -140,12 +142,12 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
return session.getMapper(mapperClass); | |||
} | |||
public E getByKey(DbSession session, K key) { | |||
return doGetByKey(session, key); | |||
public E getNullableByKey(DbSession session, K key) { | |||
return doGetNullableByKey(session, key); | |||
} | |||
public E getNonNullByKey(DbSession session, K key) { | |||
E value = doGetByKey(session, key); | |||
public E getByKey(DbSession session, K key) { | |||
E value = doGetNullableByKey(session, key); | |||
if (value == null) { | |||
throw new NotFoundException(String.format("Key '%s' not found", key)); | |||
} | |||
@@ -153,51 +155,83 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
} | |||
@Override | |||
public void update(DbSession session, E... item) { | |||
for(E _item:item) { | |||
_item.setUpdatedAt(new Date(system2.now())); | |||
doUpdate(session, _item); | |||
if (hasIndex()) { | |||
session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, _item)); | |||
} | |||
public E update(DbSession session, E item) { | |||
Date now = new Date(system2.now()); | |||
update(session, item, now); | |||
return item; | |||
} | |||
@Override | |||
public E update(DbSession session, E item, E... others) { | |||
Date now = new Date(system2.now()); | |||
update(session, item, now); | |||
for (E other : others) { | |||
update(session, other, now); | |||
} | |||
return item; | |||
} | |||
@Override | |||
public Collection<E> update(DbSession session, Collection<E> items) { | |||
//TODO check for bulk inserts | |||
Date now = new Date(system2.now()); | |||
for (E item : items) { | |||
update(session, item); | |||
update(session, item, now); | |||
} | |||
return items; | |||
} | |||
@Override | |||
public void insert(DbSession session, E... item) { | |||
for(E _item:item) { | |||
Date now = new Date(system2.now()); | |||
_item.setCreatedAt(now); | |||
_item.setUpdatedAt(now); | |||
doInsert(session, _item); | |||
if (hasIndex()) { | |||
session.enqueue(new DtoIndexAction<E>(this.getIndexType(), IndexAction.Method.UPSERT, _item)); | |||
} | |||
private void update(DbSession session, E item, Date now) { | |||
item.setUpdatedAt(now); | |||
doUpdate(session, item); | |||
if (hasIndex()) { | |||
session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); | |||
} | |||
} | |||
@Override | |||
public E insert(DbSession session, E item) { | |||
insert(session, item, new Date(system2.now())); | |||
return item; | |||
} | |||
@Override | |||
public Collection<E> insert(DbSession session, Collection<E> items) { | |||
Date now = new Date(system2.now()); | |||
for (E item : items) { | |||
insert(session, item); | |||
insert(session, item, now); | |||
} | |||
return items; | |||
} | |||
@Override | |||
public void delete(DbSession session, E... item) { | |||
for(E _item:item) { | |||
Preconditions.checkNotNull(_item.getKey(), "Dto does not have a valid Key"); | |||
deleteByKey(session, _item.getKey()); | |||
public E insert(DbSession session, E item, E... others) { | |||
Date now = new Date(system2.now()); | |||
insert(session, item, now); | |||
for (E other : others) { | |||
insert(session, other, now); | |||
} | |||
return item; | |||
} | |||
private void insert(DbSession session, E item, Date now) { | |||
item.setCreatedAt(now); | |||
item.setUpdatedAt(now); | |||
doInsert(session, item); | |||
if (hasIndex()) { | |||
session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); | |||
} | |||
} | |||
@Override | |||
public void delete(DbSession session, E item) { | |||
deleteByKey(session, item.getKey()); | |||
} | |||
@Override | |||
public void delete(DbSession session, E item, E... others) { | |||
delete(session, item); | |||
for (E e : others) { | |||
delete(session, e); | |||
} | |||
} | |||
@@ -210,7 +244,7 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
@Override | |||
public void deleteByKey(DbSession session, K key) { | |||
Preconditions.checkNotNull(key, "Cannot delete item with null key"); | |||
Preconditions.checkNotNull(key, "Missing key"); | |||
doDeleteByKey(session, key); | |||
if (hasIndex()) { | |||
session.enqueue(new KeyIndexAction<K>(getIndexType(), IndexAction.Method.DELETE, key)); |
@@ -29,22 +29,51 @@ import java.util.Collection; | |||
public interface Dao<E extends Dto<K>, K extends Serializable> extends ServerComponent { | |||
/** | |||
* Get a DTO by its key. Return <code>null</code> if the key does not exist. | |||
*/ | |||
@CheckForNull | |||
E getNullableByKey(DbSession session, K key); | |||
/** | |||
* Get a DTO by its key. | |||
* | |||
* @throws org.sonar.server.exceptions.NotFoundException if the key does not exist | |||
*/ | |||
E getByKey(DbSession session, K key); | |||
E getNonNullByKey(DbSession session, K key); | |||
/** | |||
* Update a table row. DTO id must be set. The field updatedAt | |||
* is changed by this method. | |||
*/ | |||
E update(DbSession session, E dto); | |||
/** | |||
* Update one or more table rows. Note that the returned DTO is only | |||
* the first updated one. | |||
*/ | |||
E update(DbSession session, E dto, E... others); | |||
Collection<E> update(DbSession session, Collection<E> dtos); | |||
void update(DbSession session, E... item); | |||
E insert(DbSession session, E dto); | |||
Collection<E> update(DbSession session, Collection<E> items); | |||
/** | |||
* Insert one or more database rows. Note | |||
* that the returned DTO is only the first inserted one. | |||
*/ | |||
E insert(DbSession session, E dto, E... others); | |||
void insert(DbSession session, E... item); | |||
Collection<E> insert(DbSession session, Collection<E> dtos); | |||
Collection<E> insert(DbSession session, Collection<E> items); | |||
void delete(DbSession session, E dto); | |||
void delete(DbSession session, E... item); | |||
/** | |||
* Delete one or more table rows. | |||
*/ | |||
void delete(DbSession session, E dto, E... others); | |||
void delete(DbSession session, Collection<E> items); | |||
void delete(DbSession session, Collection<E> dtos); | |||
void deleteByKey(DbSession session, K key); | |||
@@ -214,7 +214,7 @@ public class DebtModelOperations implements ServerComponent { | |||
private void disableSubCharacteristic(CharacteristicDto subCharacteristic, Date updateDate, DbSession session) { | |||
// Disable debt on all rules (even REMOVED ones, in order to have no issue if they are reactivated) linked to the sub characteristic | |||
disableRulesDebt(dbClient.ruleDao().findRulesByDebtSubCharacteristicId(subCharacteristic.getId(), session), subCharacteristic.getId(), updateDate, session); | |||
disableRulesDebt(dbClient.ruleDao().findRulesByDebtSubCharacteristicId(session, subCharacteristic.getId()), subCharacteristic.getId(), updateDate, session); | |||
disableCharacteristic(subCharacteristic, updateDate, session); | |||
} | |||
@@ -85,7 +85,7 @@ public class DuplicationsParser implements ServerComponent { | |||
private Duplication createDuplication(Map<String, ComponentDto> componentsByKey, String from, String size, String componentKey, DbSession session) { | |||
ComponentDto component = componentsByKey.get(componentKey); | |||
if (component == null) { | |||
component = componentDao.getByKey(session, componentKey); | |||
component = componentDao.getNullableByKey(session, componentKey); | |||
componentsByKey.put(componentKey, component); | |||
} | |||
return new Duplication(component, Integer.valueOf(from), Integer.valueOf(size)); |
@@ -82,7 +82,7 @@ public class DuplicationsWriter implements ServerComponent { | |||
for (Map.Entry<String, String> entry : refByComponentKey.entrySet()) { | |||
String componentKey = entry.getKey(); | |||
String ref = entry.getValue(); | |||
ComponentDto file = componentDao.getByKey(session, componentKey); | |||
ComponentDto file = componentDao.getNullableByKey(session, componentKey); | |||
if (file != null) { | |||
json.name(ref).beginObject(); | |||
json.prop("key", file.key()); |
@@ -93,7 +93,7 @@ public class ShowAction implements RequestHandler { | |||
@CheckForNull | |||
private String findDataFromComponent(String fileKey, String metricKey, DbSession session) { | |||
MeasureDto data = measureDao.getByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
MeasureDto data = measureDao.getNullableByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
if (data != null) { | |||
return data.getData(); | |||
} | |||
@@ -101,7 +101,7 @@ public class ShowAction implements RequestHandler { | |||
} | |||
private ComponentDto findComponent(String key, DbSession session) { | |||
ComponentDto componentDto = componentDao.getByKey(session, key); | |||
ComponentDto componentDto = componentDao.getNullableByKey(session, key); | |||
if (componentDto == null) { | |||
throw new NotFoundException(String.format("Component with key '%s' not found", key)); | |||
} |
@@ -48,7 +48,7 @@ public class MeasureDao extends BaseDao<MeasureMapper, MeasureDto, MeasureKey> i | |||
} | |||
@Override | |||
protected MeasureDto doGetByKey(DbSession session, MeasureKey key) { | |||
protected MeasureDto doGetNullableByKey(DbSession session, MeasureKey key) { | |||
return session.getMapper(MeasureMapper.class).selectByKey(key); | |||
} | |||
@@ -58,20 +58,20 @@ public class QProfileActiveRuleOperations implements ServerComponent { | |||
} | |||
ActiveRuleDto createActiveRule(QualityProfileKey profileKey, RuleKey ruleKey, String severity, DbSession session) { | |||
RuleDto ruleDto = ruleDao.getByKey(session, ruleKey); | |||
RuleDto ruleDto = ruleDao.getNullableByKey(session, ruleKey); | |||
QualityProfileDto profileDto = profileDao.selectByNameAndLanguage(profileKey.name(), profileKey.lang(), session); | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) | |||
.setSeverity(severity); | |||
activeRuleDao.insert(session, activeRule); | |||
List<RuleParamDto> ruleParams = ruleDao.findRuleParamsByRuleKey(ruleKey, session); | |||
List<RuleParamDto> ruleParams = ruleDao.findRuleParamsByRuleKey(session, ruleKey); | |||
List<ActiveRuleParamDto> activeRuleParams = newArrayList(); | |||
for (RuleParamDto ruleParam : ruleParams) { | |||
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(ruleParam) | |||
.setKey(ruleParam.getName()) | |||
.setValue(ruleParam.getDefaultValue()); | |||
activeRuleParams.add(activeRuleParam); | |||
activeRuleDao.addParam(activeRule, activeRuleParam, session); | |||
activeRuleDao.addParam(session, activeRule, activeRuleParam); | |||
} | |||
return activeRule; | |||
} | |||
@@ -82,7 +82,7 @@ public class QProfileActiveRuleOperations implements ServerComponent { | |||
validateParam(ruleParam, sanitizedValue); | |||
activeRuleParam.setValue(sanitizedValue); | |||
activeRuleDao.updateParam(activeRule, activeRuleParam, session); | |||
activeRuleDao.updateParam(session, activeRule, activeRuleParam); | |||
} | |||
@@ -98,8 +98,8 @@ public class QProfileActiveRuleOperations implements ServerComponent { | |||
private RuleParamDto findRuleParamNotNull(Integer ruleId, String key, DbSession session) { | |||
RuleDto rule = ruleDao.getById(ruleId, session); | |||
RuleParamDto ruleParam = ruleDao.getRuleParamByRuleAndParamKey(rule, key, session); | |||
RuleDto rule = ruleDao.getById(session, ruleId); | |||
RuleParamDto ruleParam = ruleDao.getRuleParamByRuleAndParamKey(session, rule, key); | |||
if (ruleParam == null) { | |||
throw new IllegalArgumentException("No rule param found"); | |||
} | |||
@@ -108,8 +108,8 @@ public class QProfileActiveRuleOperations implements ServerComponent { | |||
@CheckForNull | |||
private ActiveRuleParamDto findActiveRuleParam(int activeRuleId, String key, DbSession session) { | |||
ActiveRuleDto activeRule = activeRuleDao.getById(activeRuleId, session); | |||
return activeRuleDao.getParamsByActiveRuleAndKey(activeRule, key, session); | |||
ActiveRuleDto activeRule = activeRuleDao.getById(session, activeRuleId); | |||
return activeRuleDao.getParamsByActiveRuleAndKey(session, activeRule, key); | |||
} | |||
private ActiveRuleParamDto findActiveRuleParamNotNull(int activeRuleId, String key, DbSession session) { |
@@ -178,7 +178,7 @@ public class QProfileBackup implements ServerComponent { | |||
public void restoreFromActiveRules(QualityProfileKey profileKey, RulesProfile rulesProfile, DbSession session) { | |||
for (org.sonar.api.rules.ActiveRule activeRule : rulesProfile.getActiveRules()) { | |||
RuleKey ruleKey = RuleKey.of(activeRule.getRepositoryKey(), activeRule.getRuleKey()); | |||
RuleDto rule = ruleDao.getByKey(session, ruleKey); | |||
RuleDto rule = ruleDao.getNullableByKey(session, ruleKey); | |||
if (rule == null) { | |||
throw new NotFoundException(String.format("Rule '%s' does not exists.", ruleKey)); | |||
} |
@@ -145,8 +145,8 @@ public class QProfileOperations implements ServerComponent { | |||
* Delete profile without checking permission or that profile is existing or that profile can be deleted (is not defined as default, has no children, etc.) | |||
*/ | |||
public void deleteProfile(QProfile profile, DbSession session) { | |||
activeRuleDao.removeParamByProfile(profile, session); | |||
activeRuleDao.deleteByProfile(profile, session); | |||
activeRuleDao.removeParamByProfile(session, profile); | |||
activeRuleDao.deleteByProfile(session, profile); | |||
dao.delete(profile.id(), session); | |||
propertiesDao.deleteProjectProperties(PROFILE_PROPERTY_PREFIX + profile.language(), profile.name(), session); | |||
//esActiveRule.deleteActiveRulesFromProfile(profile.id()); |
@@ -150,7 +150,7 @@ public class RegisterQualityProfiles implements ServerComponent { | |||
} | |||
private void cleanUp(QualityProfileKey key, QualityProfileDto profileDto, DbSession session) { | |||
dbClient.activeRuleDao().deleteByProfileKey(key, session); | |||
dbClient.activeRuleDao().deleteByProfileKey(session, key); | |||
dbClient.qualityProfileDao().delete(session, profileDto); | |||
session.commit(); | |||
} |
@@ -63,7 +63,7 @@ public class RuleActivationContextFactory implements ServerComponent { | |||
} | |||
private RuleDto initRule(RuleKey ruleKey, RuleActivationContext context, DbSession dbSession) { | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, ruleKey); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, ruleKey); | |||
if (rule == null) { | |||
throw new IllegalArgumentException("Rule not found: " + ruleKey); | |||
} | |||
@@ -74,7 +74,7 @@ public class RuleActivationContextFactory implements ServerComponent { | |||
throw new IllegalArgumentException("A rule template can't be activated on a Quality profile: " + ruleKey); | |||
} | |||
context.setRule(rule); | |||
context.setRuleParams(db.ruleDao().findRuleParamsByRuleKey(rule.getKey(), dbSession)); | |||
context.setRuleParams(db.ruleDao().findRuleParamsByRuleKey(dbSession, rule.getKey())); | |||
return rule; | |||
} | |||
@@ -93,10 +93,10 @@ public class RuleActivationContextFactory implements ServerComponent { | |||
} | |||
private void initActiveRules(ActiveRuleKey key, RuleActivationContext context, DbSession session, boolean parent) { | |||
ActiveRuleDto activeRule = db.activeRuleDao().getByKey(session, key); | |||
ActiveRuleDto activeRule = db.activeRuleDao().getNullableByKey(session, key); | |||
Collection<ActiveRuleParamDto> activeRuleParams = null; | |||
if (activeRule != null) { | |||
activeRuleParams = db.activeRuleDao().findParamsByActiveRule(activeRule, session); | |||
activeRuleParams = db.activeRuleDao().findParamsByActiveRule(session, activeRule); | |||
} | |||
if (parent) { | |||
context.setParentActiveRule(activeRule); |
@@ -128,7 +128,7 @@ public class RuleActivator implements ServerComponent { | |||
for (Map.Entry<String, String> param : change.getParameters().entrySet()) { | |||
ActiveRuleParamDto paramDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey())); | |||
paramDto.setValue(param.getValue()); | |||
dao.addParam(activeRule, paramDto, dbSession); | |||
dao.addParam(dbSession, activeRule, paramDto); | |||
} | |||
} else if (change.getType() == ActiveRuleChange.Type.DEACTIVATED) { | |||
@@ -145,10 +145,10 @@ public class RuleActivator implements ServerComponent { | |||
// did not exist | |||
activeRuleParamDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey())); | |||
activeRuleParamDto.setValue(param.getValue()); | |||
dao.addParam(activeRule, activeRuleParamDto, dbSession); | |||
dao.addParam(dbSession, activeRule, activeRuleParamDto); | |||
} else { | |||
activeRuleParamDto.setValue(param.getValue()); | |||
dao.updateParam(activeRule, activeRuleParamDto, dbSession); | |||
dao.updateParam(dbSession, activeRule, activeRuleParamDto); | |||
} | |||
} | |||
for (ActiveRuleParamDto activeRuleParamDto : context.activeRuleParams()) { |
@@ -103,8 +103,8 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu | |||
DbSession dbSession = db.openSession(false); | |||
List<UpdateRequest> requests = new ArrayList<UpdateRequest>(); | |||
try { | |||
requests.addAll(normalize(db.activeRuleDao().getByKey(dbSession, key))); | |||
for (ActiveRuleParamDto param : db.activeRuleDao().findParamsByKey(key, dbSession)) { | |||
requests.addAll(normalize(db.activeRuleDao().getNullableByKey(dbSession, key))); | |||
for (ActiveRuleParamDto param : db.activeRuleDao().findParamsByKey(dbSession, key)) { | |||
requests.addAll(this.normalize(param, key)); | |||
} | |||
} finally { | |||
@@ -149,7 +149,7 @@ public class ActiveRuleNormalizer extends BaseNormalizer<ActiveRuleDto, ActiveRu | |||
String parentKey = null; | |||
if (activeRuleDto.getParentId() != null) { | |||
ActiveRuleDto parentDto = db.activeRuleDao().getById(activeRuleDto.getParentId(), session); | |||
ActiveRuleDto parentDto = db.activeRuleDao().getById(session, activeRuleDto.getParentId()); | |||
parentKey = parentDto.getKey().toString(); | |||
} | |||
newRule.put(ActiveRuleField.PARENT_KEY.field(), parentKey); |
@@ -41,6 +41,7 @@ import org.sonar.server.search.IndexDefinition; | |||
import org.sonar.server.search.action.IndexAction; | |||
import org.sonar.server.search.action.KeyIndexAction; | |||
import javax.annotation.CheckForNull; | |||
import java.sql.Timestamp; | |||
import java.util.List; | |||
import java.util.Map; | |||
@@ -81,19 +82,21 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
/** | |||
* @deprecated do not use ids but keys | |||
*/ | |||
@CheckForNull | |||
@Deprecated | |||
public ActiveRuleDto getById(int activeRuleId, DbSession session) { | |||
ActiveRuleDto rule = mapper(session).selectById(activeRuleId); | |||
public ActiveRuleDto getById(DbSession session, int activeRuleId) { | |||
ActiveRuleDto activeRule = mapper(session).selectById(activeRuleId); | |||
rule.setKey(ActiveRuleKey.of( | |||
profileDao.selectById(rule.getProfileId(), session).getKey(), | |||
ruleDao.getById(rule.getRulId(), session).getKey())); | |||
return rule; | |||
if (activeRule != null) { | |||
activeRule.setKey(ActiveRuleKey.of( | |||
profileDao.selectById(activeRule.getProfileId(), session).getKey(), | |||
ruleDao.getById(session, activeRule.getRulId()).getKey())); | |||
} | |||
return activeRule; | |||
} | |||
@Override | |||
protected ActiveRuleDto doGetByKey(DbSession session, ActiveRuleKey key) { | |||
protected ActiveRuleDto doGetNullableByKey(DbSession session, ActiveRuleKey key) { | |||
return mapper(session).selectByKey(key.qProfile().name(), key.qProfile().lang(), | |||
key.ruleKey().repository(), key.ruleKey().rule()); | |||
} | |||
@@ -118,7 +121,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
@Override | |||
protected void doDeleteByKey(DbSession session, ActiveRuleKey key) { | |||
ActiveRuleDto rule = this.getByKey(session, key); | |||
ActiveRuleDto rule = this.getNullableByKey(session, key); | |||
mapper(session).deleteParameters(rule.getId()); | |||
mapper(session).delete(rule.getId()); | |||
} | |||
@@ -127,8 +130,8 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
* Finder methods for Rules | |||
*/ | |||
public List<ActiveRuleDto> findByRule(RuleDto rule, DbSession dbSession) { | |||
Preconditions.checkArgument(rule.getId() != null, "Rule is not persisted"); | |||
public List<ActiveRuleDto> findByRule(DbSession dbSession, RuleDto rule) { | |||
Preconditions.checkNotNull(rule.getId(), "Rule is not persisted"); | |||
return mapper(dbSession).selectByRuleId(rule.getId()); | |||
} | |||
@@ -136,10 +139,10 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
* Nested DTO ActiveRuleParams | |||
*/ | |||
public ActiveRuleParamDto addParam(ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam, DbSession session) { | |||
Preconditions.checkState(activeRule.getId() != null, "ActiveRule id is not yet persisted"); | |||
Preconditions.checkState(activeRuleParam.getId() == null, "ActiveRuleParam is already persisted"); | |||
Preconditions.checkState(activeRuleParam.getRulesParameterId() != null, "Rule param is not persisted"); | |||
public ActiveRuleParamDto addParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { | |||
Preconditions.checkNotNull(activeRule.getId(), "ActiveRule id is not yet persisted"); | |||
Preconditions.checkArgument(activeRuleParam.getId() == null, "ActiveRuleParam is already persisted"); | |||
Preconditions.checkNotNull(activeRuleParam.getRulesParameterId(), "Rule param is not persisted"); | |||
activeRuleParam.setActiveRuleId(activeRule.getId()); | |||
mapper(session).insertParameter(activeRuleParam); | |||
@@ -147,62 +150,46 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
return activeRuleParam; | |||
} | |||
public void removeAllParam(ActiveRuleDto activeRule, DbSession session) { | |||
Preconditions.checkArgument(activeRule.getId() != null, "ActiveRule is not persisted"); | |||
//TODO Optimize this | |||
for (ActiveRuleParamDto activeRuleParam : this.findParamsByActiveRule(activeRule, session)) { | |||
this.enqueueDelete(activeRuleParam, activeRule.getKey(), session); | |||
} | |||
mapper(session).deleteParameters(activeRule.getId()); | |||
} | |||
public void removeParam(ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam, DbSession session) { | |||
Preconditions.checkArgument(activeRule.getId() != null, "ActiveRule is not persisted"); | |||
Preconditions.checkArgument(activeRuleParam.getId() != null, "ActiveRuleParam is not persisted"); | |||
mapper(session).deleteParameter(activeRuleParam.getId()); | |||
this.enqueueDelete(activeRuleParam, activeRule.getKey(), session); | |||
} | |||
public void removeParamByKeyAndName(ActiveRuleKey key, String param, DbSession session) { | |||
public void removeParamByKeyAndName(DbSession session, ActiveRuleKey key, String param) { | |||
//TODO SQL rewrite to delete by key | |||
ActiveRuleDto activeRule = this.getByKey(session, key); | |||
ActiveRuleDto activeRule = getNullableByKey(session, key); | |||
ActiveRuleParamDto activeRuleParam = mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), param); | |||
Preconditions.checkArgument(activeRuleParam.getId() != null, "ActiveRuleParam does not exist"); | |||
Preconditions.checkNotNull(activeRuleParam.getId(), "ActiveRuleParam does not exist"); | |||
mapper(session).deleteParameter(activeRuleParam.getId()); | |||
} | |||
public void updateParam(ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam, DbSession session) { | |||
Preconditions.checkArgument(activeRule.getId() != null, "ActiveRule is not persisted"); | |||
Preconditions.checkArgument(activeRuleParam.getId() != null, "ActiveRuleParam is not persisted"); | |||
public void updateParam(DbSession session, ActiveRuleDto activeRule, ActiveRuleParamDto activeRuleParam) { | |||
Preconditions.checkNotNull(activeRule.getId(), "ActiveRule is not persisted"); | |||
Preconditions.checkNotNull(activeRuleParam.getId(), "ActiveRuleParam is not persisted"); | |||
mapper(session).updateParameter(activeRuleParam); | |||
this.enqueueUpdate(activeRuleParam, activeRule.getKey(), session); | |||
} | |||
public ActiveRuleParamDto getParamsByActiveRuleAndKey(ActiveRuleDto activeRule, String key, DbSession session) { | |||
Preconditions.checkArgument(activeRule.getId() != null, "ActiveRule is not persisted"); | |||
Preconditions.checkArgument(key != null, "Param key cannot be null"); | |||
public ActiveRuleParamDto getParamsByActiveRuleAndKey(DbSession session, ActiveRuleDto activeRule, String key) { | |||
Preconditions.checkNotNull(activeRule.getId(), "ActiveRule is not persisted"); | |||
Preconditions.checkNotNull(key, "Param key cannot be null"); | |||
return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), key); | |||
} | |||
public void deleteByProfileKey(QualityProfileKey profileKey, DbSession session) { | |||
public void deleteByProfileKey(DbSession session, QualityProfileKey profileKey) { | |||
/** Functional cascade for params */ | |||
for (ActiveRuleDto activeRule : this.findByProfileKey(profileKey, session)) { | |||
for (ActiveRuleDto activeRule : this.findByProfileKey(session, profileKey)) { | |||
delete(session, activeRule); | |||
} | |||
} | |||
public List<ActiveRuleDto> findByProfileKey(QualityProfileKey profileKey, DbSession session) { | |||
public List<ActiveRuleDto> findByProfileKey(DbSession session, QualityProfileKey profileKey) { | |||
return mapper(session).selectByProfileKey(profileKey); | |||
} | |||
public void removeParamByProfileKey(QualityProfileKey profileKey, DbSession session) { | |||
int id = this.getQualityProfileId(profileKey, session); | |||
public void removeParamByProfileKey(DbSession session, QualityProfileKey profileKey) { | |||
int id = this.getQualityProfileId(session, profileKey); | |||
mapper(session).deleteParametersFromProfile(id); | |||
} | |||
@Deprecated | |||
//TODO Needed until SQL rewrite with KEY fields. | |||
private int getQualityProfileId(QualityProfileKey profileKey, DbSession session) { | |||
private int getQualityProfileId(DbSession session, QualityProfileKey profileKey) { | |||
return profileDao.selectByNameAndLanguage(profileKey.name(), profileKey.lang(), session).getId(); | |||
} | |||
@@ -210,32 +197,32 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
* Finder methods for ActiveRuleParams | |||
*/ | |||
public List<ActiveRuleParamDto> findParamsByKey(ActiveRuleKey key, DbSession session) { | |||
Preconditions.checkArgument(key != null, "ActiveRuleKey cannot be null"); | |||
ActiveRuleDto activeRule = this.getByKey(session, key); | |||
public List<ActiveRuleParamDto> findParamsByKey(DbSession session, ActiveRuleKey key) { | |||
Preconditions.checkNotNull(key, "ActiveRuleKey cannot be null"); | |||
ActiveRuleDto activeRule = getNullableByKey(session, key); | |||
return mapper(session).selectParamsByActiveRuleId(activeRule.getId()); | |||
} | |||
public ActiveRuleParamDto getParamsByKeyAndName(ActiveRuleKey key, String name, DbSession session) { | |||
Preconditions.checkArgument(key != null, "ActiveRuleKey cannot be null"); | |||
Preconditions.checkArgument(name != null, "ParameterName cannot be null"); | |||
ActiveRuleDto activeRule = this.getByKey(session, key); | |||
Preconditions.checkNotNull(key, "ActiveRuleKey cannot be null"); | |||
Preconditions.checkNotNull(name, "ParameterName cannot be null"); | |||
ActiveRuleDto activeRule = getNullableByKey(session, key); | |||
return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), name); | |||
} | |||
public List<ActiveRuleParamDto> findParamsByActiveRule(ActiveRuleDto dto, DbSession session) { | |||
Preconditions.checkArgument(dto.getId() != null, "ActiveRule is not persisted"); | |||
public List<ActiveRuleParamDto> findParamsByActiveRule(DbSession session, ActiveRuleDto dto) { | |||
Preconditions.checkNotNull(dto.getId(), "ActiveRule is not persisted"); | |||
return mapper(session).selectParamsByActiveRuleId(dto.getId()); | |||
} | |||
@Deprecated | |||
public void removeParamByProfile(QProfile profile, DbSession session) { | |||
public void removeParamByProfile(DbSession session, QProfile profile) { | |||
mapper(session).deleteParametersFromProfile(profile.id()); | |||
} | |||
@Deprecated | |||
public void deleteByProfile(QProfile profile, DbSession session) { | |||
public void deleteByProfile(DbSession session, QProfile profile) { | |||
mapper(session).deleteFromProfile(profile.id()); | |||
} | |||
} |
@@ -268,7 +268,7 @@ public class RegisterRules implements Startable { | |||
} | |||
private void mergeParams(RulesDefinition.Rule ruleDef, RuleDto rule, DbSession session) { | |||
List<RuleParamDto> paramDtos = dbClient.ruleDao().findRuleParamsByRuleKey(rule.getKey(), session); | |||
List<RuleParamDto> paramDtos = dbClient.ruleDao().findRuleParamsByRuleKey(session, rule.getKey()); | |||
List<String> existingParamDtoNames = new ArrayList<String>(); | |||
for (RuleParamDto paramDto : paramDtos) { | |||
@@ -276,12 +276,12 @@ public class RegisterRules implements Startable { | |||
if (paramDef == null) { | |||
//TODO cascade on the activeRule upon RuleDeletion | |||
//activeRuleDao.removeRuleParam(paramDto, sqlSession); | |||
dbClient.ruleDao().removeRuleParam(rule, paramDto, session); | |||
dbClient.ruleDao().removeRuleParam(session, rule, paramDto); | |||
} else { | |||
// TODO validate that existing active rules still match constraints | |||
// TODO store param name | |||
if (mergeParam(paramDto, paramDef)) { | |||
dbClient.ruleDao().updateRuleParam(rule, paramDto, session); | |||
dbClient.ruleDao().updateRuleParam(session, rule, paramDto); | |||
} else { | |||
// TODO to be replaced by synchronizer | |||
session.enqueue(new EmbeddedIndexAction<RuleKey>(IndexDefinition.RULE.getIndexType(), | |||
@@ -297,7 +297,7 @@ public class RegisterRules implements Startable { | |||
.setDescription(param.description()) | |||
.setDefaultValue(param.defaultValue()) | |||
.setType(param.type().toString()); | |||
dbClient.ruleDao().addRuleParam(rule, paramDto, session); | |||
dbClient.ruleDao().addRuleParam(session, rule, paramDto); | |||
} | |||
} | |||
} |
@@ -66,7 +66,7 @@ public class RuleOperations implements ServerComponent { | |||
checkPermission(userSession); | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
RuleDto ruleDto = dbClient.ruleDao().getByKey(session, ruleChange.ruleKey()); | |||
RuleDto ruleDto = dbClient.ruleDao().getNullableByKey(session, ruleChange.ruleKey()); | |||
if (ruleDto == null) { | |||
throw new NotFoundException(String.format("Unknown rule '%s'", ruleChange.ruleKey())); | |||
} |
@@ -75,7 +75,7 @@ public class RuleUpdater implements ServerComponent { | |||
DbSession dbSession = dbClient.openSession(false); | |||
try { | |||
Context context = new Context(); | |||
context.rule = dbClient.ruleDao().getNonNullByKey(dbSession, change.getRuleKey()); | |||
context.rule = dbClient.ruleDao().getByKey(dbSession, change.getRuleKey()); | |||
if (RuleStatus.REMOVED == context.rule.getStatus()) { | |||
throw new IllegalArgumentException("Rule with REMOVED status cannot be updated: " + change.getRuleKey()); | |||
} |
@@ -51,9 +51,8 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
super(IndexDefinition.RULE, RuleMapper.class, system); | |||
} | |||
@CheckForNull | |||
@Override | |||
public RuleDto doGetByKey(DbSession session, RuleKey key) { | |||
public RuleDto doGetNullableByKey(DbSession session, RuleKey key) { | |||
return mapper(session).selectByKey(key); | |||
} | |||
@@ -79,11 +78,11 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
} | |||
/** | |||
* @deprecated in 4.4. Use keys. | |||
* @deprecated use keys. | |||
*/ | |||
@CheckForNull | |||
@Deprecated | |||
public RuleDto getById(int id, DbSession session) { | |||
public RuleDto getById(DbSession session, int id) { | |||
return mapper(session).selectById(id); | |||
} | |||
@@ -126,26 +125,26 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
* Nested DTO RuleParams | |||
*/ | |||
public void addRuleParam(RuleDto rule, RuleParamDto ruleParam, DbSession session) { | |||
public void addRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { | |||
Preconditions.checkNotNull(rule.getId(), "Rule id must be set"); | |||
ruleParam.setRuleId(rule.getId()); | |||
mapper(session).insertParameter(ruleParam); | |||
this.enqueueInsert(ruleParam, rule.getKey(), session); | |||
param.setRuleId(rule.getId()); | |||
mapper(session).insertParameter(param); | |||
this.enqueueInsert(param, rule.getKey(), session); | |||
} | |||
public RuleParamDto updateRuleParam(RuleDto rule, RuleParamDto ruleParam, DbSession session) { | |||
public RuleParamDto updateRuleParam(DbSession session, RuleDto rule, RuleParamDto param) { | |||
Preconditions.checkNotNull(rule.getId(), "Rule id must be set"); | |||
Preconditions.checkNotNull(ruleParam.getId(), "Param is not yet persisted must be set"); | |||
ruleParam.setRuleId(rule.getId()); | |||
mapper(session).updateParameter(ruleParam); | |||
this.enqueueUpdate(ruleParam, rule.getKey(), session); | |||
return ruleParam; | |||
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 removeRuleParam(RuleDto rule, RuleParamDto ruleParam, DbSession session) { | |||
Preconditions.checkNotNull(ruleParam.getId(), "Param is not persisted"); | |||
mapper(session).deleteParameter(ruleParam.getId()); | |||
this.enqueueDelete(ruleParam, rule.getKey(), session); | |||
public void removeRuleParam(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); | |||
} | |||
/** | |||
@@ -156,24 +155,24 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
return mapper(session).selectAllParams(); | |||
} | |||
public List<RuleParamDto> findRuleParamsByRuleKey(RuleKey key, DbSession session) { | |||
public List<RuleParamDto> findRuleParamsByRuleKey(DbSession session, RuleKey key) { | |||
return mapper(session).selectParamsByRuleKey(key); | |||
} | |||
public List<RuleParamDto> findRuleParamsByRules(List<RuleDto> ruleDtos, DbSession session) { | |||
public List<RuleParamDto> findRuleParamsByRules(DbSession session, List<RuleDto> ruleDtos) { | |||
List<RuleParamDto> ruleParamDtos = new ArrayList<RuleParamDto>(); | |||
for (RuleDto rule : ruleDtos) { | |||
ruleParamDtos.addAll(findRuleParamsByRuleKey(rule.getKey(), session)); | |||
ruleParamDtos.addAll(findRuleParamsByRuleKey(session, rule.getKey())); | |||
} | |||
return ruleParamDtos; | |||
} | |||
public RuleParamDto getRuleParamByRuleAndParamKey(RuleDto rule, String key, DbSession session) { | |||
public RuleParamDto getRuleParamByRuleAndParamKey(DbSession session, RuleDto rule, String key) { | |||
Preconditions.checkNotNull(rule.getId(), "Rule is not persisted"); | |||
return mapper(session).selectParamByRuleAndKey(rule.getId(), key); | |||
} | |||
public List<RuleDto> findRulesByDebtSubCharacteristicId(int id, DbSession session) { | |||
public List<RuleDto> findRulesByDebtSubCharacteristicId(DbSession session, int id) { | |||
return mapper(session).selectBySubCharacteristicId(id); | |||
} | |||
@@ -135,8 +135,8 @@ public class RuleNormalizer extends BaseNormalizer<RuleDto, RuleKey> { | |||
DbSession dbSession = db.openSession(false); | |||
List<UpdateRequest> requests = new ArrayList<UpdateRequest>(); | |||
try { | |||
requests.addAll(normalize(db.ruleDao().getByKey(dbSession, key))); | |||
for (RuleParamDto param : db.ruleDao().findRuleParamsByRuleKey(key, dbSession)) { | |||
requests.addAll(normalize(db.ruleDao().getNullableByKey(dbSession, key))); | |||
for (RuleParamDto param : db.ruleDao().findRuleParamsByRuleKey(dbSession, key)) { | |||
requests.addAll(normalize(param, key)); | |||
} | |||
} finally { |
@@ -98,7 +98,7 @@ public class SourceService implements ServerComponent { | |||
private String findDataFromComponent(String fileKey, String metricKey) { | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
MeasureDto data = dbClient.measureDao().getByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
MeasureDto data = dbClient.measureDao().getNullableByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
if (data != null) { | |||
return data.getData(); | |||
} |
@@ -109,7 +109,7 @@ public class CoverageService implements ServerComponent { | |||
private Map<Integer, Integer> findDataFromComponent(String fileKey, String metricKey) { | |||
DbSession session = myBatis.openSession(false); | |||
try { | |||
MeasureDto data = measureDao.getByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
MeasureDto data = measureDao.getNullableByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
if (data != null) { | |||
return KeyValueFormat.parseIntInt(data.getData()); | |||
} |
@@ -49,7 +49,7 @@ public class ComponentDaoTest extends AbstractDaoTestCase { | |||
public void get_by_key() { | |||
setupData("shared"); | |||
ComponentDto result = dao.getByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java"); | |||
ComponentDto result = dao.getNullableByKey(session, "org.struts:struts-core:src/org/struts/RequestContext.java"); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.key()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java"); | |||
assertThat(result.path()).isEqualTo("src/org/struts/RequestContext.java"); | |||
@@ -59,14 +59,14 @@ public class ComponentDaoTest extends AbstractDaoTestCase { | |||
assertThat(result.subProjectId()).isEqualTo(2); | |||
assertThat(result.projectId()).isEqualTo(1); | |||
assertThat(dao.getByKey(session, "unknown")).isNull(); | |||
assertThat(dao.getNullableByKey(session, "unknown")).isNull(); | |||
} | |||
@Test | |||
public void get_by_key_on_a_root_project() { | |||
setupData("shared"); | |||
ComponentDto result = dao.getByKey(session, "org.struts:struts"); | |||
ComponentDto result = dao.getNullableByKey(session, "org.struts:struts"); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.key()).isEqualTo("org.struts:struts"); | |||
assertThat(result.path()).isNull(); |
@@ -124,7 +124,7 @@ public class ComponentAppActionTest { | |||
ComponentDto file = new ComponentDto().setId(10L).setQualifier("FIL").setKey(COMPONENT_KEY).setName("Plugin.java") | |||
.setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(5L).setProjectId(1L); | |||
when(componentDao.getByKey(session, COMPONENT_KEY)).thenReturn(file); | |||
when(componentDao.getNullableByKey(session, COMPONENT_KEY)).thenReturn(file); | |||
when(componentDao.getById(5L, session)).thenReturn(new ComponentDto().setId(5L).setLongName("SonarQube :: Plugin API")); | |||
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube")); | |||
when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session))).thenReturn(newArrayList(new PropertyDto())); | |||
@@ -140,7 +140,7 @@ public class ComponentAppActionTest { | |||
MockUserSession.set().setLogin("john").addComponentPermission(UserRole.CODEVIEWER, componentKey, componentKey); | |||
ComponentDto file = new ComponentDto().setId(1L).setQualifier("TRK").setKey(componentKey).setName("SonarQube").setProjectId(1L); | |||
when(componentDao.getByKey(session, componentKey)).thenReturn(file); | |||
when(componentDao.getNullableByKey(session, componentKey)).thenReturn(file); | |||
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube")); | |||
when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session))).thenReturn(newArrayList(new PropertyDto())); | |||
@@ -154,7 +154,7 @@ public class ComponentAppActionTest { | |||
ComponentDto file = new ComponentDto().setId(10L).setQualifier("FIL").setKey(COMPONENT_KEY).setName("Plugin.java") | |||
.setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(1L).setProjectId(1L); | |||
when(componentDao.getByKey(session, COMPONENT_KEY)).thenReturn(file); | |||
when(componentDao.getNullableByKey(session, COMPONENT_KEY)).thenReturn(file); | |||
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube")); | |||
when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session))).thenReturn(newArrayList(new PropertyDto())); | |||
when(sourceService.hasScmData(eq(COMPONENT_KEY), eq(session))).thenReturn(true); | |||
@@ -232,7 +232,7 @@ public class ComponentAppActionTest { | |||
private void addProjectSample() { | |||
ComponentDto file = new ComponentDto().setId(10L).setQualifier("FIL").setKey(COMPONENT_KEY).setName("Plugin.java") | |||
.setPath("src/main/java/org/sonar/api/Plugin.java").setSubProjectId(5L).setProjectId(1L); | |||
when(componentDao.getByKey(session, COMPONENT_KEY)).thenReturn(file); | |||
when(componentDao.getNullableByKey(session, COMPONENT_KEY)).thenReturn(file); | |||
when(componentDao.getById(5L, session)).thenReturn(new ComponentDto().setId(5L).setLongName("SonarQube :: Plugin API")); | |||
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube")); | |||
} |
@@ -39,13 +39,13 @@ public class BaseDaoTest { | |||
public void getNonNullByKey() throws Exception { | |||
BaseDao dao = mock(BaseDao.class); | |||
FakeDto dto = new FakeDto("ki"); | |||
when(dao.doGetByKey(dbSession, "ki")).thenReturn(dto); | |||
when(dao.getNonNullByKey(any(DbSession.class), anyString())).thenCallRealMethod(); | |||
when(dao.doGetNullableByKey(dbSession, "ki")).thenReturn(dto); | |||
when(dao.getByKey(any(DbSession.class), anyString())).thenCallRealMethod(); | |||
assertThat(dao.getNonNullByKey(dbSession, "ki")).isSameAs(dto); | |||
assertThat(dao.getByKey(dbSession, "ki")).isSameAs(dto); | |||
try { | |||
dao.getNonNullByKey(dbSession, "unknown"); | |||
dao.getByKey(dbSession, "unknown"); | |||
fail(); | |||
} catch (NotFoundException e) { | |||
assertThat(e).hasMessage("Key 'unknown' not found"); |
@@ -357,7 +357,7 @@ public class DebtModelOperationsTest { | |||
DbSession batchSession = mock(DbSession.class); | |||
when(dbClient.openSession(true)).thenReturn(batchSession); | |||
when(ruleDao.findRulesByDebtSubCharacteristicId(2, batchSession)).thenReturn(newArrayList( | |||
when(ruleDao.findRulesByDebtSubCharacteristicId(batchSession, 2)).thenReturn(newArrayList( | |||
new RuleDto() | |||
.setSubCharacteristicId(2) | |||
.setRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) | |||
@@ -402,7 +402,7 @@ public class DebtModelOperationsTest { | |||
DbSession batchSession = mock(DbSession.class); | |||
when(dbClient.openSession(true)).thenReturn(batchSession); | |||
when(ruleDao.findRulesByDebtSubCharacteristicId(2, batchSession)).thenReturn(newArrayList( | |||
when(ruleDao.findRulesByDebtSubCharacteristicId(batchSession, 2)).thenReturn(newArrayList( | |||
new RuleDto() | |||
.setSubCharacteristicId(10).setRemediationFunction("LINEAR_OFFSET").setRemediationCoefficient("2h").setRemediationOffset("5min") | |||
.setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("LINEAR_OFFSET").setDefaultRemediationCoefficient("4h").setDefaultRemediationOffset("15min") | |||
@@ -440,7 +440,7 @@ public class DebtModelOperationsTest { | |||
DbSession batchSession = mock(DbSession.class); | |||
when(dbClient.openSession(true)).thenReturn(batchSession); | |||
when(ruleDao.findRulesByDebtSubCharacteristicId(subCharacteristicDto.getId(), batchSession)).thenReturn(newArrayList( | |||
when(ruleDao.findRulesByDebtSubCharacteristicId(batchSession, subCharacteristicDto.getId())).thenReturn(newArrayList( | |||
new RuleDto().setSubCharacteristicId(subCharacteristicDto.getId()) | |||
.setRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.toString()) | |||
.setRemediationCoefficient("2h") |
@@ -59,17 +59,17 @@ public class DuplicationsParserTest { | |||
// Current file | |||
String key1 = "org.codehaus.sonar:sonar-plugin-api:src/main/java/org/sonar/api/utils/command/CommandExecutor.java"; | |||
currentFile = new ComponentDto().setId(10L).setQualifier("FIL").setKey(key1).setLongName("CommandExecutor").setProjectId(1L); | |||
when(componentDao.getByKey(session, key1)).thenReturn(currentFile); | |||
when(componentDao.getNullableByKey(session, key1)).thenReturn(currentFile); | |||
// File on same project | |||
String key2 = "org.codehaus.sonar:sonar-plugin-api:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java"; | |||
fileOnSameProject = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("CommandExecutor").setProjectId(1L); | |||
when(componentDao.getByKey(session, key2)).thenReturn(fileOnSameProject); | |||
when(componentDao.getNullableByKey(session, key2)).thenReturn(fileOnSameProject); | |||
// File on different project | |||
String key3 = "com.sonarsource.orchestrator:sonar-orchestrator:src/main/java/com/sonar/orchestrator/util/CommandExecutor.java"; | |||
fileOnDifferentProject = new ComponentDto().setId(12L).setQualifier("FIL").setKey(key3).setLongName("CommandExecutor").setProjectId(2L); | |||
when(componentDao.getByKey(session, key3)).thenReturn(fileOnDifferentProject); | |||
when(componentDao.getNullableByKey(session, key3)).thenReturn(fileOnDifferentProject); | |||
parser = new DuplicationsParser(componentDao); | |||
} |
@@ -65,8 +65,8 @@ public class DuplicationsWriterTest { | |||
String key2 = "org.codehaus.sonar:sonar-ws-client:src/main/java/org/sonar/wsclient/services/PropertyUpdateQuery.java"; | |||
ComponentDto file2 = new ComponentDto().setId(11L).setQualifier("FIL").setKey(key2).setLongName("PropertyUpdateQuery").setProjectId(1L); | |||
when(componentDao.getByKey(session, key1)).thenReturn(file1); | |||
when(componentDao.getByKey(session, key2)).thenReturn(file2); | |||
when(componentDao.getNullableByKey(session, key1)).thenReturn(file1); | |||
when(componentDao.getNullableByKey(session, key2)).thenReturn(file2); | |||
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube")); | |||
List<DuplicationsParser.Block> blocks = newArrayList(); | |||
@@ -104,7 +104,7 @@ public class DuplicationsWriterTest { | |||
"}" | |||
); | |||
verify(componentDao, times(2)).getByKey(eq(session), anyString()); | |||
verify(componentDao, times(2)).getNullableByKey(eq(session), anyString()); | |||
verify(componentDao, times(1)).getById(anyLong(), eq(session)); | |||
} | |||
@@ -83,11 +83,11 @@ public class ShowActionTest { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "org.codehaus.sonar:sonar", componentKey); | |||
ComponentDto componentDto = new ComponentDto().setId(10L); | |||
when(componentDao.getByKey(session, componentKey)).thenReturn(componentDto); | |||
when(componentDao.getNullableByKey(session, componentKey)).thenReturn(componentDto); | |||
String data = "{duplications}"; | |||
MeasureKey measureKey = MeasureKey.of(componentKey, CoreMetrics.DUPLICATIONS_DATA_KEY); | |||
when(measureDao.getByKey(session, measureKey)).thenReturn( | |||
when(measureDao.getNullableByKey(session, measureKey)).thenReturn( | |||
MeasureDto.createFor(measureKey).setTextValue("{duplications}") | |||
); | |||
@@ -106,10 +106,10 @@ public class ShowActionTest { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "org.codehaus.sonar:sonar", componentKey); | |||
ComponentDto componentDto = new ComponentDto().setId(10L); | |||
when(componentDao.getByKey(session, componentKey)).thenReturn(componentDto); | |||
when(componentDao.getNullableByKey(session, componentKey)).thenReturn(componentDto); | |||
MeasureKey measureKey = MeasureKey.of(componentKey, CoreMetrics.DUPLICATIONS_DATA_KEY); | |||
when(measureDao.getByKey(session, measureKey)).thenReturn(null); | |||
when(measureDao.getNullableByKey(session, measureKey)).thenReturn(null); | |||
WsTester.TestRequest request = tester.newGetRequest("api/duplications", "show").setParam("key", componentKey); | |||
request.execute(); |
@@ -54,7 +54,7 @@ public class MeasureDaoTest extends AbstractDaoTestCase { | |||
public void get_value_by_key() throws Exception { | |||
setupData("shared"); | |||
MeasureDto result = dao.getByKey(session, MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc")); | |||
MeasureDto result = dao.getNullableByKey(session, MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc")); | |||
assertThat(result.getId()).isEqualTo(22); | |||
assertThat(result.getValue()).isEqualTo(10d); | |||
} | |||
@@ -63,7 +63,7 @@ public class MeasureDaoTest extends AbstractDaoTestCase { | |||
public void get_data_by_key() throws Exception { | |||
setupData("shared"); | |||
MeasureDto result = dao.getByKey(session, MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line")); | |||
MeasureDto result = dao.getNullableByKey(session, MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line")); | |||
assertThat(result.getId()).isEqualTo(20); | |||
assertThat(result.getData()).isEqualTo("0123456789012345678901234567890123456789"); | |||
} | |||
@@ -72,7 +72,7 @@ public class MeasureDaoTest extends AbstractDaoTestCase { | |||
public void get_text_value_by_key() throws Exception { | |||
setupData("shared"); | |||
MeasureDto result = dao.getByKey(session, MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data")); | |||
MeasureDto result = dao.getNullableByKey(session, MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data")); | |||
assertThat(result.getId()).isEqualTo(21); | |||
assertThat(result.getData()).isEqualTo("36=1;37=1;38=1;39=1;43=1;48=1;53=1"); | |||
} |
@@ -316,7 +316,7 @@ public class QProfileBackupTest { | |||
when(profileDefinition.createProfile(any(ValidationMessages.class))).thenReturn(profile); | |||
definitions.add(profileDefinition); | |||
when(ruleDao.getByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(new RuleDto().setId(10).setSeverity("INFO")); | |||
when(ruleDao.getNullableByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(new RuleDto().setId(10).setSeverity("INFO")); | |||
when(qProfileOperations.newProfile(eq(name), eq(language), eq(true), any(UserSession.class), eq(session))).thenReturn(new QProfile().setId(1)); | |||
@@ -346,8 +346,8 @@ public class QProfileBackupTest { | |||
when(profileDefinition2.createProfile(any(ValidationMessages.class))).thenReturn(profile2); | |||
definitions.add(profileDefinition2); | |||
when(ruleDao.getByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(new RuleDto().setId(10).setSeverity("INFO")); | |||
when(ruleDao.getByKey(session, RuleKey.of("checkstyle", "rule"))).thenReturn(new RuleDto().setId(11).setSeverity("INFO")); | |||
when(ruleDao.getNullableByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(new RuleDto().setId(10).setSeverity("INFO")); | |||
when(ruleDao.getNullableByKey(session, RuleKey.of("checkstyle", "rule"))).thenReturn(new RuleDto().setId(11).setSeverity("INFO")); | |||
when(qProfileOperations.newProfile(eq("Default"), eq("java"), eq(true), any(UserSession.class), eq(session))).thenReturn(new QProfile().setId(1)); | |||
@@ -378,7 +378,7 @@ public class QProfileBackupTest { | |||
when(profileDefinition.createProfile(any(ValidationMessages.class))).thenReturn(profile); | |||
definitions.add(profileDefinition); | |||
when(ruleDao.getByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(null); | |||
when(ruleDao.getNullableByKey(session, RuleKey.of("pmd", "rule"))).thenReturn(null); | |||
when(qProfileOperations.newProfile(eq(name), eq(language), eq(true), any(UserSession.class), eq(session))).thenReturn(new QProfile().setId(1)); | |||
@@ -81,7 +81,7 @@ public class RegisterQualityProfilesMediumTest { | |||
// Check ActiveRules in DB | |||
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao(); | |||
assertThat(activeRuleDao.findByProfileKey(qualityProfileKey, dbSession)).hasSize(2); | |||
assertThat(activeRuleDao.findByProfileKey(dbSession, qualityProfileKey)).hasSize(2); | |||
RuleKey ruleKey = RuleKey.of("xoo", "x1"); | |||
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(qualityProfileKey, ruleKey); | |||
@@ -126,16 +126,16 @@ public class RegisterQualityProfilesMediumTest { | |||
// Check ActiveRules in DB | |||
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao(); | |||
assertThat(activeRuleDao.findByProfileKey(qualityProfileKey, dbSession)).hasSize(2); | |||
assertThat(activeRuleDao.findByProfileKey(dbSession, qualityProfileKey)).hasSize(2); | |||
RuleKey ruleKey = RuleKey.of("xoo", "x1"); | |||
ActiveRuleDto activeRule = activeRuleDao.getByKey(dbSession, ActiveRuleKey.of(qualityProfileKey, ruleKey)); | |||
ActiveRuleDto activeRule = activeRuleDao.getNullableByKey(dbSession, ActiveRuleKey.of(qualityProfileKey, ruleKey)); | |||
assertThat(activeRule.getKey().qProfile()).isEqualTo(qualityProfileKey); | |||
assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey); | |||
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL); | |||
// Check ActiveRuleParameters in DB | |||
Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.findParamsByActiveRule(activeRule, dbSession)); | |||
Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.findParamsByActiveRule(dbSession, activeRule)); | |||
assertThat(params).hasSize(2); | |||
// set by profile | |||
assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true"); |
@@ -81,11 +81,11 @@ public class RuleActivatorMediumTest { | |||
ruleActivator.activate(activation); | |||
// verify db | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(PROFILE_KEY, dbSession); | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, PROFILE_KEY); | |||
assertThat(activeRuleDtos).hasSize(1); | |||
assertThat(activeRuleDtos.get(0).getSeverityString()).isEqualTo(Severity.BLOCKER); | |||
assertThat(activeRuleDtos.get(0).getInheritance()).isNull(); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(activeRuleDtos.get(0), dbSession); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(dbSession, activeRuleDtos.get(0)); | |||
assertThat(params).hasSize(1); | |||
assertThat(params.get(0).getValue()).isEqualTo("7"); | |||
@@ -106,11 +106,11 @@ public class RuleActivatorMediumTest { | |||
ruleActivator.activate(activation); | |||
// verify db | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(PROFILE_KEY, dbSession); | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, PROFILE_KEY); | |||
assertThat(activeRuleDtos).hasSize(1); | |||
assertThat(activeRuleDtos.get(0).getSeverityString()).isEqualTo(Severity.MINOR); | |||
assertThat(activeRuleDtos.get(0).getInheritance()).isNull(); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(activeRuleDtos.get(0), dbSession); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(dbSession, activeRuleDtos.get(0)); | |||
assertThat(params).hasSize(1); | |||
assertThat(params.get(0).getValue()).isEqualTo("10"); | |||
@@ -139,11 +139,11 @@ public class RuleActivatorMediumTest { | |||
ruleActivator.activate(update); | |||
// verify db | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(PROFILE_KEY, dbSession); | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, PROFILE_KEY); | |||
assertThat(activeRuleDtos).hasSize(1); | |||
assertThat(activeRuleDtos.get(0).getSeverityString()).isEqualTo(Severity.CRITICAL); | |||
assertThat(activeRuleDtos.get(0).getInheritance()).isNull(); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(activeRuleDtos.get(0), dbSession); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(dbSession, activeRuleDtos.get(0)); | |||
assertThat(params).hasSize(1); | |||
assertThat(params.get(0).getValue()).isEqualTo("42"); | |||
@@ -168,7 +168,7 @@ public class RuleActivatorMediumTest { | |||
assertThat(db.activeRuleDao().getParamsByKeyAndName(activeRuleKey, "max", dbSession)).isNotNull(); | |||
db.activeRuleDao().removeParamByKeyAndName(activeRuleKey, "max", dbSession); | |||
db.activeRuleDao().removeParamByKeyAndName(dbSession, activeRuleKey, "max"); | |||
dbSession.commit(); | |||
assertThat(db.activeRuleDao().getParamsByKeyAndName(activeRuleKey, "max", dbSession)).isNull(); | |||
@@ -181,11 +181,11 @@ public class RuleActivatorMediumTest { | |||
ruleActivator.activate(update); | |||
// verify db | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(PROFILE_KEY, dbSession); | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, PROFILE_KEY); | |||
assertThat(activeRuleDtos).hasSize(1); | |||
assertThat(activeRuleDtos.get(0).getSeverityString()).isEqualTo(Severity.CRITICAL); | |||
assertThat(activeRuleDtos.get(0).getInheritance()).isNull(); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(activeRuleDtos.get(0), dbSession); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(dbSession, activeRuleDtos.get(0)); | |||
assertThat(params).hasSize(1); | |||
assertThat(params.get(0).getValue()).isEqualTo("42"); | |||
@@ -213,11 +213,11 @@ public class RuleActivatorMediumTest { | |||
ruleActivator.activate(update); | |||
// verify db | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(PROFILE_KEY, dbSession); | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, PROFILE_KEY); | |||
assertThat(activeRuleDtos).hasSize(1); | |||
assertThat(activeRuleDtos.get(0).getSeverityString()).isEqualTo(Severity.MINOR); | |||
assertThat(activeRuleDtos.get(0).getInheritance()).isNull(); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(activeRuleDtos.get(0), dbSession); | |||
List<ActiveRuleParamDto> params = db.activeRuleDao().findParamsByActiveRule(dbSession, activeRuleDtos.get(0)); | |||
assertThat(params).hasSize(1); | |||
assertThat(params.get(0).getValue()).isEqualTo("10"); | |||
@@ -400,7 +400,7 @@ public class RuleActivatorMediumTest { | |||
private void verifyZeroActiveRules(ActiveRuleKey key) { | |||
// verify db | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(key.qProfile(), dbSession); | |||
List<ActiveRuleDto> activeRuleDtos = db.activeRuleDao().findByProfileKey(dbSession, key.qProfile()); | |||
assertThat(activeRuleDtos).isEmpty(); | |||
//TODO test params | |||
@@ -80,7 +80,7 @@ public class ActiveRuleIndexMediumTest { | |||
dbSession.commit(); | |||
// verify db | |||
List<ActiveRuleDto> persistedDtos = db.activeRuleDao().findByRule(ruleDto, dbSession); | |||
List<ActiveRuleDto> persistedDtos = db.activeRuleDao().findByRule(dbSession, ruleDto); | |||
assertThat(persistedDtos).hasSize(1); | |||
// verify es | |||
@@ -104,12 +104,12 @@ public class ActiveRuleIndexMediumTest { | |||
RuleParamDto minParam = new RuleParamDto() | |||
.setName("min") | |||
.setType("STRING"); | |||
db.ruleDao().addRuleParam(ruleDto, minParam, dbSession); | |||
db.ruleDao().addRuleParam(dbSession, ruleDto, minParam); | |||
RuleParamDto maxParam = new RuleParamDto() | |||
.setName("max") | |||
.setType("STRING"); | |||
db.ruleDao().addRuleParam(ruleDto, maxParam, dbSession); | |||
db.ruleDao().addRuleParam(dbSession, ruleDto, maxParam); | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
@@ -118,16 +118,16 @@ public class ActiveRuleIndexMediumTest { | |||
ActiveRuleParamDto activeRuleMinParam = ActiveRuleParamDto.createFor(minParam) | |||
.setValue("minimum"); | |||
db.activeRuleDao().addParam(activeRule, activeRuleMinParam, dbSession); | |||
db.activeRuleDao().addParam(dbSession, activeRule, activeRuleMinParam); | |||
ActiveRuleParamDto activeRuleMaxParam = ActiveRuleParamDto.createFor(maxParam) | |||
.setValue("maximum"); | |||
db.activeRuleDao().addParam(activeRule, activeRuleMaxParam, dbSession); | |||
db.activeRuleDao().addParam(dbSession, activeRule, activeRuleMaxParam); | |||
dbSession.commit(); | |||
// verify db | |||
List<ActiveRuleParamDto> persistedDtos = db.activeRuleDao().findParamsByActiveRule(activeRule, dbSession); | |||
List<ActiveRuleParamDto> persistedDtos = db.activeRuleDao().findParamsByActiveRule(dbSession, activeRule); | |||
assertThat(persistedDtos).hasSize(2); | |||
// verify es | |||
@@ -158,8 +158,8 @@ public class ActiveRuleIndexMediumTest { | |||
// in db | |||
dbSession.clearCache(); | |||
assertThat(db.activeRuleDao().findByRule(rule1, dbSession)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByRule(rule2, dbSession)).hasSize(2); | |||
assertThat(db.activeRuleDao().findByRule(dbSession, rule1)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByRule(dbSession, rule2)).hasSize(2); | |||
// in es | |||
List<ActiveRule> activeRules = index.findByRule(RuleKey.of("java", "r1")); |
@@ -71,7 +71,7 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase{ | |||
session.commit(); | |||
ActiveRuleDto result = activeRuleDao.getByKey(session, activeRuleDto.getKey()); | |||
ActiveRuleDto result = activeRuleDao.getNullableByKey(session, activeRuleDto.getKey()); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.getKey()).isNotNull(); |
@@ -103,7 +103,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(1); | |||
// 1. Deactivate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_RULE_DEACTIVATE_METHOD); | |||
@@ -113,7 +113,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
} | |||
@Test | |||
@@ -130,7 +130,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(4); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(4); | |||
// 1. Deactivate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_DEACTIVATE_METHOD); | |||
@@ -139,7 +139,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
} | |||
@Test | |||
@@ -155,7 +155,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(2); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(2); | |||
// 1. Deactivate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_DEACTIVATE_METHOD); | |||
@@ -164,8 +164,8 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(0); | |||
assertThat(db.activeRuleDao().findByProfileKey(php.getKey(), session)).hasSize(2); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(0); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, php.getKey())).hasSize(2); | |||
} | |||
@Test | |||
@@ -178,7 +178,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(2); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(2); | |||
// 1. Deactivate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_DEACTIVATE_METHOD); | |||
@@ -188,7 +188,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(1); | |||
} | |||
@Test | |||
@@ -198,7 +198,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
// 1. Activate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_RULE_ACTIVATE_METHOD); | |||
@@ -208,7 +208,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(1); | |||
} | |||
@Test | |||
@@ -218,7 +218,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
try { | |||
// 1. Activate Rule | |||
@@ -240,7 +240,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
// 1. Activate Rule | |||
@@ -254,7 +254,7 @@ public class QProfilesWsMediumTest { | |||
// 2. Assert ActiveRule in DAO | |||
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey()); | |||
assertThat(db.activeRuleDao().getByKey(session,activeRuleKey).getSeverityString()) | |||
assertThat(db.activeRuleDao().getNullableByKey(session, activeRuleKey).getSeverityString()) | |||
.isEqualTo("MINOR"); | |||
} | |||
@@ -268,7 +268,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
// 1. Activate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_ACTIVATE_METHOD); | |||
@@ -278,7 +278,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(4); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(4); | |||
} | |||
@Test | |||
@@ -290,7 +290,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
// 1. Activate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_ACTIVATE_METHOD); | |||
@@ -303,7 +303,7 @@ public class QProfilesWsMediumTest { | |||
result.assertJson("{\"ignored\":[{\"key\":\"blah:toto\"}],\"activated\":[{\"key\":\"blah:tata\"}]}"); | |||
// 3. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(1); | |||
} | |||
@Test | |||
@@ -317,7 +317,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(php.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, php.getKey())).isEmpty(); | |||
// 1. Activate Rule | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_ACTIVATE_METHOD); | |||
@@ -327,7 +327,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(php.getKey(), session)).hasSize(2); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, php.getKey())).hasSize(2); | |||
} | |||
@Test | |||
@@ -340,7 +340,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 0. Assert No Active Rule for profile | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).isEmpty(); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty(); | |||
// 1. Activate Rule with query returning 0 hits | |||
WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_ACTIVATE_METHOD); | |||
@@ -350,7 +350,7 @@ public class QProfilesWsMediumTest { | |||
session.clearCache(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(0); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(0); | |||
// 1. Activate Rule with query returning 1 hits | |||
request = wsTester.newGetRequest(API_ENDPOINT, API_BULK_RULE_ACTIVATE_METHOD); | |||
@@ -360,7 +360,7 @@ public class QProfilesWsMediumTest { | |||
session.commit(); | |||
// 2. Assert ActiveRule in DAO | |||
assertThat(db.activeRuleDao().findByProfileKey(profile.getKey(), session)).hasSize(1); | |||
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(1); | |||
} | |||
private QualityProfileDto getProfile(String lang) { |
@@ -81,7 +81,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
// verify db | |||
assertThat(dbClient.ruleDao().findAll(dbSession)).hasSize(2); | |||
RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); | |||
assertThat(rule1.getName()).isEqualTo("One"); | |||
assertThat(rule1.getDescription()).isEqualTo("Description of One"); | |||
assertThat(rule1.getSeverityString()).isEqualTo(Severity.BLOCKER); | |||
@@ -94,7 +94,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
assertThat(rule1.getEffortToFixDescription()).isEqualTo("squid.S115.effortToFix"); | |||
// TODO check characteristic and remediation function | |||
List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(ruleKey1, dbSession); | |||
List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(dbSession, ruleKey1); | |||
assertThat(params).hasSize(2); | |||
RuleParamDto param = getParam(params, "param1"); | |||
assertThat(param.getDescription()).isEqualTo("parameter one"); | |||
@@ -110,7 +110,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
execute(new FakeRepositoryV1()); | |||
RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); | |||
assertThat(rule1.getCreatedAt()).isEqualTo(DATE1); | |||
assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1); | |||
} | |||
@@ -122,7 +122,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
// user adds tags and sets markdown note | |||
RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
RuleDto rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); | |||
rule1.setTags(Sets.newHashSet("usertag1", "usertag2")); | |||
rule1.setNoteData("user *note*"); | |||
rule1.setNoteUserLogin("marius"); | |||
@@ -133,7 +133,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
execute(new FakeRepositoryV2()); | |||
// rule1 has been updated | |||
rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
rule1 = dbClient.ruleDao().getNullableByKey(dbSession, ruleKey1); | |||
assertThat(rule1.getName()).isEqualTo("One v2"); | |||
assertThat(rule1.getDescription()).isEqualTo("Description of One v2"); | |||
assertThat(rule1.getSeverityString()).isEqualTo(Severity.INFO); | |||
@@ -147,19 +147,19 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
assertThat(rule1.getUpdatedAt()).isEqualTo(DATE2); | |||
assertThat(rule1.getEffortToFixDescription()).isEqualTo("squid.S115.effortToFix.v2"); | |||
// TODO check characteristic and remediation function | |||
List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(ruleKey1, dbSession); | |||
List<RuleParamDto> params = dbClient.ruleDao().findRuleParamsByRuleKey(dbSession, ruleKey1); | |||
assertThat(params).hasSize(2); | |||
RuleParamDto param = getParam(params, "param1"); | |||
assertThat(param.getDescription()).isEqualTo("parameter one v2"); | |||
assertThat(param.getDefaultValue()).isEqualTo("default1 v2"); | |||
// rule2 has been removed -> status set to REMOVED but db row is not deleted | |||
RuleDto rule2 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule2")); | |||
RuleDto rule2 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule2")); | |||
assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED); | |||
assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2); | |||
// rule3 has been created | |||
RuleDto rule3 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule3")); | |||
RuleDto rule3 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule3")); | |||
assertThat(rule3).isNotNull(); | |||
assertThat(rule3.getStatus()).isEqualTo(RuleStatus.READY); | |||
} | |||
@@ -176,7 +176,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
when(system.now()).thenReturn(DATE3.getTime()); | |||
execute(new FakeRepositoryV2()); | |||
// -> rule2 is still removed, but not update at DATE3 | |||
RuleDto rule2 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule2")); | |||
RuleDto rule2 = dbClient.ruleDao().getNullableByKey(dbSession, RuleKey.of("fake", "rule2")); | |||
assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED); | |||
assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2); | |||
} |
@@ -80,7 +80,7 @@ public class RuleDataMediumTest { | |||
dbSession.commit(); | |||
// verify that rule is persisted in db | |||
RuleDto persistedDto = dao.getByKey(dbSession, ruleKey); | |||
RuleDto persistedDto = dao.getNullableByKey(dbSession, ruleKey); | |||
assertThat(persistedDto).isNotNull(); | |||
assertThat(persistedDto.getId()).isGreaterThanOrEqualTo(0); | |||
assertThat(persistedDto.getRuleKey()).isEqualTo(ruleKey.rule()); | |||
@@ -91,7 +91,6 @@ public class RuleDataMediumTest { | |||
assertThat(persistedDto.getUpdatedAt()).isNotNull(); | |||
// verify that rule is indexed in es | |||
Rule hit = index.getByKey(ruleKey); | |||
assertThat(hit).isNotNull(); | |||
assertThat(hit.key().repository()).isEqualTo(ruleKey.repository()); | |||
@@ -122,22 +121,22 @@ public class RuleDataMediumTest { | |||
.setType(RuleParamType.INTEGER.type()) | |||
.setDefaultValue("2") | |||
.setDescription("Minimum"); | |||
dao.addRuleParam(ruleDto, minParamDto, dbSession); | |||
dao.addRuleParam(dbSession, ruleDto, minParamDto); | |||
RuleParamDto maxParamDto = new RuleParamDto() | |||
.setName("max") | |||
.setType(RuleParamType.INTEGER.type()) | |||
.setDefaultValue("10") | |||
.setDescription("Maximum"); | |||
dao.addRuleParam(ruleDto, maxParamDto, dbSession); | |||
dao.addRuleParam(dbSession, ruleDto, maxParamDto); | |||
dbSession.commit(); | |||
//Verify that RuleDto has date from insertion | |||
RuleDto theRule = dao.getByKey(dbSession, ruleKey); | |||
RuleDto theRule = dao.getNullableByKey(dbSession, ruleKey); | |||
assertThat(theRule.getCreatedAt()).isNotNull(); | |||
assertThat(theRule.getUpdatedAt()).isNotNull(); | |||
// verify that parameters are persisted in db | |||
List<RuleParamDto> persistedDtos = dao.findRuleParamsByRuleKey(theRule.getKey(), dbSession); | |||
List<RuleParamDto> persistedDtos = dao.findRuleParamsByRuleKey(dbSession, theRule.getKey()); | |||
assertThat(persistedDtos).hasSize(2); | |||
// verify that parameters are indexed in es | |||
@@ -198,14 +197,14 @@ public class RuleDataMediumTest { | |||
.setType(RuleParamType.INTEGER.type()) | |||
.setDefaultValue("2") | |||
.setDescription("Minimum"); | |||
dao.addRuleParam(ruleDto, minParamDto, dbSession); | |||
dao.addRuleParam(dbSession, ruleDto, minParamDto); | |||
RuleParamDto maxParamDto = new RuleParamDto() | |||
.setName("max") | |||
.setType(RuleParamType.INTEGER.type()) | |||
.setDefaultValue("10") | |||
.setDescription("Maximum"); | |||
dao.addRuleParam(ruleDto, maxParamDto, dbSession); | |||
dao.addRuleParam(dbSession, ruleDto, maxParamDto); | |||
dbSession.commit(); | |||
// verify that parameters are indexed in es | |||
@@ -223,7 +222,7 @@ public class RuleDataMediumTest { | |||
minParamDto | |||
.setDefaultValue("0.5") | |||
.setDescription("new description"); | |||
dao.updateRuleParam(ruleDto, minParamDto, dbSession); | |||
dao.updateRuleParam(dbSession, ruleDto, minParamDto); | |||
dbSession.commit(); | |||
// verify that parameters are updated in es |
@@ -82,7 +82,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(6).setRemediationFunction("CONSTANT_ISSUE").setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -117,7 +117,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -150,7 +150,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(2).setRemediationFunction("CONSTANT_ISSUE").setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -171,7 +171,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -204,7 +204,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(6).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -240,7 +240,7 @@ public class RuleOperationsTest { | |||
.setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
operations.updateRule(new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey(null), authorizedUserSession); | |||
@@ -262,7 +262,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(6).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -289,7 +289,7 @@ public class RuleOperationsTest { | |||
RuleDto dto = new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
operations.updateRule(new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey(null), authorizedUserSession); | |||
@@ -310,7 +310,7 @@ public class RuleOperationsTest { | |||
RuleDto dto = new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck").setSubCharacteristicId(-1); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
operations.updateRule( | |||
new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey(null), | |||
@@ -325,7 +325,7 @@ public class RuleOperationsTest { | |||
public void fail_to_update_rule_on_unknown_rule() throws Exception { | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(null); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(null); | |||
try { | |||
operations.updateRule( | |||
@@ -347,7 +347,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(2).setRemediationFunction("CONSTANT_ISSUE").setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(null); | |||
@@ -371,7 +371,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(2).setRemediationFunction("LINEAR").setRemediationCoefficient("1h"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(ruleDao.getNullableByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); |
@@ -26,7 +26,7 @@ import org.junit.ClassRule; | |||
import org.junit.Test; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.core.persistence.DbSession; | |||
import org.sonar.core.persistence.MyBatis; | |||
import org.sonar.server.db.DbClient; | |||
import org.sonar.server.rule.db.RuleDao; | |||
import org.sonar.server.rule.index.RuleIndex; | |||
import org.sonar.server.rule.index.RuleNormalizer; | |||
@@ -50,7 +50,7 @@ public class RuleServiceMediumTest { | |||
@Before | |||
public void before() { | |||
tester.clearDbAndEs(); | |||
dbSession = tester.get(MyBatis.class).openSession(false); | |||
dbSession = tester.get(DbClient.class).openSession(false); | |||
} | |||
@After | |||
@@ -62,14 +62,10 @@ public class RuleServiceMediumTest { | |||
public void test_list_tags() throws InterruptedException { | |||
// insert db | |||
RuleKey key1 = RuleKey.of("javascript", "S001"); | |||
dao.insert(dbSession, RuleTesting.newDto(key1) | |||
.setTags(Sets.newHashSet("tag1")) | |||
.setSystemTags(Sets.newHashSet("sys1", "sys2"))); | |||
RuleKey key2 = RuleKey.of("java", "S001"); | |||
dao.insert(dbSession, RuleTesting.newDto(key2) | |||
.setTags(Sets.newHashSet("tag2")) | |||
.setSystemTags(Collections.<String>emptySet())); | |||
dao.insert(dbSession, | |||
RuleTesting.newDto(key1).setTags(Sets.newHashSet("tag1")).setSystemTags(Sets.newHashSet("sys1", "sys2")), | |||
RuleTesting.newDto(key2).setTags(Sets.newHashSet("tag2")).setSystemTags(Collections.<String>emptySet())); | |||
dbSession.commit(); | |||
// all tags, including system |
@@ -106,7 +106,7 @@ public class RuleUpdaterMediumTest { | |||
updater.update(update, UserSession.get()); | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getNoteData()).isEqualTo("my *note*"); | |||
assertThat(rule.getNoteUserLogin()).isEqualTo("me"); | |||
assertThat(rule.getTags()).containsOnly("tag1"); | |||
@@ -136,7 +136,7 @@ public class RuleUpdaterMediumTest { | |||
updater.update(update, UserSession.get()); | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getNoteData()).isEqualTo("my *note*"); | |||
assertThat(rule.getNoteUserLogin()).isEqualTo("me"); | |||
assertThat(rule.getNoteCreatedAt()).isNotNull(); | |||
@@ -161,7 +161,7 @@ public class RuleUpdaterMediumTest { | |||
updater.update(update, UserSession.get()); | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getNoteData()).isNull(); | |||
assertThat(rule.getNoteUserLogin()).isNull(); | |||
assertThat(rule.getNoteCreatedAt()).isNull(); | |||
@@ -174,8 +174,7 @@ public class RuleUpdaterMediumTest { | |||
// insert db | |||
db.ruleDao().insert(dbSession, RuleTesting.newDto(RULE_KEY) | |||
.setTags(Sets.newHashSet("security")) | |||
.setSystemTags(Sets.newHashSet("java8", "javadoc")) | |||
); | |||
.setSystemTags(Sets.newHashSet("java8", "javadoc"))); | |||
dbSession.commit(); | |||
// java8 is a system tag -> ignore | |||
@@ -183,7 +182,7 @@ public class RuleUpdaterMediumTest { | |||
updater.update(update, UserSession.get()); | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getTags()).containsOnly("bug"); | |||
assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc"); | |||
@@ -204,7 +203,7 @@ public class RuleUpdaterMediumTest { | |||
updater.update(update, UserSession.get()); | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getTags()).isEmpty(); | |||
assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc"); | |||
@@ -255,7 +254,7 @@ public class RuleUpdaterMediumTest { | |||
// verify db | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getSubCharacteristicId()).isEqualTo(softReliabilityId); | |||
assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name()); | |||
assertThat(rule.getRemediationCoefficient()).isNull(); | |||
@@ -291,7 +290,7 @@ public class RuleUpdaterMediumTest { | |||
// verify db | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getSubCharacteristicId()).isNull(); | |||
assertThat(rule.getRemediationFunction()).isNull(); | |||
assertThat(rule.getRemediationCoefficient()).isNull(); | |||
@@ -327,7 +326,7 @@ public class RuleUpdaterMediumTest { | |||
// verify db | |||
dbSession.clearCache(); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, RULE_KEY); | |||
RuleDto rule = db.ruleDao().getNullableByKey(dbSession, RULE_KEY); | |||
assertThat(rule.getSubCharacteristicId()).isEqualTo(-1); | |||
assertThat(rule.getRemediationFunction()).isNull(); | |||
assertThat(rule.getRemediationCoefficient()).isNull(); |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.server.rule.db; | |||
import com.google.common.collect.ImmutableList; | |||
import com.google.common.collect.Iterables; | |||
import org.junit.After; | |||
import org.junit.Before; | |||
@@ -113,7 +112,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
@Test | |||
public void select_by_id() throws Exception { | |||
setupData("selectById"); | |||
RuleDto ruleDto = dao.getById(2, session); | |||
RuleDto ruleDto = dao.getById(session, 2); | |||
assertThat(ruleDto.getId()).isEqualTo(2); | |||
assertThat(ruleDto.getName()).isEqualTo("Avoid Null"); | |||
@@ -125,9 +124,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
@Test | |||
public void select_by_rule_key() throws Exception { | |||
setupData("select_by_rule_key"); | |||
assertThat(dao.getByKey(session, RuleKey.of("checkstyle", "AvoidComparison"))).isNotNull(); | |||
assertThat(dao.getByKey(session, RuleKey.of("checkstyle", "Unknown"))).isNull(); | |||
assertThat(dao.getByKey(session, RuleKey.of("Unknown", "AvoidComparison"))).isNull(); | |||
assertThat(dao.getNullableByKey(session, RuleKey.of("checkstyle", "AvoidComparison"))).isNotNull(); | |||
assertThat(dao.getNullableByKey(session, RuleKey.of("checkstyle", "Unknown"))).isNull(); | |||
assertThat(dao.getNullableByKey(session, RuleKey.of("Unknown", "AvoidComparison"))).isNull(); | |||
} | |||
@Test | |||
@@ -285,7 +284,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
.setDefaultRemediationOffset("5min") | |||
.setEffortToFixDescription("squid.S115.effortToFix2"); | |||
dao.insert(session, ImmutableList.of(ruleToInsert1, ruleToInsert2)); | |||
dao.insert(session, ruleToInsert1, ruleToInsert2); | |||
session.commit(); | |||
checkTables("insert_all", "rules"); | |||
@@ -308,8 +307,8 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
@Test | |||
public void select_parameters_by_rule_id() throws Exception { | |||
setupData("select_parameters_by_rule_id"); | |||
RuleDto rule = dao.getById(1, session); | |||
List<RuleParamDto> ruleDtos = dao.findRuleParamsByRuleKey(rule.getKey(), session); | |||
RuleDto rule = dao.getById(session, 1); | |||
List<RuleParamDto> ruleDtos = dao.findRuleParamsByRuleKey(session, rule.getKey()); | |||
assertThat(ruleDtos.size()).isEqualTo(1); | |||
RuleParamDto ruleDto = ruleDtos.get(0); | |||
@@ -324,17 +323,17 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
public void select_parameters_by_rule_ids() throws Exception { | |||
setupData("select_parameters_by_rule_ids"); | |||
RuleDto rule1 = dao.getById(1, session); | |||
RuleDto rule2 = dao.getById(2, session); | |||
assertThat(dao.findRuleParamsByRules(newArrayList(rule1, rule2), session)).hasSize(2); | |||
assertThat(dao.findRuleParamsByRules(newArrayList(rule1), session)).hasSize(1); | |||
RuleDto rule1 = dao.getById(session, 1); | |||
RuleDto rule2 = dao.getById(session, 2); | |||
assertThat(dao.findRuleParamsByRules(session, newArrayList(rule1, rule2))).hasSize(2); | |||
assertThat(dao.findRuleParamsByRules(session, newArrayList(rule1))).hasSize(1); | |||
} | |||
@Test | |||
public void insert_parameter() { | |||
setupData("insert_parameter"); | |||
RuleDto rule1 = dao.getById(1, session); | |||
RuleDto rule1 = dao.getById(session, 1); | |||
RuleParamDto param = RuleParamDto.createFor(rule1) | |||
.setName("max") | |||
@@ -342,7 +341,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
.setDefaultValue("30") | |||
.setDescription("My Parameter"); | |||
dao.addRuleParam(rule1, param, session); | |||
dao.addRuleParam(session, rule1, param); | |||
session.commit(); | |||
checkTables("insert_parameter", "rules_parameters"); | |||
@@ -352,9 +351,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
public void update_parameter() { | |||
setupData("update_parameter"); | |||
RuleDto rule1 = dao.getById(1, session); | |||
RuleDto rule1 = dao.getById(session, 1); | |||
List<RuleParamDto> params = dao.findRuleParamsByRuleKey(rule1.getKey(), session); | |||
List<RuleParamDto> params = dao.findRuleParamsByRuleKey(session, rule1.getKey()); | |||
assertThat(params).hasSize(1); | |||
RuleParamDto param = Iterables.getFirst(params, null); | |||
@@ -364,7 +363,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
.setDefaultValue("^[a-z]+(\\.[a-z][a-z0-9]*)*$") | |||
.setDescription("Regular expression used to check the package names against."); | |||
dao.updateRuleParam(rule1, param, session); | |||
dao.updateRuleParam(session, rule1, param); | |||
session.commit(); | |||
checkTables("update_parameter", "rules_parameters"); |
@@ -40,6 +40,7 @@ import org.sonar.core.rule.RuleDto; | |||
import org.sonar.core.rule.RuleParamDto; | |||
import org.sonar.core.technicaldebt.db.CharacteristicDto; | |||
import org.sonar.server.db.DbClient; | |||
import org.sonar.server.debt.DebtTesting; | |||
import org.sonar.server.rule.Rule; | |||
import org.sonar.server.rule.db.RuleDao; | |||
import org.sonar.server.search.FacetValue; | |||
@@ -160,7 +161,6 @@ public class RuleIndexMediumTest { | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001"))); | |||
dbSession.commit(); | |||
QueryOptions options = new QueryOptions(); | |||
options.addFieldsToReturn(RuleNormalizer.RuleField.LANGUAGE.field(), RuleNormalizer.RuleField.STATUS.field()); | |||
Result<Rule> results = index.search(new RuleQuery(), options); | |||
@@ -184,7 +184,6 @@ public class RuleIndexMediumTest { | |||
.setName("testing the partial match and matching of rule")); | |||
dbSession.commit(); | |||
// substring | |||
RuleQuery query = new RuleQuery().setQueryText("test"); | |||
assertThat(index.search(query, new QueryOptions()).getHits()).hasSize(1); | |||
@@ -259,11 +258,11 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_any_of_languages() throws InterruptedException { | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setLanguage("java")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S002")).setLanguage("js")); | |||
dao.insert(dbSession, | |||
newRuleDto(RuleKey.of("java", "S001")).setLanguage("java"), | |||
newRuleDto(RuleKey.of("javascript", "S002")).setLanguage("js")); | |||
dbSession.commit(); | |||
RuleQuery query = new RuleQuery().setLanguages(Arrays.asList("cobol", "js")); | |||
Result<Rule> results = index.search(query, new QueryOptions()); | |||
@@ -286,16 +285,10 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_characteristics() throws InterruptedException { | |||
CharacteristicDto char1 = new CharacteristicDto().setName("char1") | |||
.setKey("char1") | |||
.setEnabled(true); | |||
CharacteristicDto char1 = DebtTesting.newCharacteristicDto("char1"); | |||
dbClient.debtCharacteristicDao().insert(char1, dbSession); | |||
dbSession.commit(); | |||
CharacteristicDto char11 = new CharacteristicDto().setName("char11") | |||
.setKey("char11") | |||
.setEnabled(true) | |||
CharacteristicDto char11 = DebtTesting.newCharacteristicDto("char11") | |||
.setParentId(char1.getId()); | |||
dbClient.debtCharacteristicDao().insert(char11, dbSession); | |||
dbSession.commit(); | |||
@@ -493,14 +486,14 @@ public class RuleIndexMediumTest { | |||
.setName("testing") | |||
.setType("STRING") | |||
.setDefaultValue(value); | |||
dao.addRuleParam(rule, param, dbSession); | |||
dao.addRuleParam(dbSession, rule, param); | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule) | |||
.setSeverity("BLOCKER"); | |||
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param); | |||
dbClient.activeRuleDao().insert(dbSession, activeRule); | |||
dbClient.activeRuleDao().addParam(activeRule, activeRuleParam, dbSession); | |||
dbClient.activeRuleDao().addParam(dbSession, activeRule, activeRuleParam); | |||
dbSession.commit(); | |||
assertThat(index.getByKey(rule.getKey()).params().get(0).defaultValue()).isEqualTo(value); |
@@ -236,25 +236,25 @@ public class RulesWebServiceTest { | |||
.setType("string") | |||
.setDescription("My small description") | |||
.setName("my_var"); | |||
ruleDao.addRuleParam(rule, param, session); | |||
ruleDao.addRuleParam(session, rule, param); | |||
RuleParamDto param2 = RuleParamDto.createFor(rule) | |||
.setDefaultValue("other value") | |||
.setType("integer") | |||
.setDescription("My small description") | |||
.setName("the_var"); | |||
ruleDao.addRuleParam(rule, param2, session); | |||
ruleDao.addRuleParam(session, rule, param2); | |||
ActiveRuleDto activeRule = newActiveRule(profile, rule); | |||
tester.get(ActiveRuleDao.class).insert(session, activeRule); | |||
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param) | |||
.setValue("The VALUE"); | |||
tester.get(ActiveRuleDao.class).addParam(activeRule, activeRuleParam, session); | |||
tester.get(ActiveRuleDao.class).addParam(session, activeRule, activeRuleParam); | |||
ActiveRuleParamDto activeRuleParam2 = ActiveRuleParamDto.createFor(param2) | |||
.setValue("The Other Value"); | |||
tester.get(ActiveRuleDao.class).addParam(activeRule, activeRuleParam2, session); | |||
tester.get(ActiveRuleDao.class).addParam(session, activeRule, activeRuleParam2); | |||
session.commit(); | |||
@@ -99,7 +99,7 @@ public class SourceServiceTest { | |||
@Test | |||
public void get_scm_author_data() throws Exception { | |||
service.getScmAuthorData(COMPONENT_KEY); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)); | |||
} | |||
@Test | |||
@@ -117,7 +117,7 @@ public class SourceServiceTest { | |||
@Test | |||
public void not_get_scm_author_data_if_no_data() throws Exception { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_KEY); | |||
when(measureDao.getByKey(eq(session), any(MeasureKey.class))).thenReturn(null); | |||
when(measureDao.getNullableByKey(eq(session), any(MeasureKey.class))).thenReturn(null); | |||
assertThat(service.getScmAuthorData(COMPONENT_KEY)).isNull(); | |||
} | |||
@@ -125,13 +125,13 @@ public class SourceServiceTest { | |||
public void get_scm_date_data() throws Exception { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_KEY); | |||
service.getScmDateData(COMPONENT_KEY); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)); | |||
} | |||
@Test | |||
public void not_get_scm_date_data_if_no_data() throws Exception { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_KEY); | |||
when(measureDao.getByKey(eq(session), any(MeasureKey.class))).thenReturn(null); | |||
when(measureDao.getNullableByKey(eq(session), any(MeasureKey.class))).thenReturn(null); | |||
assertThat(service.getScmDateData(COMPONENT_KEY)).isNull(); | |||
} | |||
@@ -79,43 +79,43 @@ public class CoverageServiceTest { | |||
@Test | |||
public void get_hits_data() throws Exception { | |||
service.getHits(COMPONENT_KEY, CoverageService.TYPE.UT); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)); | |||
service.getHits(COMPONENT_KEY, CoverageService.TYPE.IT); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY)); | |||
service.getHits(COMPONENT_KEY, CoverageService.TYPE.OVERALL); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA_KEY)); | |||
} | |||
@Test | |||
public void not_get_hits_data_if_no_data() throws Exception { | |||
when(measureDao.getByKey(eq(session), any(MeasureKey.class))).thenReturn(null); | |||
when(measureDao.getNullableByKey(eq(session), any(MeasureKey.class))).thenReturn(null); | |||
assertThat(service.getHits(COMPONENT_KEY, CoverageService.TYPE.UT)).isEqualTo(Collections.emptyMap()); | |||
} | |||
@Test | |||
public void get_conditions_data() throws Exception { | |||
service.getConditions(COMPONENT_KEY, CoverageService.TYPE.UT); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.CONDITIONS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.CONDITIONS_BY_LINE_KEY)); | |||
service.getConditions(COMPONENT_KEY, CoverageService.TYPE.IT); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_CONDITIONS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_CONDITIONS_BY_LINE_KEY)); | |||
service.getConditions(COMPONENT_KEY, CoverageService.TYPE.OVERALL); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_CONDITIONS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_CONDITIONS_BY_LINE_KEY)); | |||
} | |||
@Test | |||
public void get_covered_conditions_data() throws Exception { | |||
service.getCoveredConditions(COMPONENT_KEY, CoverageService.TYPE.UT); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)); | |||
service.getCoveredConditions(COMPONENT_KEY, CoverageService.TYPE.IT); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY)); | |||
service.getCoveredConditions(COMPONENT_KEY, CoverageService.TYPE.OVERALL); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY)); | |||
verify(measureDao).getNullableByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY)); | |||
} | |||
@Test |