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.

IndexedIssueDtoTest.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 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.db.issue;
  21. import java.util.Set;
  22. import org.junit.Test;
  23. import org.sonar.api.issue.Issue;
  24. import org.sonar.api.issue.impact.Severity;
  25. import org.sonar.api.issue.impact.SoftwareQuality;
  26. import org.sonar.core.issue.status.SimpleStatus;
  27. import static org.assertj.core.api.Assertions.assertThat;
  28. import static org.assertj.core.api.Assertions.assertThatThrownBy;
  29. import static org.assertj.core.groups.Tuple.tuple;
  30. public class IndexedIssueDtoTest {
  31. @Test
  32. public void settersGetters_shouldSetAndGetValues() {
  33. IndexedIssueDto indexedIssueDto = new IndexedIssueDto()
  34. .setIssueKey("issueKey")
  35. .setAssignee("assignee")
  36. .setAuthorLogin("authorLogin")
  37. .setStatus("status")
  38. .setNewCodeReferenceIssue(true)
  39. .setCleanCodeAttribute("cleanCodeAttribute")
  40. .setRuleCleanCodeAttribute("ruleCleanCodeAttribute")
  41. .setCodeVariants("codeVariants")
  42. .setSecurityStandards("securityStandards")
  43. .setComponentUuid("componentUuid")
  44. .setIssueCloseDate(1L)
  45. .setIssueCreationDate(2L)
  46. .setIssueUpdateDate(3L)
  47. .setEffort(4L)
  48. .setIsMain(true)
  49. .setLanguage("language")
  50. .setLine(5)
  51. .setPath("path")
  52. .setProjectUuid("projectUuid")
  53. .setQualifier("qualifier")
  54. .setResolution("resolution")
  55. .setRuleUuid("ruleUuid")
  56. .setScope("scope")
  57. .setSeverity("severity")
  58. .setTags("tags")
  59. .setIssueType(6)
  60. .setBranchUuid("branchUuid");
  61. indexedIssueDto.getImpacts().add(new ImpactDto().setSoftwareQuality(SoftwareQuality.SECURITY).setSeverity(Severity.HIGH));
  62. indexedIssueDto.getRuleDefaultImpacts().add(new ImpactDto().setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(Severity.MEDIUM));
  63. assertThat(indexedIssueDto)
  64. .extracting(IndexedIssueDto::getIssueKey, IndexedIssueDto::getAssignee, IndexedIssueDto::getAuthorLogin, IndexedIssueDto::getStatus,
  65. IndexedIssueDto::isNewCodeReferenceIssue, IndexedIssueDto::getCleanCodeAttribute, IndexedIssueDto::getRuleCleanCodeAttribute, IndexedIssueDto::getCodeVariants,
  66. IndexedIssueDto::getSecurityStandards, IndexedIssueDto::getComponentUuid, IndexedIssueDto::getIssueCloseDate, IndexedIssueDto::getIssueCreationDate,
  67. IndexedIssueDto::getIssueUpdateDate, IndexedIssueDto::getEffort, IndexedIssueDto::isMain, IndexedIssueDto::getLanguage, IndexedIssueDto::getLine,
  68. IndexedIssueDto::getPath, IndexedIssueDto::getProjectUuid, IndexedIssueDto::getQualifier, IndexedIssueDto::getResolution,
  69. IndexedIssueDto::getRuleUuid, IndexedIssueDto::getScope, IndexedIssueDto::getSeverity, IndexedIssueDto::getTags, IndexedIssueDto::getIssueType,
  70. IndexedIssueDto::getBranchUuid)
  71. .containsExactly("issueKey", "assignee", "authorLogin", "status", true, "cleanCodeAttribute", "ruleCleanCodeAttribute", "codeVariants", "securityStandards",
  72. "componentUuid", 1L, 2L, 3L, 4L, true, "language", 5, "path", "projectUuid", "qualifier", "resolution", "ruleUuid",
  73. "scope", "severity", "tags", 6, "branchUuid");
  74. assertThat(indexedIssueDto.getImpacts())
  75. .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity)
  76. .containsExactly(tuple(SoftwareQuality.SECURITY, Severity.HIGH));
  77. assertThat(indexedIssueDto.getRuleDefaultImpacts())
  78. .extracting(ImpactDto::getSoftwareQuality, ImpactDto::getSeverity)
  79. .containsExactly(tuple(SoftwareQuality.MAINTAINABILITY, Severity.MEDIUM));
  80. assertThat(indexedIssueDto.getEffectiveImpacts())
  81. .containsEntry(SoftwareQuality.MAINTAINABILITY, Severity.MEDIUM)
  82. .containsEntry(SoftwareQuality.SECURITY, Severity.HIGH);
  83. }
  84. @Test
  85. public void getSimpleStatus_shouldReturnSimpleStatusFromStatusAndResolution() {
  86. IndexedIssueDto issue1 = new IndexedIssueDto().setStatus(Issue.STATUS_OPEN);
  87. IndexedIssueDto issue2 = new IndexedIssueDto().setStatus(Issue.STATUS_RESOLVED).setResolution(Issue.RESOLUTION_WONT_FIX);
  88. IndexedIssueDto issue3 = new IndexedIssueDto().setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED);
  89. assertThat(Set.of(issue1, issue2, issue3)).extracting(IndexedIssueDto::getSimpleStatus)
  90. .containsExactlyInAnyOrder(SimpleStatus.OPEN.name(), SimpleStatus.ACCEPTED.name(), SimpleStatus.FIXED.name());
  91. IndexedIssueDto issueWithStatusNull = new IndexedIssueDto();
  92. assertThatThrownBy(issueWithStatusNull::getSimpleStatus)
  93. .isInstanceOf(IllegalArgumentException.class)
  94. .hasMessage("Status must be initialized to retrieve simple status");
  95. }
  96. }