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.3KB

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