You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

QProfilesWsMediumTest.java 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.qualityprofile.ws;
  21. import com.google.common.collect.ImmutableSet;
  22. import java.util.Collections;
  23. import java.util.Optional;
  24. import org.junit.Before;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.sonar.api.rule.RuleKey;
  28. import org.sonar.api.rule.RuleStatus;
  29. import org.sonar.api.rule.Severity;
  30. import org.sonar.api.server.ws.WebService.Param;
  31. import org.sonar.api.utils.System2;
  32. import org.sonar.db.DbClient;
  33. import org.sonar.db.DbSession;
  34. import org.sonar.db.DbTester;
  35. import org.sonar.db.organization.OrganizationDto;
  36. import org.sonar.db.qualityprofile.ActiveRuleDto;
  37. import org.sonar.db.qualityprofile.ActiveRuleKey;
  38. import org.sonar.db.qualityprofile.QProfileDto;
  39. import org.sonar.db.rule.RuleDefinitionDto;
  40. import org.sonar.db.rule.RuleTesting;
  41. import org.sonar.server.es.EsTester;
  42. import org.sonar.server.es.SearchOptions;
  43. import org.sonar.server.exceptions.BadRequestException;
  44. import org.sonar.server.organization.DefaultOrganizationProvider;
  45. import org.sonar.server.organization.TestDefaultOrganizationProvider;
  46. import org.sonar.server.qualityprofile.QProfileName;
  47. import org.sonar.server.qualityprofile.QProfileRules;
  48. import org.sonar.server.qualityprofile.QProfileRulesImpl;
  49. import org.sonar.server.qualityprofile.QProfileTesting;
  50. import org.sonar.server.qualityprofile.RuleActivator;
  51. import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
  52. import org.sonar.server.rule.index.RuleIndex;
  53. import org.sonar.server.rule.index.RuleIndexer;
  54. import org.sonar.server.rule.index.RuleQuery;
  55. import org.sonar.server.rule.ws.RuleQueryFactory;
  56. import org.sonar.server.rule.ws.RuleWsSupport;
  57. import org.sonar.server.tester.UserSessionRule;
  58. import org.sonar.server.util.TypeValidations;
  59. import org.sonar.server.ws.WsActionTester;
  60. import static java.util.Collections.emptyList;
  61. import static org.assertj.core.api.Assertions.assertThat;
  62. import static org.junit.Assert.fail;
  63. import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_LANGUAGES;
  64. import static org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE;
  65. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_KEY;
  66. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RESET;
  67. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_RULE;
  68. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SEVERITY;
  69. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TARGET_KEY;
  70. import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TARGET_SEVERITY;
  71. public class QProfilesWsMediumTest {
  72. @Rule
  73. public UserSessionRule userSessionRule = UserSessionRule.standalone()
  74. .logIn().setRoot();
  75. @Rule
  76. public EsTester es = EsTester.create();
  77. @Rule
  78. public DbTester dbTester = DbTester.create();
  79. private DbClient dbClient = dbTester.getDbClient();
  80. private DbSession dbSession = dbTester.getSession();
  81. private RuleIndex ruleIndex = new RuleIndex(es.client(), System2.INSTANCE);
  82. private RuleIndexer ruleIndexer = new RuleIndexer(es.client(), dbClient);
  83. private ActiveRuleIndexer activeRuleIndexer = new ActiveRuleIndexer(dbClient, es.client());
  84. private TypeValidations typeValidations = new TypeValidations(emptyList());
  85. private RuleActivator ruleActivator = new RuleActivator(System2.INSTANCE, dbClient, typeValidations, userSessionRule);
  86. private QProfileRules qProfileRules = new QProfileRulesImpl(dbClient, ruleActivator, ruleIndex, activeRuleIndexer);
  87. private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
  88. private QProfileWsSupport qProfileWsSupport = new QProfileWsSupport(dbClient, userSessionRule, defaultOrganizationProvider);
  89. private RuleWsSupport ruleWsSupport = new RuleWsSupport(dbClient, userSessionRule, defaultOrganizationProvider);
  90. private RuleQueryFactory ruleQueryFactory = new RuleQueryFactory(dbClient, ruleWsSupport);
  91. private OrganizationDto organization;
  92. private WsActionTester wsDeactivateRule = new WsActionTester(new DeactivateRuleAction(dbClient, qProfileRules, userSessionRule, qProfileWsSupport));
  93. private WsActionTester wsDeactivateRules = new WsActionTester(new DeactivateRulesAction(ruleQueryFactory, userSessionRule, qProfileRules, qProfileWsSupport, dbClient));
  94. private WsActionTester wsActivateRule = new WsActionTester(new ActivateRuleAction(dbClient, qProfileRules, userSessionRule, qProfileWsSupport));
  95. private WsActionTester wsActivateRules = new WsActionTester(new ActivateRulesAction(ruleQueryFactory, userSessionRule, qProfileRules, qProfileWsSupport, dbClient));
  96. @Before
  97. public void setUp() throws Exception {
  98. organization = dbTester.organizations().insert();
  99. }
  100. @Test
  101. public void deactivate_rule() {
  102. QProfileDto profile = createProfile("java");
  103. RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
  104. createActiveRule(rule, profile);
  105. ruleIndexer.commitAndIndex(dbSession, rule.getId());
  106. activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
  107. // 0. Assert No Active Rule for profile
  108. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(1);
  109. // 1. Deactivate Rule
  110. wsDeactivateRule.newRequest().setMethod("POST")
  111. .setParam(PARAM_KEY, profile.getKee())
  112. .setParam(PARAM_RULE, rule.getKey().toString())
  113. .execute();
  114. dbSession.clearCache();
  115. // 2. Assert ActiveRule in DAO
  116. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  117. }
  118. @Test
  119. public void bulk_deactivate_rule() {
  120. QProfileDto profile = createProfile("java");
  121. RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto1");
  122. RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "toto2");
  123. RuleDefinitionDto rule2 = createRule(profile.getLanguage(), "toto3");
  124. RuleDefinitionDto rule3 = createRule(profile.getLanguage(), "toto4");
  125. createActiveRule(rule0, profile);
  126. createActiveRule(rule2, profile);
  127. createActiveRule(rule3, profile);
  128. createActiveRule(rule1, profile);
  129. dbSession.commit();
  130. activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
  131. // 0. Assert No Active Rule for profile
  132. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(4);
  133. // 1. Deactivate Rule
  134. wsDeactivateRules.newRequest().setMethod("POST")
  135. .setParam(PARAM_TARGET_KEY, profile.getKee())
  136. .execute();
  137. dbSession.clearCache();
  138. // 2. Assert ActiveRule in DAO
  139. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  140. }
  141. @Test
  142. public void bulk_deactivate_rule_not_all() {
  143. QProfileDto profile = createProfile("java");
  144. QProfileDto php = createProfile("php");
  145. RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto1");
  146. RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "toto2");
  147. createActiveRule(rule0, profile);
  148. createActiveRule(rule1, profile);
  149. createActiveRule(rule0, php);
  150. createActiveRule(rule1, php);
  151. dbSession.commit();
  152. activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
  153. // 0. Assert No Active Rule for profile
  154. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(2);
  155. // 1. Deactivate Rule
  156. wsDeactivateRules.newRequest().setMethod("POST")
  157. .setParam(PARAM_TARGET_KEY, profile.getKee())
  158. .execute();
  159. dbSession.clearCache();
  160. // 2. Assert ActiveRule in DAO
  161. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(0);
  162. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, php.getKee())).hasSize(2);
  163. }
  164. @Test
  165. public void bulk_deactivate_rule_by_profile() {
  166. QProfileDto profile = createProfile("java");
  167. RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "hello");
  168. RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "world");
  169. createActiveRule(rule0, profile);
  170. createActiveRule(rule1, profile);
  171. dbSession.commit();
  172. activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
  173. // 0. Assert No Active Rule for profile
  174. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(2);
  175. // 1. Deactivate Rule
  176. wsDeactivateRules.newRequest().setMethod("POST")
  177. .setParam(PARAM_TARGET_KEY, profile.getKee())
  178. .setParam(Param.TEXT_QUERY, "hello")
  179. .execute();
  180. dbSession.clearCache();
  181. // 2. Assert ActiveRule in DAO
  182. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(1);
  183. }
  184. @Test
  185. public void activate_rule() {
  186. QProfileDto profile = createProfile("java");
  187. RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
  188. ruleIndexer.commitAndIndex(dbSession, rule.getId());
  189. // 0. Assert No Active Rule for profile
  190. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  191. // 1. Activate Rule
  192. wsActivateRule.newRequest().setMethod("POST")
  193. .setParam(PARAM_KEY, profile.getKee())
  194. .setParam(PARAM_RULE, rule.getKey().toString())
  195. .execute();
  196. dbSession.clearCache();
  197. // 2. Assert ActiveRule in DAO
  198. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(1);
  199. }
  200. @Test
  201. public void activate_rule_diff_languages() {
  202. QProfileDto profile = createProfile("java");
  203. RuleDefinitionDto rule = createRule("php", "toto");
  204. ruleIndexer.commitAndIndex(dbSession, rule.getId());
  205. // 0. Assert No Active Rule for profile
  206. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  207. try {
  208. // 1. Activate Rule
  209. wsActivateRule.newRequest().setMethod("POST")
  210. .setParam(PARAM_KEY, profile.getKee())
  211. .setParam(PARAM_RULE, rule.getKey().toString())
  212. .execute();
  213. dbSession.clearCache();
  214. fail();
  215. } catch (BadRequestException e) {
  216. assertThat(e.getMessage()).isEqualTo("php rule blah:toto cannot be activated on java profile Pjava");
  217. }
  218. }
  219. @Test
  220. public void activate_rule_override_severity() {
  221. QProfileDto profile = createProfile("java");
  222. RuleDefinitionDto rule = createRule(profile.getLanguage(), "toto");
  223. ruleIndexer.commitAndIndex(dbSession, rule.getId());
  224. // 0. Assert No Active Rule for profile
  225. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  226. // 1. Activate Rule
  227. wsActivateRule.newRequest().setMethod("POST")
  228. .setParam(PARAM_KEY, profile.getKee())
  229. .setParam(PARAM_RULE, rule.getKey().toString())
  230. .setParam(PARAM_SEVERITY, "MINOR")
  231. .execute();
  232. dbSession.clearCache();
  233. // 2. Assert ActiveRule in DAO
  234. ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile, rule.getKey());
  235. Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, activeRuleKey);
  236. assertThat(activeRuleDto.isPresent()).isTrue();
  237. assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR);
  238. }
  239. @Test
  240. public void bulk_activate_rule() throws Exception {
  241. QProfileDto profile = createProfile("java");
  242. createRule(profile.getLanguage(), "toto");
  243. createRule(profile.getLanguage(), "tata");
  244. createRule(profile.getLanguage(), "hello");
  245. createRule(profile.getLanguage(), "world");
  246. dbSession.commit();
  247. // 0. Assert No Active Rule for profile
  248. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  249. // 1. Activate Rule
  250. wsActivateRules.newRequest().setMethod("POST")
  251. .setParam(PARAM_TARGET_KEY, profile.getKee())
  252. .setParam(PARAM_LANGUAGES, "java")
  253. .execute()
  254. .assertJson(getClass(), "bulk_activate_rule.json");
  255. dbSession.clearCache();
  256. // 2. Assert ActiveRule in DAO
  257. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(4);
  258. }
  259. @Test
  260. public void bulk_activate_rule_not_all() throws Exception {
  261. QProfileDto java = createProfile("java");
  262. QProfileDto php = createProfile("php");
  263. createRule(java.getLanguage(), "toto");
  264. createRule(java.getLanguage(), "tata");
  265. createRule(php.getLanguage(), "hello");
  266. createRule(php.getLanguage(), "world");
  267. dbSession.commit();
  268. // 0. Assert No Active Rule for profile
  269. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, php.getKee())).isEmpty();
  270. // 1. Activate Rule
  271. wsActivateRules.newRequest().setMethod("POST")
  272. .setParam(PARAM_TARGET_KEY, php.getKee())
  273. .setParam(PARAM_LANGUAGES, "php")
  274. .execute()
  275. .assertJson(getClass(), "bulk_activate_rule_not_all.json");
  276. dbSession.clearCache();
  277. // 2. Assert ActiveRule in DAO
  278. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, php.getKee())).hasSize(2);
  279. }
  280. @Test
  281. public void bulk_activate_rule_by_query() {
  282. QProfileDto profile = createProfile("java");
  283. createRule(profile.getLanguage(), "toto");
  284. createRule(profile.getLanguage(), "tata");
  285. createRule(profile.getLanguage(), "hello");
  286. createRule(profile.getLanguage(), "world");
  287. dbSession.commit();
  288. // 0. Assert No Active Rule for profile
  289. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  290. // 1. Activate Rule with query returning 0 hits
  291. wsActivateRules.newRequest().setMethod("POST")
  292. .setParam(PARAM_TARGET_KEY, profile.getKee())
  293. .setParam(Param.TEXT_QUERY, "php")
  294. .execute();
  295. dbSession.clearCache();
  296. // 2. Assert ActiveRule in DAO
  297. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(0);
  298. // 1. Activate Rule with query returning 1 hits
  299. wsActivateRules.newRequest().setMethod("POST")
  300. .setParam(PARAM_TARGET_KEY, profile.getKee())
  301. .setParam(Param.TEXT_QUERY, "world")
  302. .execute();
  303. dbSession.commit();
  304. // 2. Assert ActiveRule in DAO
  305. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).hasSize(1);
  306. }
  307. @Test
  308. public void bulk_activate_rule_by_query_with_severity() {
  309. QProfileDto profile = createProfile("java");
  310. RuleDefinitionDto rule0 = createRule(profile.getLanguage(), "toto");
  311. RuleDefinitionDto rule1 = createRule(profile.getLanguage(), "tata");
  312. dbSession.commit();
  313. // 0. Assert No Active Rule for profile
  314. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, profile.getKee())).isEmpty();
  315. // 2. Assert ActiveRule with BLOCKER severity
  316. assertThat(ruleIndex.search(
  317. new RuleQuery().setSeverities(ImmutableSet.of("BLOCKER")),
  318. new SearchOptions()).getIds()).hasSize(2);
  319. // 1. Activate Rule with query returning 2 hits
  320. wsActivateRules.newRequest().setMethod("POST")
  321. .setParam(PARAM_TARGET_KEY, profile.getKee())
  322. .setParam(PARAM_TARGET_SEVERITY, "MINOR")
  323. .execute();
  324. dbSession.commit();
  325. // 2. Assert ActiveRule with MINOR severity
  326. assertThat(dbClient.activeRuleDao().selectByRuleId(dbSession, organization, rule0.getId()).get(0).getSeverityString()).isEqualTo("MINOR");
  327. assertThat(ruleIndex.searchAll(new RuleQuery()
  328. .setQProfile(profile)
  329. .setKey(rule0.getKey().toString())
  330. .setActiveSeverities(Collections.singleton("MINOR"))
  331. .setActivation(true))).toIterable().hasSize(1);
  332. }
  333. @Test
  334. public void does_not_return_warnings_when_bulk_activate_on_profile_and_rules_exist_on_another_language_than_profile() throws Exception {
  335. QProfileDto javaProfile = createProfile("java");
  336. createRule(javaProfile.getLanguage(), "toto");
  337. createRule(javaProfile.getLanguage(), "tata");
  338. QProfileDto phpProfile = createProfile("php");
  339. createRule(phpProfile.getLanguage(), "hello");
  340. createRule(phpProfile.getLanguage(), "world");
  341. dbSession.commit();
  342. // 1. Activate Rule
  343. wsActivateRules.newRequest().setMethod("POST")
  344. .setParam(PARAM_TARGET_KEY, javaProfile.getKee())
  345. .setParam(PARAM_QPROFILE, javaProfile.getKee())
  346. .setParam("activation", "false")
  347. .execute()
  348. .assertJson(getClass(), "does_not_return_warnings_when_bulk_activate_on_profile_and_rules_exist_on_another_language_than_profile.json");
  349. dbSession.clearCache();
  350. // 2. Assert ActiveRule in DAO
  351. assertThat(dbClient.activeRuleDao().selectByProfileUuid(dbSession, javaProfile.getKee())).hasSize(2);
  352. }
  353. @Test
  354. public void reset() {
  355. QProfileDto profile = QProfileTesting.newXooP1(organization);
  356. QProfileDto childProfile = QProfileTesting.newXooP2(organization).setParentKee(QProfileTesting.XOO_P1_KEY);
  357. dbClient.qualityProfileDao().insert(dbSession, profile, childProfile);
  358. RuleDefinitionDto rule = createRule(profile.getLanguage(), "rule");
  359. ActiveRuleDto active1 = ActiveRuleDto.createFor(profile, rule)
  360. .setSeverity(rule.getSeverityString());
  361. ActiveRuleDto active2 = ActiveRuleDto.createFor(childProfile, rule)
  362. .setSeverity("MINOR");
  363. dbClient.activeRuleDao().insert(dbSession, active1);
  364. dbClient.activeRuleDao().insert(dbSession, active2);
  365. dbSession.commit();
  366. activeRuleIndexer.indexOnStartup(activeRuleIndexer.getIndexTypes());
  367. // 0. assert rule child rule is minor
  368. Optional<ActiveRuleDto> activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey());
  369. assertThat(activeRuleDto.isPresent()).isTrue();
  370. assertThat(activeRuleDto.get().getSeverityString()).isEqualTo(Severity.MINOR);
  371. // 1. reset child rule
  372. wsActivateRule.newRequest().setMethod("POST")
  373. .setParam(PARAM_KEY, childProfile.getKee())
  374. .setParam(PARAM_RULE, rule.getKey().toString())
  375. .setParam(PARAM_RESET, "true")
  376. .execute();
  377. dbSession.clearCache();
  378. // 2. assert rule child rule is NOT minor
  379. activeRuleDto = dbClient.activeRuleDao().selectByKey(dbSession, active2.getKey());
  380. assertThat(activeRuleDto.isPresent()).isTrue();
  381. assertThat(activeRuleDto.get().getSeverityString()).isNotEqualTo(Severity.MINOR);
  382. }
  383. private QProfileDto createProfile(String lang) {
  384. QProfileDto profile = QProfileTesting.newQProfileDto(organization, new QProfileName(lang, "P" + lang), "p" + lang);
  385. dbClient.qualityProfileDao().insert(dbSession, profile);
  386. return profile;
  387. }
  388. private RuleDefinitionDto createRule(String lang, String id) {
  389. RuleDefinitionDto rule = RuleTesting.newRule(RuleKey.of("blah", id))
  390. .setLanguage(lang)
  391. .setSeverity(Severity.BLOCKER)
  392. .setStatus(RuleStatus.READY);
  393. dbClient.ruleDao().insert(dbSession, rule);
  394. ruleIndexer.commitAndIndex(dbSession, rule.getId());
  395. return rule;
  396. }
  397. private ActiveRuleDto createActiveRule(RuleDefinitionDto rule, QProfileDto profile) {
  398. ActiveRuleDto activeRule = ActiveRuleDto.createFor(profile, rule)
  399. .setSeverity(rule.getSeverityString());
  400. dbClient.activeRuleDao().insert(dbSession, activeRule);
  401. return activeRule;
  402. }
  403. }