*/
package org.sonar.server.rule;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.server.db.DbClient;
+import org.sonar.server.rule.index.RuleIndexer;
import org.sonar.server.user.UserSession;
import static com.google.common.collect.Lists.newArrayList;
public class RuleUpdater {
private final DbClient dbClient;
+ private final RuleIndexer ruleIndexer;
private final System2 system;
- public RuleUpdater(DbClient dbClient, System2 system) {
+ public RuleUpdater(DbClient dbClient, RuleIndexer ruleIndexer, System2 system) {
this.dbClient = dbClient;
+ this.ruleIndexer = ruleIndexer;
this.system = system;
}
Context context = newContext(update);
// validate only the changes, not all the rule fields
apply(update, context, userSession);
- dbClient.deprecatedRuleDao().update(dbSession, context.rule);
+ update(dbSession, context.rule);
updateParameters(dbSession, update, context);
dbSession.commit();
+ ruleIndexer.setEnabled(true).index();
return true;
}
+ @VisibleForTesting
+ boolean update(RuleUpdate update, UserSession userSession) {
+ DbSession dbSession = dbClient.openSession(false);
+ try {
+ return update(dbSession, update, userSession);
+ } finally {
+ dbClient.closeSession(dbSession);
+ }
+ }
+
/**
* Load all the DTOs required for validating changes and updating rule
*/
DbSession dbSession = dbClient.openSession(false);
try {
Context context = new Context();
- context.rule = dbClient.deprecatedRuleDao().getByKey(dbSession, change.getRuleKey());
+ context.rule = dbClient.ruleDao().selectOrFailByKey(dbSession, change.getRuleKey());
if (RuleStatus.REMOVED == context.rule.getStatus()) {
throw new IllegalArgumentException("Rule with REMOVED status cannot be updated: " + change.getRuleKey());
}
throw new IllegalArgumentException("The description is missing");
} else {
context.rule.setDescription(description);
+ context.rule.setDescriptionFormat(RuleDto.Format.MARKDOWN);
}
}
private void updateParameters(DbSession dbSession, RuleUpdate update, Context context) {
if (update.isChangeParameters() && update.isCustomRule()) {
RuleDto customRule = context.rule;
- RuleDto templateRule = dbClient.deprecatedRuleDao().selectTemplate(customRule, dbSession);
- if (templateRule == null) {
+ Integer templateId = customRule.getTemplateId();
+ Preconditions.checkNotNull(templateId, "Rule '%s' has no persisted template!", customRule);
+ Optional<RuleDto> templateRule = dbClient.ruleDao().selectById(templateId, dbSession);
+ if (!templateRule.isPresent()) {
throw new IllegalStateException(String.format("Template %s of rule %s does not exist",
customRule.getTemplateId(), customRule.getKey()));
}
private void deleteOrUpdateParameters(DbSession dbSession, RuleUpdate update, RuleDto customRule, List<String> paramKeys,
Multimap<RuleDto, ActiveRuleDto> activeRules, Multimap<ActiveRuleDto, ActiveRuleParamDto> activeRuleParams) {
- for (RuleParamDto ruleParamDto : dbClient.deprecatedRuleDao().selectRuleParamsByRuleKey(dbSession, update.getRuleKey())) {
+ for (RuleParamDto ruleParamDto : dbClient.ruleDao().selectRuleParamsByRuleKey(dbSession, update.getRuleKey())) {
String key = ruleParamDto.getName();
String value = Strings.emptyToNull(update.parameter(key));
// Update rule param
ruleParamDto.setDefaultValue(value);
- dbClient.deprecatedRuleDao().updateRuleParam(dbSession, customRule, ruleParamDto);
+ dbClient.ruleDao().updateRuleParam(dbSession, customRule, ruleParamDto);
if (value != null) {
// Update linked active rule params or create new one
private RuleDto rule;
}
+ private void update(DbSession session, RuleDto rule) {
+ rule.setUpdatedAtInMs(system.now());
+ rule.setUpdatedAt(new Date(system.now()));
+ dbClient.ruleDao().update(session, rule);
+ }
+
}
*/
package org.sonar.server.rule;
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.annotation.Nonnull;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.sonar.api.rule.Severity;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.server.debt.internal.DefaultDebtRemediationFunction;
+import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.qualityprofile.ActiveRuleKey;
import org.sonar.db.qualityprofile.QualityProfileDto;
+import org.sonar.db.rule.RuleDao;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleParamDto;
import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.db.DbClient;
+import org.sonar.server.es.SearchOptions;
import org.sonar.server.qualityprofile.ActiveRule;
import org.sonar.server.qualityprofile.QProfileTesting;
import org.sonar.server.qualityprofile.RuleActivation;
import org.sonar.server.qualityprofile.RuleActivator;
import org.sonar.server.qualityprofile.index.ActiveRuleIndex;
-import org.sonar.server.rule.db.RuleDao;
-import org.sonar.server.rule.index.RuleIndex;
-import org.sonar.server.search.BaseIndex;
+import org.sonar.server.rule.index.RuleIndex2;
+import org.sonar.server.rule.index.RuleQuery;
import org.sonar.server.tester.ServerTester;
import org.sonar.server.tester.UserSessionRule;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+// TODO remove ServerTester usage when ActiveRule Daov2 is removed
public class RuleUpdaterMediumTest {
- private static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
+ static final RuleKey RULE_KEY = RuleKey.of("squid", "S001");
@ClassRule
public static ServerTester tester = new ServerTester();
+
@org.junit.Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
DbClient db = tester.get(DbClient.class);
RuleDao ruleDao = tester.get(RuleDao.class);
- DbSession dbSession;
- BaseIndex<Rule, RuleDto, RuleKey> ruleIndex = tester.get(RuleIndex.class);
- RuleUpdater updater = tester.get(RuleUpdater.class);
+ DbSession dbSession = db.openSession(false);
+ RuleIndex2 ruleIndex = tester.get(RuleIndex2.class);
+
+ RuleUpdater underTest = tester.get(RuleUpdater.class);
@Before
public void before() {
tester.clearDbAndIndexes();
- dbSession = db.openSession(false);
}
@After
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(Sets.newHashSet("java9"));
try {
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
fail();
} catch (IllegalArgumentException e) {
assertThat(e).hasMessage("Rule with REMOVED status cannot be updated: squid:S001");
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY);
assertThat(update.isEmpty()).isTrue();
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
- RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getNoteData()).isEqualTo("my *note*");
assertThat(rule.getNoteUserLogin()).isEqualTo("me");
assertThat(rule.getTags()).containsOnly("tag1");
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY);
update.setMarkdownNote("my *note*");
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
- RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getNoteData()).isEqualTo("my *note*");
assertThat(rule.getNoteUserLogin()).isEqualTo("me");
assertThat(rule.getNoteCreatedAt()).isNotNull();
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setMarkdownNote(null);
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
- RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getNoteData()).isNull();
assertThat(rule.getNoteUserLogin()).isNull();
assertThat(rule.getNoteCreatedAt()).isNull();
// java8 is a system tag -> ignore
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(Sets.newHashSet("bug", "java8"));
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
- RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getTags()).containsOnly("bug");
assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc");
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setTags(null);
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
- RuleDto rule = ruleDao.getNullableByKey(dbSession, RULE_KEY);
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
assertThat(rule.getTags()).isEmpty();
assertThat(rule.getSystemTags()).containsOnly("java8", "javadoc");
DefaultDebtRemediationFunction fn = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "1min");
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(fn);
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
- Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
- assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
- assertThat(indexedRule.debtRemediationFunction().coefficient()).isNull();
- assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("1min");
-
- assertThat(indexedRule.debtOverloaded()).isTrue();
- assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
- assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
- assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+ assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
+ assertThat(rule.getRemediationCoefficient()).isNull();
+ assertThat(rule.getRemediationOffset()).isEqualTo("1min");
+
+ assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
+ assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+ assertThat(rule.getDefaultRemediationOffset()).isEqualTo("5min");
}
@Test
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "2d", null));
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
- Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
- assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
- assertThat(indexedRule.debtRemediationFunction().coefficient()).isEqualTo("2d");
- assertThat(indexedRule.debtRemediationFunction().offset()).isNull();
-
- assertThat(indexedRule.debtOverloaded()).isTrue();
- assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
- assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
- assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isNull();
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+ assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
+ assertThat(rule.getRemediationCoefficient()).isEqualTo("2d");
+ assertThat(rule.getRemediationOffset()).isNull();
+
+ assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
+ assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+ assertThat(rule.getDefaultRemediationOffset()).isNull();
}
@Test
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY)
.setDebtRemediationFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "10min"));
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// verify debt is overridden
- Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
- assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
- assertThat(indexedRule.debtRemediationFunction().coefficient()).isNull();
- assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("10min");
-
- assertThat(indexedRule.debtOverloaded()).isTrue();
- assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
- assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
- assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+ assertThat(rule.getRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE.name());
+ assertThat(rule.getRemediationCoefficient()).isNull();
+ assertThat(rule.getRemediationOffset()).isEqualTo("10min");
+
+ assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name());
+ assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+ assertThat(rule.getDefaultRemediationOffset()).isEqualTo("5min");
}
@Test
dbSession.commit();
RuleUpdate update = RuleUpdate.createForPluginRule(RULE_KEY).setDebtRemediationFunction(null);
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// verify debt is coming from default values
- Rule indexedRule = tester.get(RuleIndex.class).getByKey(RULE_KEY);
- assertThat(indexedRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
- assertThat(indexedRule.debtRemediationFunction().coefficient()).isEqualTo("1d");
- assertThat(indexedRule.debtRemediationFunction().offset()).isEqualTo("5min");
-
- assertThat(indexedRule.debtOverloaded()).isFalse();
- assertThat(indexedRule.defaultDebtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
- assertThat(indexedRule.defaultDebtRemediationFunction().coefficient()).isEqualTo("1d");
- assertThat(indexedRule.defaultDebtRemediationFunction().offset()).isEqualTo("5min");
+ RuleDto rule = ruleDao.selectOrFailByKey(dbSession, RULE_KEY);
+ assertThat(rule.getDefaultRemediationFunction()).isEqualTo(DebtRemediationFunction.Type.LINEAR.name());
+ assertThat(rule.getDefaultRemediationCoefficient()).isEqualTo("1d");
+ assertThat(rule.getDefaultRemediationOffset()).isEqualTo("5min");
+
+ assertThat(rule.getRemediationFunction()).isNull();
+ assertThat(rule.getRemediationCoefficient()).isNull();
+ assertThat(rule.getRemediationOffset()).isNull();
}
@Test
.setSeverity("MAJOR")
.setStatus(RuleStatus.READY)
.setParameters(ImmutableMap.of("regex", "b.*"));
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// Verify custom rule is updated
- Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
+ RuleDto customRuleReloaded = ruleDao.selectOrFailByKey(dbSession, customRule.getKey());
assertThat(customRuleReloaded).isNotNull();
- assertThat(customRuleReloaded.name()).isEqualTo("New name");
- assertThat(customRuleReloaded.htmlDescription()).isEqualTo("New description");
- assertThat(customRuleReloaded.severity()).isEqualTo("MAJOR");
- assertThat(customRuleReloaded.status()).isEqualTo(RuleStatus.READY);
- assertThat(customRuleReloaded.params()).hasSize(2);
-
- assertThat(customRuleReloaded.params().get(0).defaultValue()).isEqualTo("b.*");
- assertThat(customRuleReloaded.params().get(1).defaultValue()).isNull();
+ assertThat(customRuleReloaded.getName()).isEqualTo("New name");
+ assertThat(customRuleReloaded.getDescription()).isEqualTo("New description");
+ assertThat(customRuleReloaded.getSeverityString()).isEqualTo("MAJOR");
+ assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.READY);
+
+ List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRuleReloaded.getKey());
+ assertThat(params).hasSize(2);
+ assertThat(params.get(0).getDefaultValue()).isEqualTo("b.*");
+ assertThat(params.get(1).getDefaultValue()).isNull();
+
+ // Verify in index
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(customRule.getKey());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(customRule.getKey());
+
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero();
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero();
}
@Test
.setMarkdownDescription("New description")
.setSeverity("MAJOR")
.setStatus(RuleStatus.READY);
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// Verify custom rule is updated
- Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
- RuleParam param = customRuleReloaded.params().get(0);
- assertThat(param.defaultValue()).isNull();
+ List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRule.getKey());
+ assertThat(params.get(0).getDefaultValue()).isNull();
}
@Test
// Update custom rule parameter 'regex', add 'message' and remove 'format'
RuleUpdate update = RuleUpdate.createForCustomRule(customRule.getKey())
.setParameters(ImmutableMap.of("regex", "b.*", "message", "a message"));
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// Verify custom rule parameters has been updated
- Rule customRuleReloaded = ruleIndex.getByKey(customRule.getKey());
- assertThat(customRuleReloaded.params()).hasSize(3);
- assertThat(customRuleReloaded.param("regex")).isNotNull();
- assertThat(customRuleReloaded.param("regex").defaultValue()).isEqualTo("b.*");
- assertThat(customRuleReloaded.param("message")).isNotNull();
- assertThat(customRuleReloaded.param("message").defaultValue()).isEqualTo("a message");
- assertThat(customRuleReloaded.param("format")).isNotNull();
- assertThat(customRuleReloaded.param("format").defaultValue()).isNull();
-
- RuleParam param = customRuleReloaded.params().get(0);
- assertThat(param.defaultValue()).isEqualTo("b.*");
+ List<RuleParamDto> params = ruleDao.selectRuleParamsByRuleKey(dbSession, customRule.getKey());
+ assertThat(params).hasSize(3);
+
+ Map<String, RuleParamDto> paramsByKey = paramsByKey(params);
+ assertThat(paramsByKey.get("regex")).isNotNull();
+ assertThat(paramsByKey.get("regex").getDefaultValue()).isEqualTo("b.*");
+ assertThat(paramsByKey.get("message")).isNotNull();
+ assertThat(paramsByKey.get("message").getDefaultValue()).isEqualTo("a message");
+ assertThat(paramsByKey.get("format")).isNotNull();
+ assertThat(paramsByKey.get("format").getDefaultValue()).isNull();
// Verify active rule parameters has been updated
ActiveRule activeRule = tester.get(ActiveRuleIndex.class).getByKey(ActiveRuleKey.of(profileDto.getKey(), customRule.getKey()));
.setName("")
.setMarkdownDescription("New desc");
try {
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The name is missing");
.setName("New name")
.setMarkdownDescription("");
try {
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("The description is missing");
.setName("New name")
.setMarkdownDescription("New description")
.setSeverity(Severity.CRITICAL);
- updater.update(dbSession, update, userSessionRule);
+ underTest.update(update, userSessionRule);
dbSession.clearCache();
// Verify manual rule is updated
- Rule manualRuleReloaded = ruleIndex.getByKey(manualRule.getKey());
+ RuleDto manualRuleReloaded = ruleDao.selectOrFailByKey(dbSession, manualRule.getKey());
assertThat(manualRuleReloaded).isNotNull();
- assertThat(manualRuleReloaded.name()).isEqualTo("New name");
- assertThat(manualRuleReloaded.htmlDescription()).isEqualTo("New description");
- assertThat(manualRuleReloaded.severity()).isEqualTo(Severity.CRITICAL);
+ assertThat(manualRuleReloaded.getName()).isEqualTo("New name");
+ assertThat(manualRuleReloaded.getDescription()).isEqualTo("New description");
+ assertThat(manualRuleReloaded.getSeverityString()).isEqualTo(Severity.CRITICAL);
+
+ // Verify in index
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("New name"), new SearchOptions()).getIds()).containsOnly(manualRule.getKey());
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("New description"), new SearchOptions()).getIds()).containsOnly(manualRule.getKey());
+
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old name"), new SearchOptions()).getTotal()).isZero();
+ assertThat(ruleIndex.search(new RuleQuery().setQueryText("Old description"), new SearchOptions()).getTotal()).isZero();
}
@Test
assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom or a manual rule");
}
}
+
+ private static Map<String, RuleParamDto> paramsByKey(List<RuleParamDto> params) {
+ return FluentIterable.from(params).uniqueIndex(RuleParamToKey.INSTANCE);
+ }
+
+ private enum RuleParamToKey implements Function<RuleParamDto, String> {
+ INSTANCE;
+
+ @Override
+ public String apply(@Nonnull RuleParamDto input) {
+ return input.getName();
+ }
+ }
}