*/
package org.sonar.server.rule;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import org.assertj.core.api.Fail;
import org.assertj.core.groups.Tuple;
.setMarkdownDescription("Some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
RuleKey customRuleKey = underTest.create(dbSession, newRule);
RuleDto rule = dbTester.getDbClient().ruleDao().selectOrFailByKey(dbSession, customRuleKey);
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", ""));
+ .setParameters(Map.of("regex", ""));
RuleKey customRuleKey = underTest.create(dbSession, newRule);
.setSeverity(Severity.MAJOR)
.setType(RuleType.SECURITY_HOTSPOT)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", ""));
+ .setParameters(Map.of("regex", ""));
RuleKey customRuleKey = underTest.create(dbSession, newRule);
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("myIntegers", "1,3"));
+ .setParameters(Map.of("myIntegers", "1,3"));
RuleKey customRuleKey = underTest.create(dbSession, newRule);
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, singletonList(newRule)))
.isInstanceOf(IllegalArgumentException.class)
.setMarkdownDescription("Some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("myIntegers", "1,polop,2"));
+ .setParameters(Map.of("myIntegers", "1,polop,2"));
underTest.create(dbSession, newRule);
})
.isInstanceOf(BadRequestException.class)
.setMarkdownDescription("Some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("first", "polop", "second", "palap"));
+ .setParameters(Map.of("first", "polop", "second", "palap"));
try {
underTest.create(dbSession, newRule);
Fail.failBecauseExceptionWasNotThrown(BadRequestException.class);
.setMarkdownDescription("New description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "c.*"));
+ .setParameters(Map.of("regex", "c.*"));
RuleKey customRuleKey = underTest.create(dbSession, newRule);
RuleDto result = dbTester.getDbClient().ruleDao().selectOrFailByKey(dbSession, customRuleKey);
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "c.*"))
+ .setParameters(Map.of("regex", "c.*"))
.setPreventReactivation(true);
try {
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, newRule))
.isInstanceOf(BadRequestException.class)
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*")));
+ .setParameters(Map.of("regex", "a.*")));
underTest.create(dbSession, newRule.get());
// Create another custom rule having same key
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*")));
+ .setParameters(Map.of("regex", "a.*")));
assertThatThrownBy(() -> underTest.create(dbSession, newRule.get()))
.isInstanceOf(IllegalArgumentException.class)
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, newRule))
.isInstanceOf(BadRequestException.class)
.setName("My custom")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
underTest.create(dbSession, newRule);
})
.isInstanceOf(BadRequestException.class)
.setName("My custom")
.setMarkdownDescription("some description")
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, newRule))
.isInstanceOf(BadRequestException.class)
.setMarkdownDescription("some description")
.setSeverity("INVALID")
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, newRule))
.isInstanceOf(BadRequestException.class)
.setName("My custom")
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, newRule))
.isInstanceOf(BadRequestException.class)
.setMarkdownDescription("some description")
.setSeverity(Severity.MAJOR)
.setStatus(RuleStatus.READY)
- .setParameters(ImmutableMap.of("regex", "a.*"));
+ .setParameters(Map.of("regex", "a.*"));
assertThatThrownBy(() -> underTest.create(dbSession, newRule))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("The template key doesn't exist: java:S001");
}
+ @Test
+ public void create_givenSecurityHotspotRule_doNotSetCleanCodeAttribute() {
+ RuleDto templateRule = createTemplateRule();
+
+ NewCustomRule newRule = NewCustomRule.createForCustomRule("security_hotspots_rule", templateRule.getKey())
+ .setName("My custom")
+ .setMarkdownDescription("some description")
+ .setSeverity(Severity.MAJOR)
+ .setStatus(RuleStatus.READY)
+ .setType(RuleType.SECURITY_HOTSPOT);
+
+ RuleKey customRuleKey = underTest.create(dbSession, newRule);
+
+ RuleDto result = dbTester.getDbClient().ruleDao().selectOrFailByKey(dbSession, customRuleKey);
+
+ assertThat(result.getCleanCodeAttribute()).isNull();
+ }
+
private RuleDto createTemplateRule() {
RuleDto templateRule = RuleTesting.newRule(RuleKey.of("java", "S001"))
.setIsTemplate(true)