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.

XooRulesDefinitionTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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.xoo.rule;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.sonar.api.SonarEdition;
  24. import org.sonar.api.SonarQubeSide;
  25. import org.sonar.api.impl.server.RulesDefinitionContext;
  26. import org.sonar.api.internal.SonarRuntimeImpl;
  27. import org.sonar.api.server.debt.DebtRemediationFunction;
  28. import org.sonar.api.server.rule.RulesDefinition;
  29. import org.sonar.api.utils.Version;
  30. import static org.assertj.core.api.Assertions.assertThat;
  31. public class XooRulesDefinitionTest {
  32. private XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY));
  33. private RulesDefinition.Context context = new RulesDefinitionContext();
  34. @Before
  35. public void setUp() {
  36. def.define(context);
  37. }
  38. @Test
  39. public void define_xoo_rules() {
  40. RulesDefinition.Repository repo = context.repository("xoo");
  41. assertThat(repo).isNotNull();
  42. assertThat(repo.name()).isEqualTo("Xoo");
  43. assertThat(repo.language()).isEqualTo("xoo");
  44. assertThat(repo.rules()).hasSize(22);
  45. RulesDefinition.Rule rule = repo.rule(OneIssuePerLineSensor.RULE_KEY);
  46. assertThat(rule.name()).isNotEmpty();
  47. assertThat(rule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
  48. assertThat(rule.debtRemediationFunction().gapMultiplier()).isEqualTo("1min");
  49. assertThat(rule.debtRemediationFunction().baseEffort()).isNull();
  50. assertThat(rule.gapDescription()).isNotEmpty();
  51. }
  52. @Test
  53. public void define_xoo_hotspot_rule() {
  54. RulesDefinition.Repository repo = context.repository("xoo");
  55. assertThat(repo).isNotNull();
  56. assertThat(repo.name()).isEqualTo("Xoo");
  57. assertThat(repo.language()).isEqualTo("xoo");
  58. assertThat(repo.rules()).hasSize(22);
  59. RulesDefinition.Rule rule = repo.rule(HotspotSensor.RULE_KEY);
  60. assertThat(rule.name()).isNotEmpty();
  61. assertThat(rule.securityStandards())
  62. .isNotEmpty()
  63. .containsExactlyInAnyOrder("cwe:1", "cwe:89", "cwe:123", "cwe:863", "owaspTop10:a1", "owaspTop10:a3");
  64. }
  65. @Test
  66. public void define_xooExternal_rules() {
  67. RulesDefinition.Repository repo = context.repository("external_XooEngine");
  68. assertThat(repo).isNotNull();
  69. assertThat(repo.name()).isEqualTo("XooEngine");
  70. assertThat(repo.language()).isEqualTo("xoo");
  71. assertThat(repo.rules()).hasSize(1);
  72. }
  73. @Test
  74. public void define_xoo2_rules() {
  75. RulesDefinition.Repository repo = context.repository("xoo2");
  76. assertThat(repo).isNotNull();
  77. assertThat(repo.name()).isEqualTo("Xoo2");
  78. assertThat(repo.language()).isEqualTo("xoo2");
  79. assertThat(repo.rules()).hasSize(2);
  80. }
  81. }