@@ -56,22 +56,22 @@ public class ComponentDao extends BaseDao<ComponentMapper, ComponentDto, String> | |||
} | |||
@Override | |||
protected ComponentDto doGetByKey(String key, DbSession session) { | |||
protected ComponentDto doGetByKey(DbSession session, String key) { | |||
return getMapper(session).selectByKey(key); | |||
} | |||
@Override | |||
protected ComponentDto doInsert(ComponentDto item, DbSession session) { | |||
protected ComponentDto doInsert(DbSession session, ComponentDto item) { | |||
throw notImplemented(); | |||
} | |||
@Override | |||
protected ComponentDto doUpdate(ComponentDto item, DbSession session) { | |||
protected ComponentDto doUpdate(DbSession session, ComponentDto item) { | |||
throw notImplemented(); | |||
} | |||
@Override | |||
protected void doDeleteByKey(String key, DbSession session) { | |||
protected void doDeleteByKey(DbSession session, String key) { | |||
throw notImplemented(); | |||
} | |||
@@ -80,7 +80,7 @@ public class ComponentDao extends BaseDao<ComponentMapper, ComponentDto, String> | |||
} | |||
@Override | |||
public void synchronizeAfter(long timestamp, DbSession session) { | |||
public void synchronizeAfter(DbSession session, long timestamp) { | |||
throw new IllegalStateException("Not implemented yet"); | |||
} | |||
} |
@@ -105,7 +105,7 @@ public class ComponentAppAction implements RequestHandler { | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
ComponentDto component = dbClient.componentDao().getByKey(fileKey, session); | |||
ComponentDto component = dbClient.componentDao().getByKey(session, fileKey); | |||
if (component == null) { | |||
throw new NotFoundException(String.format("Component '%s' does not exists.", fileKey)); | |||
} |
@@ -20,8 +20,8 @@ | |||
package org.sonar.server.db; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.core.persistence.DaoComponent; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.core.persistence.DaoComponent; | |||
import org.sonar.core.persistence.DbSession; | |||
import org.sonar.core.persistence.Dto; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
@@ -32,12 +32,9 @@ import org.sonar.server.search.action.IndexAction; | |||
import org.sonar.server.search.action.KeyIndexAction; | |||
import javax.annotation.Nullable; | |||
import java.io.Serializable; | |||
import java.util.ArrayList; | |||
import java.util.Collection; | |||
import java.util.Date; | |||
import java.util.List; | |||
/** | |||
* naming convention for DAO | |||
@@ -131,24 +128,24 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
return indexDefinition != null ? this.indexDefinition.getIndexType() : null; | |||
} | |||
protected abstract E doGetByKey(K key, DbSession session); | |||
protected abstract E doGetByKey(DbSession session, K key); | |||
protected abstract E doInsert(E item, DbSession session); | |||
protected abstract E doInsert(DbSession session, E item); | |||
protected abstract E doUpdate(E item, DbSession session); | |||
protected abstract E doUpdate(DbSession session, E item); | |||
protected abstract void doDeleteByKey(K key, DbSession session); | |||
protected abstract void doDeleteByKey(DbSession session, K key); | |||
protected M mapper(DbSession session) { | |||
return session.getMapper(mapperClass); | |||
} | |||
public E getByKey(K key, DbSession session) { | |||
return doGetByKey(key, session); | |||
public E getByKey(DbSession session, K key) { | |||
return doGetByKey(session, key); | |||
} | |||
public E getNonNullByKey(K key, DbSession session) { | |||
E value = doGetByKey(key, session); | |||
public E getNonNullByKey(DbSession session, K key) { | |||
E value = doGetByKey(session, key); | |||
if (value == null) { | |||
throw new NotFoundException(String.format("Key '%s' not found", key)); | |||
} | |||
@@ -156,30 +153,30 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
} | |||
@Override | |||
public E update(E item, DbSession session) { | |||
public E update(DbSession session, E item) { | |||
item.setUpdatedAt(new Date(system2.now())); | |||
this.doUpdate(item, session); | |||
doUpdate(session, item); | |||
if (hasIndex()) { | |||
session.enqueue(new DtoIndexAction<E>(this.getIndexType(), IndexAction.Method.UPSERT, item)); | |||
session.enqueue(new DtoIndexAction<E>(getIndexType(), IndexAction.Method.UPSERT, item)); | |||
} | |||
return item; | |||
} | |||
@Override | |||
public List<E> update(List<E> items, DbSession session) { | |||
public Collection<E> update(DbSession session, Collection<E> items) { | |||
//TODO check for bulk inserts | |||
List<E> results = new ArrayList<E>(); | |||
for (E item : items) { | |||
results.add(this.update(item, session)); | |||
update(session, item); | |||
} | |||
return items; | |||
} | |||
@Override | |||
public E insert(E item, DbSession session) { | |||
item.setCreatedAt(new Date(system2.now())); | |||
item.setUpdatedAt(item.getCreatedAt()); | |||
this.doInsert(item, session); | |||
public E insert(DbSession session, E 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)); | |||
} | |||
@@ -187,34 +184,32 @@ public abstract class BaseDao<M, E extends Dto<K>, K extends Serializable> imple | |||
} | |||
@Override | |||
public List<E> insert(List<E> items, DbSession session) { | |||
//TODO check for bulk inserts | |||
List<E> results = new ArrayList<E>(); | |||
public Collection<E> insert(DbSession session, Collection<E> items) { | |||
for (E item : items) { | |||
results.add(this.insert(item, session)); | |||
insert(session, item); | |||
} | |||
return items; | |||
} | |||
@Override | |||
public void delete(E item, DbSession session) { | |||
public void delete(DbSession session, E item) { | |||
Preconditions.checkNotNull(item.getKey(), "Dto does not have a valid Key"); | |||
deleteByKey(item.getKey(), session); | |||
deleteByKey(session, item.getKey()); | |||
} | |||
@Override | |||
public void delete(Collection<E> items, DbSession session) { | |||
public void delete(DbSession session, Collection<E> items) { | |||
for (E item : items) { | |||
delete(item, session); | |||
delete(session, item); | |||
} | |||
} | |||
@Override | |||
public void deleteByKey(K key, DbSession session) { | |||
Preconditions.checkNotNull(key, "cannot delete Item with null key"); | |||
doDeleteByKey(key, session); | |||
public void deleteByKey(DbSession session, K key) { | |||
Preconditions.checkNotNull(key, "Cannot delete item with null key"); | |||
doDeleteByKey(session, key); | |||
if (hasIndex()) { | |||
session.enqueue(new KeyIndexAction<K>(this.getIndexType(), IndexAction.Method.DELETE, key)); | |||
session.enqueue(new KeyIndexAction<K>(getIndexType(), IndexAction.Method.DELETE, key)); | |||
} | |||
} | |||
@@ -26,29 +26,28 @@ import org.sonar.core.persistence.Dto; | |||
import javax.annotation.CheckForNull; | |||
import java.io.Serializable; | |||
import java.util.Collection; | |||
import java.util.List; | |||
public interface Dao<E extends Dto<K>, K extends Serializable> extends ServerComponent { | |||
@CheckForNull | |||
E getByKey(K key, DbSession session); | |||
E getByKey(DbSession session, K key); | |||
E getNonNullByKey(K key, DbSession session); | |||
E getNonNullByKey(DbSession session, K key); | |||
E update(E item, DbSession session); | |||
E update(DbSession session, E item); | |||
List<E> update(List<E> items, DbSession session); | |||
Collection<E> update(DbSession session, Collection<E> items); | |||
E insert(E item, DbSession session); | |||
E insert(DbSession session, E item); | |||
List<E> insert(List<E> items, DbSession session); | |||
Collection<E> insert(DbSession session, Collection<E> items); | |||
void delete(E item, DbSession session); | |||
void delete(DbSession session, E item); | |||
void delete(Collection<E> items, DbSession session); | |||
void delete(DbSession session, Collection<E> items); | |||
void deleteByKey(K key, DbSession session); | |||
void deleteByKey(DbSession session, K key); | |||
void synchronizeAfter(long timestamp, DbSession session); | |||
void synchronizeAfter(DbSession session, long timestamp); | |||
} |
@@ -192,7 +192,7 @@ public class DebtModelBackup implements ServerComponent { | |||
rule.setRemediationCoefficient(null); | |||
rule.setRemediationOffset(null); | |||
rule.setUpdatedAt(updateDate); | |||
dbClient.ruleDao().update(rule, session); | |||
dbClient.ruleDao().update(session, rule); | |||
} | |||
} | |||
@@ -239,7 +239,7 @@ public class DebtModelOperations implements ServerComponent { | |||
ruleDto.setDefaultRemediationCoefficient(null); | |||
ruleDto.setDefaultRemediationOffset(null); | |||
} | |||
dbClient.ruleDao().update(ruleDto, session); | |||
dbClient.ruleDao().update(session, ruleDto); | |||
} | |||
} | |||
@@ -104,7 +104,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(componentKey, session); | |||
ComponentDto file = componentDao.getByKey(session, componentKey); | |||
if (file != null) { | |||
json.name(ref).beginObject(); | |||
json.prop("key", file.key()); |
@@ -82,7 +82,7 @@ public class ShowAction implements RequestHandler { | |||
@CheckForNull | |||
private String findDataFromComponent(String fileKey, String metricKey, DbSession session) { | |||
MeasureDto data = measureDao.getByKey(MeasureKey.of(fileKey, metricKey), session); | |||
MeasureDto data = measureDao.getByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
if (data != null) { | |||
return data.getData(); | |||
} |
@@ -48,7 +48,7 @@ public class MeasureDao extends BaseDao<MeasureMapper, MeasureDto, MeasureKey> i | |||
} | |||
@Override | |||
protected MeasureDto doGetByKey(MeasureKey key, DbSession session) { | |||
protected MeasureDto doGetByKey(DbSession session, MeasureKey key) { | |||
return session.getMapper(MeasureMapper.class).selectByKey(key); | |||
} | |||
@@ -69,22 +69,22 @@ public class MeasureDao extends BaseDao<MeasureMapper, MeasureDto, MeasureKey> i | |||
} | |||
@Override | |||
protected MeasureDto doInsert(MeasureDto item, DbSession session) { | |||
protected MeasureDto doInsert(DbSession session, MeasureDto item) { | |||
throw new IllegalStateException("Not implemented yet"); | |||
} | |||
@Override | |||
protected MeasureDto doUpdate(MeasureDto item, DbSession session) { | |||
protected MeasureDto doUpdate(DbSession session, MeasureDto item) { | |||
throw new IllegalStateException("Not implemented yet"); | |||
} | |||
@Override | |||
protected void doDeleteByKey(MeasureKey key, DbSession session) { | |||
protected void doDeleteByKey(DbSession session, MeasureKey key) { | |||
throw new IllegalStateException("Not implemented yet"); | |||
} | |||
@Override | |||
public void synchronizeAfter(long timestamp, DbSession session) { | |||
public void synchronizeAfter(DbSession session, long timestamp) { | |||
throw new IllegalStateException("Not implemented yet"); | |||
} | |||
} |
@@ -129,7 +129,7 @@ public class ActiveRuleService implements ServerComponent { | |||
if (change.getType() == ActiveRuleChange.Type.ACTIVATED) { | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(context.profile(), context.rule()); | |||
activeRule.setSeverity(change.getSeverity()); | |||
dao.insert(activeRule, dbSession); | |||
dao.insert(dbSession, activeRule); | |||
for (Map.Entry<String, String> param : change.getParameters().entrySet()) { | |||
ActiveRuleParamDto paramDto = ActiveRuleParamDto.createFor(context.ruleParamsByKeys().get(param.getKey())); | |||
paramDto.setValue(param.getValue()); | |||
@@ -137,12 +137,12 @@ public class ActiveRuleService implements ServerComponent { | |||
} | |||
} else if (change.getType() == ActiveRuleChange.Type.DEACTIVATED) { | |||
dao.deleteByKey(change.getKey(), dbSession); | |||
dao.deleteByKey(dbSession, change.getKey()); | |||
} else if (change.getType() == ActiveRuleChange.Type.UPDATED) { | |||
ActiveRuleDto activeRule = context.activeRule(); | |||
activeRule.setSeverity(change.getSeverity()); | |||
dao.update(activeRule, dbSession); | |||
dao.update(dbSession, activeRule); | |||
for (Map.Entry<String, String> param : change.getParameters().entrySet()) { | |||
ActiveRuleParamDto activeRuleParamDto = context.activeRuleParamsAsMap().get(param.getKey()); |
@@ -62,12 +62,12 @@ public class QProfileActiveRuleOperations implements ServerComponent { | |||
} | |||
ActiveRuleDto createActiveRule(QualityProfileKey profileKey, RuleKey ruleKey, String severity, DbSession session) { | |||
RuleDto ruleDto = ruleDao.getByKey(ruleKey, session); | |||
RuleDto ruleDto = ruleDao.getByKey(session, ruleKey); | |||
//TODO use BaseDao for profileDao | |||
QualityProfileDto profileDto = profileDao.selectByNameAndLanguage(profileKey.name(), profileKey.lang(), session); | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) | |||
.setSeverity(severity); | |||
activeRuleDao.insert(activeRule, session); | |||
activeRuleDao.insert(session, activeRule); | |||
List<RuleParamDto> ruleParams = ruleDao.findRuleParamsByRuleKey(ruleKey, session); | |||
List<ActiveRuleParamDto> activeRuleParams = newArrayList(); |
@@ -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(ruleKey, session); | |||
RuleDto rule = ruleDao.getByKey(session, ruleKey); | |||
if (rule == null) { | |||
throw new NotFoundException(String.format("Rule '%s' does not exists.", ruleKey)); | |||
} |
@@ -62,7 +62,7 @@ public class RuleActivationContextFactory implements ServerComponent { | |||
} | |||
private RuleDto initRule(RuleKey ruleKey, RuleActivationContext context, DbSession dbSession) { | |||
RuleDto rule = db.ruleDao().getByKey(ruleKey, dbSession); | |||
RuleDto rule = db.ruleDao().getByKey(dbSession, ruleKey); | |||
if (rule == null) { | |||
throw new IllegalArgumentException("Rule not found: " + ruleKey); | |||
} | |||
@@ -89,7 +89,7 @@ public class RuleActivationContextFactory implements ServerComponent { | |||
} | |||
private void initActiveRules(ActiveRuleKey key, RuleActivationContext context, DbSession session, boolean parent) { | |||
ActiveRuleDto activeRule = db.activeRuleDao().getByKey(key, session); | |||
ActiveRuleDto activeRule = db.activeRuleDao().getByKey(session, key); | |||
Collection<ActiveRuleParamDto> activeRuleParams = null; | |||
if (activeRule != null) { | |||
activeRuleParams = db.activeRuleDao().findParamsByActiveRule(activeRule, session); |
@@ -92,7 +92,7 @@ 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(key, dbSession))); | |||
requests.addAll(normalize(db.activeRuleDao().getByKey(dbSession, key))); | |||
for (ActiveRuleParamDto param : db.activeRuleDao().findParamsByKey(key, dbSession)) { | |||
requests.addAll(this.normalize(param, key)); | |||
} |
@@ -63,7 +63,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
} | |||
@Override | |||
public void synchronizeAfter(long timestamp, final DbSession session) { | |||
public void synchronizeAfter(final DbSession session, long timestamp) { | |||
session.select("selectAllKeysAfterTimestamp", new Timestamp(timestamp), new ResultHandler() { | |||
@Override | |||
public void handleResult(ResultContext context) { | |||
@@ -90,13 +90,13 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
} | |||
@Override | |||
protected ActiveRuleDto doGetByKey(ActiveRuleKey key, DbSession session) { | |||
protected ActiveRuleDto doGetByKey(DbSession session, ActiveRuleKey key) { | |||
return mapper(session).selectByKey(key.qProfile().name(), key.qProfile().lang(), | |||
key.ruleKey().repository(), key.ruleKey().rule()); | |||
} | |||
@Override | |||
protected ActiveRuleDto doInsert(ActiveRuleDto item, DbSession session) { | |||
protected ActiveRuleDto doInsert(DbSession session, ActiveRuleDto item) { | |||
Preconditions.checkArgument(item.getProfileId() != null, "Quality profile is not persisted (missing id)"); | |||
Preconditions.checkArgument(item.getRulId() != null, "Rule is not persisted (missing id)"); | |||
Preconditions.checkArgument(item.getId() == null, "ActiveRule is already persisted"); | |||
@@ -105,7 +105,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
} | |||
@Override | |||
protected ActiveRuleDto doUpdate(ActiveRuleDto item, DbSession session) { | |||
protected ActiveRuleDto doUpdate(DbSession session, ActiveRuleDto item) { | |||
Preconditions.checkArgument(item.getProfileId() != null, "Quality profile is not persisted (missing id)"); | |||
Preconditions.checkArgument(item.getRulId() != null, "Rule is not persisted (missing id)"); | |||
Preconditions.checkArgument(item.getId() != null, "ActiveRule is not persisted"); | |||
@@ -114,8 +114,8 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
} | |||
@Override | |||
protected void doDeleteByKey(ActiveRuleKey key, DbSession session) { | |||
ActiveRuleDto rule = this.getByKey(key, session); | |||
protected void doDeleteByKey(DbSession session, ActiveRuleKey key) { | |||
ActiveRuleDto rule = this.getByKey(session, key); | |||
mapper(session).deleteParameters(rule.getId()); | |||
mapper(session).delete(rule.getId()); | |||
} | |||
@@ -162,7 +162,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
public void removeParamByKeyAndName(ActiveRuleKey key, String param, DbSession session) { | |||
//TODO SQL rewrite to delete by key | |||
ActiveRuleDto activeRule = this.getByKey(key, session); | |||
ActiveRuleDto activeRule = this.getByKey(session, key); | |||
ActiveRuleParamDto activeRuleParam = mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), param); | |||
Preconditions.checkArgument(activeRuleParam.getId() != null, "ActiveRuleParam does not exist"); | |||
mapper(session).deleteParameter(activeRuleParam.getId()); | |||
@@ -184,7 +184,7 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
public void deleteByProfileKey(QualityProfileKey profileKey, DbSession session) { | |||
/** Functional cascade for params */ | |||
for (ActiveRuleDto activeRule : this.findByProfileKey(profileKey, session)) { | |||
delete(activeRule, session); | |||
delete(session, activeRule); | |||
} | |||
} | |||
@@ -209,14 +209,14 @@ public class ActiveRuleDao extends BaseDao<ActiveRuleMapper, ActiveRuleDto, Acti | |||
public List<ActiveRuleParamDto> findParamsByKey(ActiveRuleKey key, DbSession session) { | |||
Preconditions.checkArgument(key != null, "ActiveRuleKey cannot be null"); | |||
ActiveRuleDto activeRule = this.getByKey(key, session); | |||
ActiveRuleDto activeRule = this.getByKey(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(key, session); | |||
ActiveRuleDto activeRule = this.getByKey(session, key); | |||
return mapper(session).selectParamByActiveRuleAndKey(activeRule.getId(), name); | |||
} | |||
@@ -117,7 +117,7 @@ public class RegisterRules implements Startable { | |||
} | |||
if (executeUpdate) { | |||
dbClient.ruleDao().update(rule, session); | |||
dbClient.ruleDao().update(session, rule); | |||
} else { | |||
// TODO replace this hack by index synchronizer | |||
session.enqueue(new KeyIndexAction<RuleKey>(IndexDefinition.RULE.getIndexType(), | |||
@@ -179,7 +179,7 @@ public class RegisterRules implements Startable { | |||
.setEffortToFixDescription(ruleDef.effortToFixDescription()) | |||
.setSystemTags(ruleDef.tags()); | |||
return dbClient.ruleDao().insert(ruleDto, session); | |||
return dbClient.ruleDao().insert(session, ruleDto); | |||
} | |||
private boolean mergeRule(RulesDefinition.Rule def, RuleDto dto) { | |||
@@ -347,7 +347,7 @@ public class RegisterRules implements Startable { | |||
ruleDto.setDefaultRemediationCoefficient(parent.getDefaultRemediationCoefficient()); | |||
ruleDto.setDefaultRemediationOffset(parent.getDefaultRemediationOffset()); | |||
ruleDto.setEffortToFixDescription(parent.getEffortToFixDescription()); | |||
dbClient.ruleDao().update(ruleDto, session); | |||
dbClient.ruleDao().update(session, ruleDto); | |||
toBeRemoved = false; | |||
} | |||
} | |||
@@ -356,7 +356,7 @@ public class RegisterRules implements Startable { | |||
ruleDto.setStatus(Rule.STATUS_REMOVED); | |||
ruleDto.setSystemTags(Collections.EMPTY_SET); | |||
ruleDto.setTags(Collections.EMPTY_SET); | |||
dbClient.ruleDao().update(ruleDto, session); | |||
dbClient.ruleDao().update(session, ruleDto); | |||
removedRules.add(ruleDto); | |||
if (removedRules.size() % 100 == 0) { | |||
session.commit(); |
@@ -66,7 +66,7 @@ public class RuleOperations implements ServerComponent { | |||
checkPermission(userSession); | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
RuleDto ruleDto = dbClient.ruleDao().getByKey(ruleChange.ruleKey(), session); | |||
RuleDto ruleDto = dbClient.ruleDao().getByKey(session, ruleChange.ruleKey()); | |||
if (ruleDto == null) { | |||
throw new NotFoundException(String.format("Unknown rule '%s'", ruleChange.ruleKey())); | |||
} | |||
@@ -132,7 +132,7 @@ public class RuleOperations implements ServerComponent { | |||
} | |||
if (needUpdate) { | |||
dbClient.ruleDao().update(ruleDto, session); | |||
dbClient.ruleDao().update(session, ruleDto); | |||
} | |||
return needUpdate; | |||
} |
@@ -83,10 +83,10 @@ public class RuleService implements ServerComponent { | |||
DbSession dbSession = db.openSession(false); | |||
try { | |||
RuleDto rule = db.ruleDao().getNonNullByKey(ruleKey, dbSession); | |||
RuleDto rule = db.ruleDao().getNonNullByKey(dbSession, ruleKey); | |||
boolean changed = RuleTagHelper.applyTags(rule, tags); | |||
if (changed) { | |||
db.ruleDao().update(rule, dbSession); | |||
db.ruleDao().update(dbSession, rule); | |||
dbSession.commit(); | |||
} | |||
} finally { | |||
@@ -105,7 +105,7 @@ public class RuleService implements ServerComponent { | |||
checkAdminPermission(userSession); | |||
DbSession dbSession = db.openSession(false); | |||
try { | |||
RuleDto rule = db.ruleDao().getNonNullByKey(ruleKey, dbSession); | |||
RuleDto rule = db.ruleDao().getNonNullByKey(dbSession, ruleKey); | |||
if (StringUtils.isBlank(markdownNote)) { | |||
rule.setNoteData(null); | |||
rule.setNoteCreatedAt(null); | |||
@@ -117,7 +117,7 @@ public class RuleService implements ServerComponent { | |||
rule.setNoteUpdatedAt(new Date()); | |||
rule.setNoteUserLogin(userSession.login()); | |||
} | |||
db.ruleDao().update(rule, dbSession); | |||
db.ruleDao().update(dbSession, rule); | |||
dbSession.commit(); | |||
} finally { | |||
dbSession.close(); |
@@ -53,7 +53,7 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
@CheckForNull | |||
@Override | |||
public RuleDto doGetByKey(RuleKey key, DbSession session) { | |||
public RuleDto doGetByKey(DbSession session, RuleKey key) { | |||
return mapper(session).selectByKey(key); | |||
} | |||
@@ -62,19 +62,19 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
} | |||
@Override | |||
protected RuleDto doInsert(RuleDto item, DbSession session) { | |||
protected RuleDto doInsert(DbSession session, RuleDto item) { | |||
mapper(session).insert(item); | |||
return item; | |||
} | |||
@Override | |||
protected RuleDto doUpdate(RuleDto item, DbSession session) { | |||
protected RuleDto doUpdate(DbSession session, RuleDto item) { | |||
mapper(session).update(item); | |||
return item; | |||
} | |||
@Override | |||
protected void doDeleteByKey(RuleKey key, DbSession session) { | |||
protected void doDeleteByKey(DbSession session, RuleKey key) { | |||
throw new UnsupportedOperationException("Rules cannot be deleted"); | |||
} | |||
@@ -92,7 +92,7 @@ public class RuleDao extends BaseDao<RuleMapper, RuleDto, RuleKey> { | |||
@Override | |||
public void synchronizeAfter(long timestamp, final DbSession session) { | |||
public void synchronizeAfter(final DbSession session, long timestamp) { | |||
session.select("selectKeysOfRulesUpdatedSince", new Timestamp(timestamp), new ResultHandler() { | |||
@Override | |||
public void handleResult(ResultContext context) { |
@@ -134,7 +134,7 @@ 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(key, dbSession))); | |||
requests.addAll(normalize(db.ruleDao().getByKey(dbSession, key))); | |||
for (RuleParamDto param : db.ruleDao().findRuleParamsByRuleKey(key, dbSession)) { | |||
requests.addAll(normalize(param, key)); | |||
} |
@@ -46,7 +46,7 @@ public class IndexSynchronizer implements Startable { | |||
DbSession session = db.openSession(true); | |||
LOG.info("Starting DB to Index synchronization"); | |||
long start = System.currentTimeMillis(); | |||
db.activeRuleDao().synchronizeAfter(0, session); | |||
db.activeRuleDao().synchronizeAfter(session, 0); | |||
LOG.info("Synchronization done in {}ms...", (System.currentTimeMillis()-start)); | |||
session.close(); | |||
} |
@@ -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(MeasureKey.of(fileKey, metricKey), session); | |||
MeasureDto data = dbClient.measureDao().getByKey(session, MeasureKey.of(fileKey, metricKey)); | |||
if (data != null) { | |||
return data.getData(); | |||
} |
@@ -137,7 +137,7 @@ public class CopyRequirementsFromCharacteristicsToRules implements ServerCompone | |||
rule.setRemediationFunction(null); | |||
rule.setRemediationCoefficient(null); | |||
rule.setRemediationOffset(null); | |||
dbClient.ruleDao().update(rule, session); | |||
dbClient.ruleDao().update(session, rule); | |||
} | |||
private void convertEnabledRequirement(RuleDto ruleRow, RequirementDto enabledRequirement, DbSession session) { | |||
@@ -167,7 +167,7 @@ public class CopyRequirementsFromCharacteristicsToRules implements ServerCompone | |||
if (!isDebtDefaultValuesSameAsOverriddenValues(ruleRow)) { | |||
// Default values on debt are not the same that ones set by SQALE, update the rule | |||
dbClient.ruleDao().update(ruleRow, session); | |||
dbClient.ruleDao().update(session, ruleRow); | |||
} | |||
} | |||
@@ -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(MeasureKey.of(fileKey, metricKey), session); | |||
MeasureDto data = measureDao.getByKey(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("org.struts:struts-core:src/org/struts/RequestContext.java", session); | |||
ComponentDto result = dao.getByKey(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("unknown", session)).isNull(); | |||
assertThat(dao.getByKey(session, "unknown")).isNull(); | |||
} | |||
@Test | |||
public void get_by_key_on_a_root_project() { | |||
setupData("shared"); | |||
ComponentDto result = dao.getByKey("org.struts:struts", session); | |||
ComponentDto result = dao.getByKey(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(COMPONENT_KEY, session)).thenReturn(file); | |||
when(componentDao.getByKey(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(componentKey, session)).thenReturn(file); | |||
when(componentDao.getByKey(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(COMPONENT_KEY, session)).thenReturn(file); | |||
when(componentDao.getByKey(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(COMPONENT_KEY, session)).thenReturn(file); | |||
when(componentDao.getByKey(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("ki", dbSession)).thenReturn(dto); | |||
when(dao.getNonNullByKey(anyString(), any(DbSession.class))).thenCallRealMethod(); | |||
when(dao.doGetByKey(dbSession, "ki")).thenReturn(dto); | |||
when(dao.getNonNullByKey(any(DbSession.class), anyString())).thenCallRealMethod(); | |||
assertThat(dao.getNonNullByKey("ki", dbSession)).isSameAs(dto); | |||
assertThat(dao.getNonNullByKey(dbSession, "ki")).isSameAs(dto); | |||
try { | |||
dao.getNonNullByKey("unknown", dbSession); | |||
dao.getNonNullByKey(dbSession, "unknown"); | |||
fail(); | |||
} catch (NotFoundException e) { | |||
assertThat(e).hasMessage("Key 'unknown' not found"); |
@@ -454,7 +454,7 @@ public class DebtModelBackupTest { | |||
verifyNoMoreInteractions(dao); | |||
verify(ruleDao).selectEnabledAndNonManual(session); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verifyNoMoreInteractions(ruleDao); | |||
verify(session).commit(); | |||
@@ -513,7 +513,7 @@ public class DebtModelBackupTest { | |||
verifyNoMoreInteractions(dao); | |||
verify(ruleDao).selectEnabledAndNonManual(session); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verifyNoMoreInteractions(ruleDao); | |||
verify(session).commit(); | |||
@@ -568,7 +568,7 @@ public class DebtModelBackupTest { | |||
debtModelBackup.reset(); | |||
verify(ruleDao).selectEnabledAndNonManual(session); | |||
verify(ruleDao, times(2)).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao, times(2)).update(eq(session), ruleCaptor.capture()); | |||
verifyNoMoreInteractions(ruleDao); | |||
verify(session).commit(); | |||
@@ -608,7 +608,7 @@ public class DebtModelBackupTest { | |||
verifyNoMoreInteractions(dao); | |||
verify(ruleDao).selectEnabledAndNonManual(session); | |||
verify(ruleDao, never()).update(any(RuleDto.class), eq(session)); | |||
verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); | |||
verifyZeroInteractions(defLoader); | |||
verify(session).commit(); |
@@ -368,7 +368,7 @@ public class DebtModelOperationsTest { | |||
service.delete(2); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(batchSession)); | |||
verify(ruleDao).update(eq(batchSession), ruleCaptor.capture()); | |||
RuleDto ruleDto = ruleCaptor.getValue(); | |||
assertThat(ruleDto.getUpdatedAt()).isEqualTo(now); | |||
@@ -408,7 +408,7 @@ public class DebtModelOperationsTest { | |||
service.delete(2); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(batchSession)); | |||
verify(ruleDao).update(eq(batchSession), ruleCaptor.capture()); | |||
RuleDto ruleDto = ruleCaptor.getValue(); | |||
// Default debt data are disabled | |||
@@ -450,7 +450,7 @@ public class DebtModelOperationsTest { | |||
service.delete(1); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(batchSession)); | |||
verify(ruleDao).update(eq(batchSession), ruleCaptor.capture()); | |||
verify(dao, times(2)).update(characteristicCaptor.capture(), eq(batchSession)); | |||
CharacteristicDto subCharacteristicDto = characteristicCaptor.getAllValues().get(0); |
@@ -64,8 +64,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(key1, session)).thenReturn(file1); | |||
when(componentDao.getByKey(key2, session)).thenReturn(file2); | |||
when(componentDao.getByKey(session, key1)).thenReturn(file1); | |||
when(componentDao.getByKey(session, key2)).thenReturn(file2); | |||
when(componentDao.getById(1L, session)).thenReturn(new ComponentDto().setId(1L).setLongName("SonarQube")); | |||
test( | |||
@@ -103,7 +103,7 @@ public class DuplicationsWriterTest { | |||
"}" | |||
); | |||
verify(componentDao, times(2)).getByKey(anyString(), eq(session)); | |||
verify(componentDao, times(2)).getByKey(eq(session), anyString()); | |||
verify(componentDao, times(1)).getById(anyLong(), eq(session)); | |||
} | |||
@@ -69,7 +69,7 @@ public class ShowActionTest { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "org.codehaus.sonar:sonar", componentKey); | |||
MeasureKey measureKey = MeasureKey.of(componentKey, CoreMetrics.DUPLICATIONS_DATA_KEY); | |||
when(measureDao.getByKey(measureKey, session)).thenReturn( | |||
when(measureDao.getByKey(session, measureKey)).thenReturn( | |||
MeasureDto.createFor(measureKey).setTextValue("{duplications}") | |||
); | |||
@@ -85,7 +85,7 @@ public class ShowActionTest { | |||
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, "org.codehaus.sonar:sonar", componentKey); | |||
MeasureKey measureKey = MeasureKey.of(componentKey, CoreMetrics.DUPLICATIONS_DATA_KEY); | |||
when(measureDao.getByKey(measureKey, session)).thenReturn(null); | |||
when(measureDao.getByKey(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(MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "ncloc"), session); | |||
MeasureDto result = dao.getByKey(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(MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "authors_by_line"), session); | |||
MeasureDto result = dao.getByKey(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(MeasureKey.of("org.struts:struts-core:src/org/struts/RequestContext.java", "coverage_line_hits_data"), session); | |||
MeasureDto result = dao.getByKey(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"); | |||
} |
@@ -360,10 +360,10 @@ public class ActiveRuleServiceMediumTest { | |||
dbClient.qualityProfileDao().insert(dbSession, profile1); | |||
RuleDto rule1 = RuleDto.createFor(RuleKey.of("java", "r1")).setSeverity(Severity.MAJOR); | |||
dbClient.ruleDao().insert(rule1, dbSession); | |||
dbClient.ruleDao().insert(dbSession, rule1); | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile1, rule1).setSeverity("BLOCKER"); | |||
dbClient.activeRuleDao().insert(activeRule, dbSession); | |||
dbClient.activeRuleDao().insert(dbSession, activeRule); | |||
dbSession.commit(); | |||
tester.clearIndexes(); | |||
@@ -372,7 +372,7 @@ public class ActiveRuleServiceMediumTest { | |||
assertThat(index.getByKey(activeRule.getKey())).isNull(); | |||
// 1. Synchronize since 0 | |||
dbClient.activeRuleDao().synchronizeAfter(0,dbSession); | |||
dbClient.activeRuleDao().synchronizeAfter(dbSession, 0); | |||
// 2. Assert that we have the rule in Index | |||
assertThat(index.getByKey(activeRule.getKey())).isNotNull(); | |||
@@ -387,12 +387,12 @@ public class ActiveRuleServiceMediumTest { | |||
RuleDto rule1 = RuleDto.createFor(RuleKey.of("java", "r1")).setSeverity(Severity.MAJOR); | |||
RuleDto rule2 = RuleDto.createFor(RuleKey.of("java", "r2")).setSeverity(Severity.MAJOR); | |||
dbClient.ruleDao().insert(rule1, dbSession); | |||
dbClient.ruleDao().insert(rule2, dbSession); | |||
dbClient.ruleDao().insert(dbSession, rule1); | |||
dbClient.ruleDao().insert(dbSession, rule2); | |||
dbClient.activeRuleDao().insert(ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR), dbSession); | |||
dbClient.activeRuleDao().insert(ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER), dbSession); | |||
dbClient.activeRuleDao().insert(ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL), dbSession); | |||
dbClient.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule1).setSeverity(Severity.MINOR)); | |||
dbClient.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile1, rule2).setSeverity(Severity.BLOCKER)); | |||
dbClient.activeRuleDao().insert(dbSession, ActiveRuleDto.createFor(profile2, rule2).setSeverity(Severity.CRITICAL)); | |||
dbSession.commit(); | |||
// find by rule key |
@@ -316,7 +316,7 @@ public class QProfileBackupTest { | |||
when(profileDefinition.createProfile(any(ValidationMessages.class))).thenReturn(profile); | |||
definitions.add(profileDefinition); | |||
when(ruleDao.getByKey(RuleKey.of("pmd", "rule"), session)).thenReturn(new RuleDto().setId(10).setSeverity("INFO")); | |||
when(ruleDao.getByKey(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(RuleKey.of("pmd", "rule"), session)).thenReturn(new RuleDto().setId(10).setSeverity("INFO")); | |||
when(ruleDao.getByKey(RuleKey.of("checkstyle", "rule"), session)).thenReturn(new RuleDto().setId(11).setSeverity("INFO")); | |||
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(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(RuleKey.of("pmd", "rule"), session)).thenReturn(null); | |||
when(ruleDao.getByKey(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)); | |||
@@ -111,7 +111,7 @@ public class QProfileOperationsTest { | |||
dto.setId(currentId++); | |||
return null; | |||
} | |||
}).when(activeRuleDao).insert(any(ActiveRuleDto.class), any(DbSession.class)); | |||
}).when(activeRuleDao).insert(any(DbSession.class), any(ActiveRuleDto.class)); | |||
doAnswer(new Answer() { | |||
public Object answer(InvocationOnMock invocation) { | |||
Object[] args = invocation.getArguments(); |
@@ -21,7 +21,6 @@ | |||
package org.sonar.server.qualityprofile; | |||
import org.junit.After; | |||
import org.junit.Ignore; | |||
import org.junit.Test; | |||
import org.sonar.api.profiles.ProfileDefinition; | |||
import org.sonar.api.profiles.RulesProfile; | |||
@@ -130,7 +129,7 @@ public class RegisterQualityProfilesMediumTest { | |||
assertThat(activeRuleDao.findByProfileKey(qualityProfileKey, dbSession)).hasSize(2); | |||
RuleKey ruleKey = RuleKey.of("xoo", "x1"); | |||
ActiveRuleDto activeRule = activeRuleDao.getByKey(ActiveRuleKey.of(qualityProfileKey, ruleKey), dbSession); | |||
ActiveRuleDto activeRule = activeRuleDao.getByKey(dbSession, ActiveRuleKey.of(qualityProfileKey, ruleKey)); | |||
assertThat(activeRule.getKey().qProfile()).isEqualTo(qualityProfileKey); | |||
assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey); | |||
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL); |
@@ -79,13 +79,13 @@ public class ActiveRuleIndexMediumTest { | |||
// insert db | |||
RuleKey ruleKey = RuleKey.of("javascript", "S001"); | |||
RuleDto ruleDto = newRuleDto(ruleKey); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
.setSeverity(Severity.BLOCKER); | |||
activeRuleDao.insert(activeRule, dbSession); | |||
activeRuleDao.insert(dbSession, activeRule); | |||
dbSession.commit(); | |||
// verify that activeRules are persisted in db | |||
@@ -115,7 +115,7 @@ public class ActiveRuleIndexMediumTest { | |||
// insert db | |||
RuleKey ruleKey = RuleKey.of("javascript", "S001"); | |||
RuleDto ruleDto = newRuleDto(ruleKey); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
RuleParamDto minParam = new RuleParamDto() | |||
.setName("min") | |||
@@ -131,7 +131,7 @@ public class ActiveRuleIndexMediumTest { | |||
ActiveRuleDto activeRule = ActiveRuleDto.createFor(profileDto, ruleDto) | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
.setSeverity(Severity.BLOCKER); | |||
activeRuleDao.insert(activeRule, dbSession); | |||
activeRuleDao.insert(dbSession, activeRule); | |||
ActiveRuleParamDto activeRuleMinParam = ActiveRuleParamDto.createFor(minParam) | |||
.setValue("minimum"); | |||
@@ -166,11 +166,11 @@ public class ActiveRuleIndexMediumTest { | |||
// insert db | |||
RuleDto ruleDto = newRuleDto(RuleKey.of("javascript", "S001")); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
// insert db | |||
RuleDto ruleDto2 = newRuleDto(RuleKey.of("javascript", "S002")); | |||
dao.insert(ruleDto2, dbSession); | |||
dao.insert(dbSession, ruleDto2); | |||
ActiveRuleDto find1 = ActiveRuleDto.createFor(profile1, ruleDto) | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
@@ -184,9 +184,9 @@ public class ActiveRuleIndexMediumTest { | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
.setSeverity(Severity.BLOCKER); | |||
activeRuleDao.insert(find1, dbSession); | |||
activeRuleDao.insert(find2, dbSession); | |||
activeRuleDao.insert(notFound, dbSession); | |||
activeRuleDao.insert(dbSession, find1); | |||
activeRuleDao.insert(dbSession, find2); | |||
activeRuleDao.insert(dbSession, notFound); | |||
dbSession.commit(); | |||
// verify that activeRules are persisted in db | |||
@@ -218,9 +218,9 @@ public class ActiveRuleIndexMediumTest { | |||
// insert db | |||
RuleDto rule1 = newRuleDto(RuleKey.of("javascript", "S001")); | |||
dao.insert(rule1, dbSession); | |||
dao.insert(dbSession, rule1); | |||
RuleDto rule2 = newRuleDto(RuleKey.of("javascript", "S002")); | |||
dao.insert(rule2, dbSession); | |||
dao.insert(dbSession, rule2); | |||
ActiveRuleDto onP1 = ActiveRuleDto.createFor(profileDto, rule1) | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
@@ -234,9 +234,9 @@ public class ActiveRuleIndexMediumTest { | |||
.setInheritance(ActiveRule.Inheritance.INHERIT.name()) | |||
.setSeverity(Severity.BLOCKER); | |||
activeRuleDao.insert(onP1, dbSession); | |||
activeRuleDao.insert(firstOnP1, dbSession); | |||
activeRuleDao.insert(firstOnP2, dbSession); | |||
activeRuleDao.insert(dbSession, onP1); | |||
activeRuleDao.insert(dbSession, firstOnP1); | |||
activeRuleDao.insert(dbSession, firstOnP2); | |||
dbSession.commit(); | |||
// verify that activeRules are persisted in db |
@@ -63,15 +63,15 @@ public class ActiveRuleDaoTest extends AbstractDaoTestCase{ | |||
qualityProfileDao.insert(session, profile); | |||
RuleDto rule = RuleDto.createFor(RuleKey.of("repo","rule")); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(profile, rule) | |||
.setSeverity("BLOCKER"); | |||
activeRuleDao.insert(activeRuleDto, session); | |||
activeRuleDao.insert(session, activeRuleDto); | |||
session.commit(); | |||
ActiveRuleDto result = activeRuleDao.getByKey(activeRuleDto.getKey(), session); | |||
ActiveRuleDto result = activeRuleDao.getByKey(session, activeRuleDto.getKey()); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.getKey()).isNotNull(); |
@@ -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(ruleKey1, dbSession); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
assertThat(rule1.getName()).isEqualTo("One"); | |||
assertThat(rule1.getDescription()).isEqualTo("Description of One"); | |||
assertThat(rule1.getSeverityString()).isEqualTo(Severity.BLOCKER); | |||
@@ -110,7 +110,7 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
execute(new FakeRepositoryV1()); | |||
RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
assertThat(rule1.getCreatedAt()).isEqualTo(DATE1); | |||
assertThat(rule1.getUpdatedAt()).isEqualTo(DATE1); | |||
} | |||
@@ -122,18 +122,18 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
// user adds tags and sets markdown note | |||
RuleKey ruleKey1 = RuleKey.of("fake", "rule1"); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession); | |||
RuleDto rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
rule1.setTags(Sets.newHashSet("usertag1", "usertag2")); | |||
rule1.setNoteData("user *note*"); | |||
rule1.setNoteUserLogin("marius"); | |||
dbClient.ruleDao().update(rule1, dbSession); | |||
dbClient.ruleDao().update(dbSession, rule1); | |||
dbSession.commit(); | |||
when(system.now()).thenReturn(DATE2.getTime()); | |||
execute(new FakeRepositoryV2()); | |||
// rule1 has been updated | |||
rule1 = dbClient.ruleDao().getByKey(ruleKey1, dbSession); | |||
rule1 = dbClient.ruleDao().getByKey(dbSession, ruleKey1); | |||
assertThat(rule1.getName()).isEqualTo("One v2"); | |||
assertThat(rule1.getDescription()).isEqualTo("Description of One v2"); | |||
assertThat(rule1.getSeverityString()).isEqualTo(Severity.INFO); | |||
@@ -154,12 +154,12 @@ public class RegisterRulesTest extends AbstractDaoTestCase { | |||
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(RuleKey.of("fake", "rule2"), dbSession); | |||
RuleDto rule2 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule2")); | |||
assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED.toString()); | |||
assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2); | |||
// rule3 has been created | |||
RuleDto rule3 = dbClient.ruleDao().getByKey(RuleKey.of("fake", "rule3"), dbSession); | |||
RuleDto rule3 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule3")); | |||
assertThat(rule3).isNotNull(); | |||
assertThat(rule3.getStatus()).isEqualTo(RuleStatus.READY.toString()); | |||
} | |||
@@ -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(RuleKey.of("fake", "rule2"), dbSession); | |||
RuleDto rule2 = dbClient.ruleDao().getByKey(dbSession, RuleKey.of("fake", "rule2")); | |||
assertThat(rule2.getStatus()).isEqualTo(RuleStatus.REMOVED.toString()); | |||
assertThat(rule2.getUpdatedAt()).isEqualTo(DATE2); | |||
} |
@@ -74,11 +74,11 @@ public class RuleDataMediumTest { | |||
public void insert_in_db_and_index_in_es() throws InterruptedException { | |||
// insert db | |||
RuleKey ruleKey = RuleKey.of("javascript", "S001"); | |||
dao.insert(newRuleDto(ruleKey), dbSession); | |||
dao.insert(dbSession, newRuleDto(ruleKey)); | |||
dbSession.commit(); | |||
// verify that rule is persisted in db | |||
RuleDto persistedDto = dao.getByKey(ruleKey, dbSession); | |||
RuleDto persistedDto = dao.getByKey(dbSession, ruleKey); | |||
assertThat(persistedDto).isNotNull(); | |||
assertThat(persistedDto.getId()).isGreaterThanOrEqualTo(0); | |||
assertThat(persistedDto.getRuleKey()).isEqualTo(ruleKey.rule()); | |||
@@ -112,7 +112,7 @@ public class RuleDataMediumTest { | |||
// insert db | |||
RuleKey ruleKey = RuleKey.of("javascript", "S001"); | |||
RuleDto ruleDto = newRuleDto(ruleKey); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
dbSession.commit(); | |||
RuleParamDto minParamDto = new RuleParamDto() | |||
@@ -130,7 +130,7 @@ public class RuleDataMediumTest { | |||
dbSession.commit(); | |||
//Verify that RuleDto has date from insertion | |||
RuleDto theRule = dao.getByKey(ruleKey, dbSession); | |||
RuleDto theRule = dao.getByKey(dbSession, ruleKey); | |||
assertThat(theRule.getCreatedAt()).isNotNull(); | |||
assertThat(theRule.getUpdatedAt()).isNotNull(); | |||
@@ -158,7 +158,7 @@ public class RuleDataMediumTest { | |||
RuleDto ruleDto = newRuleDto(ruleKey) | |||
.setTags(ImmutableSet.of("hello")) | |||
.setName("first name"); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
dbSession.commit(); | |||
// verify that parameters are indexed in es | |||
@@ -170,7 +170,7 @@ public class RuleDataMediumTest { | |||
//Update in DB | |||
ruleDto.setTags(ImmutableSet.of("world")) | |||
.setName("second name"); | |||
dao.update(ruleDto, dbSession); | |||
dao.update(dbSession, ruleDto); | |||
dbSession.commit(); | |||
// verify that parameters are updated in es | |||
@@ -188,7 +188,7 @@ public class RuleDataMediumTest { | |||
RuleDto ruleDto = newRuleDto(ruleKey) | |||
.setTags(ImmutableSet.of("hello")) | |||
.setName("first name"); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
dbSession.commit(); | |||
RuleParamDto minParamDto = new RuleParamDto() | |||
@@ -255,7 +255,7 @@ public class RuleDataMediumTest { | |||
RuleKey ruleKey = RuleKey.of("test", "r1"); | |||
RuleDto ruleDto = newRuleDto(ruleKey) | |||
.setDefaultSubCharacteristicId(char11.getId()); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
dbSession.commit(); | |||
@@ -285,7 +285,7 @@ public class RuleDataMediumTest { | |||
db.debtCharacteristicDao().insert(char21, dbSession); | |||
ruleDto.setSubCharacteristicId(char21.getId()); | |||
dao.update(ruleDto, dbSession); | |||
dao.update(dbSession, ruleDto); | |||
dbSession.commit(); | |||
@@ -82,7 +82,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(6).setRemediationFunction("CONSTANT_ISSUE").setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -98,7 +98,7 @@ public class RuleOperationsTest { | |||
authorizedUserSession | |||
); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -117,7 +117,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -132,7 +132,7 @@ public class RuleOperationsTest { | |||
authorizedUserSession | |||
); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -150,7 +150,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(2).setRemediationFunction("CONSTANT_ISSUE").setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -161,7 +161,7 @@ public class RuleOperationsTest { | |||
authorizedUserSession | |||
); | |||
verify(ruleDao, never()).update(any(RuleDto.class), eq(session)); | |||
verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); | |||
verify(session, never()).commit(); | |||
} | |||
@@ -171,7 +171,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(2).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -186,7 +186,7 @@ public class RuleOperationsTest { | |||
authorizedUserSession | |||
); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -204,7 +204,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(6).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -219,7 +219,7 @@ public class RuleOperationsTest { | |||
authorizedUserSession | |||
); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -240,11 +240,11 @@ public class RuleOperationsTest { | |||
.setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
operations.updateRule(new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey(null), authorizedUserSession); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -262,7 +262,7 @@ public class RuleOperationsTest { | |||
.setDefaultSubCharacteristicId(6).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -272,7 +272,7 @@ public class RuleOperationsTest { | |||
operations.updateRule(new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey("COMPILER"), authorizedUserSession); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -289,11 +289,11 @@ public class RuleOperationsTest { | |||
RuleDto dto = new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
operations.updateRule(new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey(null), authorizedUserSession); | |||
verify(ruleDao).update(ruleCaptor.capture(), eq(session)); | |||
verify(ruleDao).update(eq(session), ruleCaptor.capture()); | |||
verify(session).commit(); | |||
RuleDto result = ruleCaptor.getValue(); | |||
@@ -310,14 +310,14 @@ public class RuleOperationsTest { | |||
RuleDto dto = new RuleDto().setId(1).setRepositoryKey("squid").setRuleKey("UselessImportCheck").setSubCharacteristicId(-1); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
operations.updateRule( | |||
new RuleChange().setRuleKey(ruleKey).setDebtCharacteristicKey(null), | |||
authorizedUserSession | |||
); | |||
verify(ruleDao, never()).update(any(RuleDto.class), eq(session)); | |||
verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); | |||
verify(session, never()).commit(); | |||
} | |||
@@ -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(ruleKey, session)).thenReturn(null); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(null); | |||
try { | |||
operations.updateRule( | |||
@@ -337,7 +337,7 @@ public class RuleOperationsTest { | |||
assertThat(e).isInstanceOf(NotFoundException.class); | |||
} | |||
verify(ruleDao, never()).update(any(RuleDto.class), eq(session)); | |||
verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); | |||
verify(session, never()).commit(); | |||
} | |||
@@ -347,7 +347,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(2).setRemediationFunction("CONSTANT_ISSUE").setRemediationOffset("10min"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(null); | |||
@@ -361,7 +361,7 @@ public class RuleOperationsTest { | |||
assertThat(e).isInstanceOf(NotFoundException.class); | |||
} | |||
verify(ruleDao, never()).update(any(RuleDto.class), eq(session)); | |||
verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); | |||
verify(session, never()).commit(); | |||
} | |||
@@ -371,7 +371,7 @@ public class RuleOperationsTest { | |||
.setSubCharacteristicId(2).setRemediationFunction("LINEAR").setRemediationCoefficient("1h"); | |||
RuleKey ruleKey = RuleKey.of("squid", "UselessImportCheck"); | |||
when(ruleDao.getByKey(ruleKey, session)).thenReturn(dto); | |||
when(ruleDao.getByKey(session, ruleKey)).thenReturn(dto); | |||
CharacteristicDto subCharacteristic = new CharacteristicDto().setId(2).setKey("COMPILER").setName("Compiler").setParentId(1); | |||
when(characteristicDao.selectByKey("COMPILER", session)).thenReturn(subCharacteristic); | |||
@@ -386,7 +386,7 @@ public class RuleOperationsTest { | |||
assertThat(e).isInstanceOf(BadRequestException.class).hasMessage("Invalid coefficient: foo (Duration 'foo' is invalid, it should use the following sample format : 2d 10h 15min)"); | |||
} | |||
verify(ruleDao, never()).update(any(RuleDto.class), eq(session)); | |||
verify(ruleDao, never()).update(eq(session), any(RuleDto.class)); | |||
verify(session, never()).commit(); | |||
} | |||
} |
@@ -79,16 +79,15 @@ public class RuleServiceMediumTest { | |||
// insert db | |||
RuleKey rule1 = RuleKey.of("javascript", "S001"); | |||
dao.insert(newRuleDto(rule1) | |||
dao.insert(dbSession, newRuleDto(rule1) | |||
.setTags(Sets.newHashSet("security")) | |||
.setSystemTags(Collections.<String>emptySet()), | |||
dbSession | |||
.setSystemTags(Collections.<String>emptySet()) | |||
); | |||
RuleKey rule2 = RuleKey.of("java", "S001"); | |||
dao.insert(newRuleDto(rule2) | |||
dao.insert(dbSession, newRuleDto(rule2) | |||
.setTags(Sets.newHashSet("toberemoved")) | |||
.setSystemTags(Sets.newHashSet("bug")), dbSession); | |||
.setSystemTags(Sets.newHashSet("bug"))); | |||
dbSession.commit(); | |||
service.setTags(rule2, Sets.newHashSet("bug", "security")); | |||
@@ -124,14 +123,14 @@ public class RuleServiceMediumTest { | |||
public void setNote() throws Exception { | |||
MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN).setLogin("marius"); | |||
RuleKey ruleKey = RuleKey.of("javascript", "S001"); | |||
dao.insert(newRuleDto(ruleKey), dbSession); | |||
dao.insert(dbSession, newRuleDto(ruleKey)); | |||
dbSession.commit(); | |||
// 1. CREATE NOTE | |||
service.setNote(ruleKey, "my *note*"); | |||
// verify db | |||
RuleDto dto = dao.getNonNullByKey(ruleKey, dbSession); | |||
RuleDto dto = dao.getNonNullByKey(dbSession, ruleKey); | |||
assertThat(dto.getNoteData()).isEqualTo("my *note*"); | |||
assertThat(dto.getNoteCreatedAt()).isNotNull(); | |||
assertThat(dto.getNoteUpdatedAt()).isNotNull(); | |||
@@ -147,7 +146,7 @@ public class RuleServiceMediumTest { | |||
// 2. DELETE NOTE | |||
service.setNote(ruleKey, null); | |||
dbSession.clearCache(); | |||
dto = dao.getNonNullByKey(ruleKey, dbSession); | |||
dto = dao.getNonNullByKey(dbSession, ruleKey); | |||
assertThat(dto.getNoteData()).isNull(); | |||
assertThat(dto.getNoteCreatedAt()).isNull(); | |||
assertThat(dto.getNoteUpdatedAt()).isNull(); | |||
@@ -165,16 +164,15 @@ public class RuleServiceMediumTest { | |||
public void test_list_tags() throws InterruptedException { | |||
// insert db | |||
RuleKey rule1 = RuleKey.of("javascript", "S001"); | |||
dao.insert(newRuleDto(rule1) | |||
dao.insert(dbSession, newRuleDto(rule1) | |||
.setTags(Sets.newHashSet("security")) | |||
.setSystemTags(Sets.newHashSet("java-coding", "stephane.gamard@sonarsource.com")), | |||
dbSession | |||
.setSystemTags(Sets.newHashSet("java-coding", "stephane.gamard@sonarsource.com")) | |||
); | |||
RuleKey rule2 = RuleKey.of("java", "S001"); | |||
dao.insert(newRuleDto(rule2) | |||
dao.insert(dbSession, newRuleDto(rule2) | |||
.setTags(Sets.newHashSet("mytag")) | |||
.setSystemTags(Sets.newHashSet("")), dbSession); | |||
.setSystemTags(Sets.newHashSet(""))); | |||
dbSession.commit(); | |||
@@ -199,8 +197,8 @@ public class RuleServiceMediumTest { | |||
RuleDto rule1 = newRuleDto(RuleKey.of("test", "rule1")); | |||
RuleDto rule2 = newRuleDto(RuleKey.of("test", "rule2")); | |||
tester.get(RuleDao.class).insert(rule1, dbSession); | |||
tester.get(RuleDao.class).insert(rule2, dbSession); | |||
tester.get(RuleDao.class).insert(dbSession, rule1); | |||
tester.get(RuleDao.class).insert(dbSession, rule2); | |||
ActiveRuleDto activeRule1 = ActiveRuleDto.createFor(qprofile1, rule1) | |||
.setSeverity(Severity.BLOCKER); | |||
@@ -208,9 +206,9 @@ public class RuleServiceMediumTest { | |||
.setSeverity(Severity.BLOCKER); | |||
ActiveRuleDto activeRule3 = ActiveRuleDto.createFor(qprofile2, rule2) | |||
.setSeverity(Severity.BLOCKER); | |||
tester.get(ActiveRuleDao.class).insert(activeRule1, dbSession); | |||
tester.get(ActiveRuleDao.class).insert(activeRule2, dbSession); | |||
tester.get(ActiveRuleDao.class).insert(activeRule3, dbSession); | |||
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule1); | |||
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule2); | |||
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule3); | |||
dbSession.commit(); | |||
@@ -125,9 +125,9 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
@Test | |||
public void select_by_rule_key() throws Exception { | |||
setupData("select_by_rule_key"); | |||
assertThat(dao.getByKey(RuleKey.of("checkstyle", "AvoidComparison"), session)).isNotNull(); | |||
assertThat(dao.getByKey(RuleKey.of("checkstyle", "Unknown"), session)).isNull(); | |||
assertThat(dao.getByKey(RuleKey.of("Unknown", "AvoidComparison"), session)).isNull(); | |||
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(); | |||
} | |||
@Test | |||
@@ -212,7 +212,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
.setEffortToFixDescription("squid.S115.effortToFix"); | |||
dao.update(ruleToUpdate, session); | |||
dao.update(session, ruleToUpdate); | |||
session.commit(); | |||
checkTables("update", "rules"); | |||
@@ -247,7 +247,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
.setDefaultRemediationOffset("10h") | |||
.setEffortToFixDescription("squid.S115.effortToFix"); | |||
dao.insert(ruleToInsert, session); | |||
dao.insert(session, ruleToInsert); | |||
session.commit(); | |||
checkTables("insert", "rules"); | |||
@@ -303,7 +303,7 @@ public class RuleDaoTest extends AbstractDaoTestCase { | |||
.setDefaultRemediationOffset("5min") | |||
.setEffortToFixDescription("squid.S115.effortToFix2"); | |||
dao.insert(ImmutableList.of(ruleToInsert1, ruleToInsert2), session); | |||
dao.insert(session, ImmutableList.of(ruleToInsert1, ruleToInsert2)); | |||
session.commit(); | |||
checkTables("insert_all", "rules"); |
@@ -77,7 +77,7 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void getByKey() throws InterruptedException { | |||
RuleDto ruleDto = newRuleDto(RuleKey.of("javascript", "S001")); | |||
dao.insert(ruleDto, dbSession); | |||
dao.insert(dbSession, ruleDto); | |||
dbSession.commit(); | |||
Rule rule = index.getByKey(RuleKey.of("javascript", "S001")); | |||
@@ -103,11 +103,11 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void global_facet_on_repositories() { | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S001")).setRuleKey("X001"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("php", "S001")) | |||
.setSystemTags(ImmutableSet.of("sysTag")), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S002")).setRuleKey("X002") | |||
.setTags(ImmutableSet.of("tag1")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001")).setRuleKey("X001")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("php", "S001")) | |||
.setSystemTags(ImmutableSet.of("sysTag"))); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S002")).setRuleKey("X002") | |||
.setTags(ImmutableSet.of("tag1"))); | |||
dbSession.commit(); | |||
index.refresh(); | |||
@@ -136,7 +136,7 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void return_all_doc_fields_by_default() { | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S001")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001"))); | |||
dbSession.commit(); | |||
@@ -155,7 +155,7 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void select_doc_fields_to_return() { | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S001")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001"))); | |||
dbSession.commit(); | |||
@@ -178,8 +178,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_name_by_query() { | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S001")) | |||
.setName("testing the partial match and matching of rule"), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001")) | |||
.setName("testing the partial match and matching of rule")); | |||
dbSession.commit(); | |||
@@ -202,11 +202,11 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_key_by_query() { | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S001")) | |||
.setRuleKey("X001"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("cobol", "S001")) | |||
.setRuleKey("X001"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("php", "S002")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001")) | |||
.setRuleKey("X001")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("cobol", "S001")) | |||
.setRuleKey("X001")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("php", "S002"))); | |||
dbSession.commit(); | |||
@@ -226,8 +226,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_all_rules() throws InterruptedException { | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S001")), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S001"))); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002"))); | |||
dbSession.commit(); | |||
@@ -239,8 +239,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_any_of_repositories() { | |||
dao.insert(newRuleDto(RuleKey.of("findbugs", "S001")), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("pmd", "S002")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("findbugs", "S001"))); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("pmd", "S002"))); | |||
dbSession.commit(); | |||
@@ -260,8 +260,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_any_of_languages() throws InterruptedException { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")).setLanguage("java"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S002")).setLanguage("js"), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setLanguage("java")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S002")).setLanguage("js")); | |||
dbSession.commit(); | |||
@@ -301,10 +301,10 @@ public class RuleIndexMediumTest { | |||
dbClient.debtCharacteristicDao().insert(char11, dbSession); | |||
dbSession.commit(); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")) | |||
.setSubCharacteristicId(char11.getId()), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")) | |||
.setSubCharacteristicId(char11.getId())); | |||
dao.insert(newRuleDto(RuleKey.of("javascript", "S002")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("javascript", "S002"))); | |||
dbSession.commit(); | |||
@@ -347,8 +347,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_any_of_severities() throws InterruptedException { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")).setSeverity(Severity.BLOCKER), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")).setSeverity(Severity.INFO), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setSeverity(Severity.BLOCKER)); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002")).setSeverity(Severity.INFO)); | |||
dbSession.commit(); | |||
@@ -372,8 +372,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_any_of_statuses() throws InterruptedException { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")).setStatus(RuleStatus.BETA.name()), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")).setStatus(RuleStatus.READY.name()), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setStatus(RuleStatus.BETA.name())); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002")).setStatus(RuleStatus.READY.name())); | |||
dbSession.commit(); | |||
@@ -397,9 +397,9 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void sort_by_name() { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")).setName("abcd"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")).setName("ABC"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S003")).setName("FGH"), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setName("abcd")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002")).setName("ABC")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S003")).setName("FGH")); | |||
dbSession.commit(); | |||
@@ -420,8 +420,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void sort_by_language() throws InterruptedException { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")).setLanguage("java"), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")).setLanguage("php"), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setLanguage("java")); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002")).setLanguage("php")); | |||
dbSession.commit(); | |||
@@ -446,25 +446,25 @@ public class RuleIndexMediumTest { | |||
dbClient.qualityProfileDao().insert(qualityProfileDto2); | |||
RuleDto rule1 = newRuleDto(RuleKey.of("java", "S001")); | |||
dao.insert(rule1, dbSession); | |||
dao.insert(dbSession, rule1); | |||
RuleDto rule2 = newRuleDto(RuleKey.of("java", "S002")); | |||
dao.insert(rule2, dbSession); | |||
dao.insert(dbSession, rule2); | |||
RuleDto rule3 = newRuleDto(RuleKey.of("java", "S003")); | |||
dao.insert(rule3, dbSession); | |||
dao.insert(dbSession, rule3); | |||
dbClient.activeRuleDao().insert( | |||
ActiveRuleDto.createFor(qualityProfileDto1, rule1) | |||
.setSeverity("BLOCKER"), dbSession | |||
dbSession, ActiveRuleDto.createFor(qualityProfileDto1, rule1) | |||
.setSeverity("BLOCKER") | |||
); | |||
dbClient.activeRuleDao().insert( | |||
ActiveRuleDto.createFor(qualityProfileDto2, rule1) | |||
.setSeverity("BLOCKER"), dbSession | |||
dbSession, ActiveRuleDto.createFor(qualityProfileDto2, rule1) | |||
.setSeverity("BLOCKER") | |||
); | |||
dbClient.activeRuleDao().insert( | |||
ActiveRuleDto.createFor(qualityProfileDto1, rule2) | |||
.setSeverity("BLOCKER"), dbSession | |||
dbSession, ActiveRuleDto.createFor(qualityProfileDto1, rule2) | |||
.setSeverity("BLOCKER") | |||
); | |||
@@ -502,8 +502,8 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void search_by_tag() throws InterruptedException { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")).setTags(ImmutableSet.of("tag1")), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")).setTags(ImmutableSet.of("tag2")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001")).setTags(ImmutableSet.of("tag1"))); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002")).setTags(ImmutableSet.of("tag2"))); | |||
dbSession.commit(); | |||
@@ -545,9 +545,9 @@ public class RuleIndexMediumTest { | |||
@Test | |||
public void paging() { | |||
dao.insert(newRuleDto(RuleKey.of("java", "S001")), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S002")), dbSession); | |||
dao.insert(newRuleDto(RuleKey.of("java", "S003")), dbSession); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S001"))); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S002"))); | |||
dao.insert(dbSession, newRuleDto(RuleKey.of("java", "S003"))); | |||
dbSession.commit(); | |||
@@ -103,11 +103,11 @@ public class RulesWebServiceTest { | |||
tester.get(QualityProfileDao.class).insert(session, profile); | |||
RuleDto rule = newRuleDto(RuleKey.of(profile.getLanguage(), "S001")); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(profile, rule) | |||
.setSeverity("BLOCKER"); | |||
tester.get(ActiveRuleDao.class).insert(activeRuleDto, session); | |||
tester.get(ActiveRuleDao.class).insert(session, activeRuleDto); | |||
session.commit(); | |||
@@ -141,8 +141,8 @@ public class RulesWebServiceTest { | |||
@Test | |||
public void search_2_rules() throws Exception { | |||
ruleDao.insert(newRuleDto(RuleKey.of("javascript", "S001")), session); | |||
ruleDao.insert(newRuleDto(RuleKey.of("javascript", "S002")), session); | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("javascript", "S001"))); | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("javascript", "S002"))); | |||
session.commit(); | |||
MockUserSession.set(); | |||
@@ -155,11 +155,11 @@ public class RulesWebServiceTest { | |||
@Test | |||
public void search_debt_rules() throws Exception { | |||
ruleDao.insert(newRuleDto(RuleKey.of("javascript", "S001")) | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("javascript", "S001")) | |||
.setDefaultRemediationCoefficient("DefaultCoef") | |||
.setDefaultRemediationFunction("DefaultFunction") | |||
.setDefaultRemediationCoefficient("DefaultCoef") | |||
.setDefaultSubCharacteristicId(1), session); | |||
.setDefaultSubCharacteristicId(1)); | |||
session.commit(); | |||
@@ -177,10 +177,10 @@ public class RulesWebServiceTest { | |||
tester.get(QualityProfileDao.class).insert(session, profile); | |||
RuleDto rule = newRuleDto(RuleKey.of(profile.getLanguage(), "S001")); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
ActiveRuleDto activeRule = newActiveRule(profile, rule); | |||
tester.get(ActiveRuleDao.class).insert(activeRule, session); | |||
tester.get(ActiveRuleDao.class).insert(session, activeRule); | |||
session.commit(); | |||
@@ -207,12 +207,12 @@ public class RulesWebServiceTest { | |||
session.commit(); | |||
RuleDto rule = newRuleDto(RuleKey.of(profile.getLanguage(), "S001")); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
ActiveRuleDto activeRule = newActiveRule(profile, rule); | |||
tester.get(ActiveRuleDao.class).insert(activeRule, session); | |||
tester.get(ActiveRuleDao.class).insert(session, activeRule); | |||
ActiveRuleDto activeRule2 = newActiveRule(profile2, rule); | |||
tester.get(ActiveRuleDao.class).insert(activeRule2, session); | |||
tester.get(ActiveRuleDao.class).insert(session, activeRule2); | |||
session.commit(); | |||
@@ -233,7 +233,7 @@ public class RulesWebServiceTest { | |||
tester.get(QualityProfileDao.class).insert(session, profile); | |||
RuleDto rule = newRuleDto(RuleKey.of(profile.getLanguage(), "S001")); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
session.commit(); | |||
@@ -252,7 +252,7 @@ public class RulesWebServiceTest { | |||
ruleDao.addRuleParam(rule, param2, session); | |||
ActiveRuleDto activeRule = newActiveRule(profile, rule); | |||
tester.get(ActiveRuleDao.class).insert(activeRule, session); | |||
tester.get(ActiveRuleDao.class).insert(session, activeRule); | |||
ActiveRuleParamDto activeRuleParam = ActiveRuleParamDto.createFor(param) | |||
.setValue("The VALUE"); | |||
@@ -282,12 +282,12 @@ public class RulesWebServiceTest { | |||
RuleDto rule = newRuleDto(RuleKey.of(profile.getLanguage(), "S001")) | |||
.setTags(ImmutableSet.of("hello", "world")); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
RuleDto rule2 = newRuleDto(RuleKey.of(profile.getLanguage(), "S002")) | |||
.setTags(ImmutableSet.of("java")) | |||
.setSystemTags(ImmutableSet.of("sys1")); | |||
ruleDao.insert(rule2, session); | |||
ruleDao.insert(session, rule2); | |||
session.commit(); | |||
@@ -305,7 +305,7 @@ public class RulesWebServiceTest { | |||
RuleDto rule = newRuleDto(RuleKey.of(profile.getLanguage(), "S001")) | |||
.setNoteData("this is *bold*"); | |||
ruleDao.insert(rule, session); | |||
ruleDao.insert(session, rule); | |||
session.commit(); | |||
@@ -319,10 +319,10 @@ public class RulesWebServiceTest { | |||
@Test | |||
public void filter_by_tags() throws Exception { | |||
ruleDao.insert(newRuleDto(RuleKey.of("java", "S001")) | |||
.setSystemTags(ImmutableSet.of("tag1")), session); | |||
ruleDao.insert(newRuleDto(RuleKey.of("java", "S002")) | |||
.setSystemTags(ImmutableSet.of("tag2")), session); | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("java", "S001")) | |||
.setSystemTags(ImmutableSet.of("tag1"))); | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("java", "S002")) | |||
.setSystemTags(ImmutableSet.of("tag2"))); | |||
session.commit(); | |||
@@ -337,8 +337,8 @@ public class RulesWebServiceTest { | |||
@Test | |||
public void sort_by_name() throws Exception { | |||
ruleDao.insert(newRuleDto(RuleKey.of("java", "S001")).setName("a"), session); | |||
ruleDao.insert(newRuleDto(RuleKey.of("java", "S002")).setName("b"), session); | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("java", "S001")).setName("a")); | |||
ruleDao.insert(session, newRuleDto(RuleKey.of("java", "S002")).setName("b")); | |||
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(MeasureKey.of(COMPONENT_KEY, CoreMetrics.SCM_AUTHORS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(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(any(MeasureKey.class), eq(session))).thenReturn(null); | |||
when(measureDao.getByKey(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(MeasureKey.of(COMPONENT_KEY, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(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(any(MeasureKey.class), eq(session))).thenReturn(null); | |||
when(measureDao.getByKey(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(MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY)); | |||
service.getHits(COMPONENT_KEY, CoverageService.TYPE.IT); | |||
verify(measureDao).getByKey(MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERAGE_LINE_HITS_DATA_KEY)); | |||
service.getHits(COMPONENT_KEY, CoverageService.TYPE.OVERALL); | |||
verify(measureDao).getByKey(MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERAGE_LINE_HITS_DATA_KEY), session); | |||
verify(measureDao).getByKey(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(any(MeasureKey.class), eq(session))).thenReturn(null); | |||
when(measureDao.getByKey(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(MeasureKey.of(COMPONENT_KEY, CoreMetrics.CONDITIONS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.CONDITIONS_BY_LINE_KEY)); | |||
service.getConditions(COMPONENT_KEY, CoverageService.TYPE.IT); | |||
verify(measureDao).getByKey(MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_CONDITIONS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_CONDITIONS_BY_LINE_KEY)); | |||
service.getConditions(COMPONENT_KEY, CoverageService.TYPE.OVERALL); | |||
verify(measureDao).getByKey(MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_CONDITIONS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(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(MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY)); | |||
service.getCoveredConditions(COMPONENT_KEY, CoverageService.TYPE.IT); | |||
verify(measureDao).getByKey(MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.IT_COVERED_CONDITIONS_BY_LINE_KEY)); | |||
service.getCoveredConditions(COMPONENT_KEY, CoverageService.TYPE.OVERALL); | |||
verify(measureDao).getByKey(MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY), session); | |||
verify(measureDao).getByKey(session, MeasureKey.of(COMPONENT_KEY, CoreMetrics.OVERALL_COVERED_CONDITIONS_BY_LINE_KEY)); | |||
} | |||
@Test |