assertThat(db.activeRuleDao().findByProfileKey(session, php.getKey())).hasSize(2);
}
@Test
public void bulk_activate_rule_by_query() throws Exception {
QualityProfileDto profile = createProfile("java");
RuleDto rule0 = createRule(profile.getLanguage(), "toto");
RuleDto rule1 = createRule(profile.getLanguage(), "tata");
RuleDto rule2 = createRule(profile.getLanguage(), "hello");
RuleDto rule3 = createRule(profile.getLanguage(), "world");
session.commit();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule with query returning 0 hits
WsTester.TestRequest request = wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
request.setParam(SearchOptions.PARAM_TEXT_QUERY, "php");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(0);
// 1. Activate Rule with query returning 1 hits
request = wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey().toString());
request.setParam(SearchOptions.PARAM_TEXT_QUERY, "world");
result = request.execute();
session.commit();
// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().findByProfileKey(session, profile.getKey())).hasSize(1);
}