diff options
author | Dimitris Kavvathas <dimitris.kavvathas@sonarsource.com> | 2023-07-20 15:41:51 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-02 20:03:03 +0000 |
commit | bb784c0d359bdb37286c77d25897728b8ea85563 (patch) | |
tree | 523d50a9ab33f55d672f8b1dc7076d023c4b65fd /sonar-core | |
parent | 30abc015459aecb07ea2e3fba2b4bba52a652f74 (diff) | |
download | sonarqube-bb784c0d359bdb37286c77d25897728b8ea85563.tar.gz sonarqube-bb784c0d359bdb37286c77d25897728b8ea85563.zip |
SONAR-19372 add api/issues/anticipated_transitions endpoint
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/AnticipatedTransition.java | 150 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/AnticipatedTransitionTest.java | 74 |
2 files changed, 224 insertions, 0 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/AnticipatedTransition.java b/sonar-core/src/main/java/org/sonar/core/issue/AnticipatedTransition.java new file mode 100644 index 00000000000..5d0fe394964 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/issue/AnticipatedTransition.java @@ -0,0 +1,150 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue; + +import java.time.Instant; +import java.util.Date; +import java.util.Objects; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.jetbrains.annotations.Nullable; +import org.sonar.api.issue.Issue; +import org.sonar.api.rule.RuleKey; +import org.sonar.core.issue.tracking.Trackable; + +public class AnticipatedTransition implements Trackable { + + private final String projectKey; + private final String branch; + private final String transition; + private final String userUuid; + private final String comment; + private final String filePath; + private final Integer line; + private final String message; + private final String lineHash; + private final RuleKey ruleKey; + + public AnticipatedTransition( + String projectKey, + @Nullable String branch, + String userUuid, + @Nullable RuleKey ruleKey, + @Nullable String message, + @Nullable String filePath, + @Nullable Integer line, + @Nullable String lineHash, + String transition, + @Nullable String comment) { + this.projectKey = projectKey; + this.branch = branch; + this.transition = transition; + this.userUuid = userUuid; + this.comment = comment; + this.filePath = filePath; + this.line = line; + this.message = message; + this.lineHash = lineHash; + this.ruleKey = ruleKey; + } + + public String getProjectKey() { + return projectKey; + } + + public String getBranch() { + return branch; + } + + public String getTransition() { + return transition; + } + + public String getUserUuid() { + return userUuid; + } + + public String getComment() { + return comment; + } + + public String getFilePath() { + return filePath; + } + + @Nullable + @Override + public Integer getLine() { + return line; + } + + @Nullable + @Override + public String getMessage() { + return message; + } + + @Nullable + @Override + public String getLineHash() { + return lineHash; + } + + @Override + public RuleKey getRuleKey() { + return ruleKey; + } + + @Override + public String getStatus() { + // Since it's an anticipated transition, the issue will always be open upon the first analysis. + return Issue.STATUS_OPEN; + } + + @Override + public Date getUpdateDate() { + return Date.from(Instant.now()); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AnticipatedTransition that = (AnticipatedTransition) o; + return Objects.equals(projectKey, that.projectKey) + && Objects.equals(branch, that.branch) + && Objects.equals(transition, that.transition) + && Objects.equals(userUuid, that.userUuid) + && Objects.equals(comment, that.comment) + && Objects.equals(filePath, that.filePath) + && Objects.equals(line, that.line) + && Objects.equals(message, that.message) + && Objects.equals(lineHash, that.lineHash) + && Objects.equals(ruleKey, that.ruleKey); + } + + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/issue/AnticipatedTransitionTest.java b/sonar-core/src/test/java/org/sonar/core/issue/AnticipatedTransitionTest.java new file mode 100644 index 00000000000..041753af341 --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/issue/AnticipatedTransitionTest.java @@ -0,0 +1,74 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.issue; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.sonar.api.rule.RuleKey; + +public class AnticipatedTransitionTest { + + @Test + public void givenTwoAnticipatedTransitions_whenFieldsHaveTheSameValue_theyShouldBeEqual() { + AnticipatedTransition anticipatedTransition = getAnticipatedTransition(); + AnticipatedTransition anticipatedTransition2 = getAnticipatedTransition(); + + assertFieldsAreTheSame(anticipatedTransition, anticipatedTransition2); + Assertions.assertThat(anticipatedTransition).isEqualTo(anticipatedTransition2); + } + + @Test + public void givenTwoAnticipatedTransitions_whenFieldsHaveTheSameValue_hashcodeShouldBeTheSame() { + AnticipatedTransition anticipatedTransition = getAnticipatedTransition(); + AnticipatedTransition anticipatedTransition2 = getAnticipatedTransition(); + + assertFieldsAreTheSame(anticipatedTransition, anticipatedTransition2); + Assertions.assertThat(anticipatedTransition).hasSameHashCodeAs(anticipatedTransition2); + } + + private void assertFieldsAreTheSame(AnticipatedTransition anticipatedTransition, AnticipatedTransition anticipatedTransition2) { + Assertions.assertThat(anticipatedTransition.getProjectKey()).isEqualTo(anticipatedTransition2.getProjectKey()); + Assertions.assertThat(anticipatedTransition.getBranch()).isEqualTo(anticipatedTransition2.getBranch()); + Assertions.assertThat(anticipatedTransition.getUserUuid()).isEqualTo(anticipatedTransition2.getUserUuid()); + Assertions.assertThat(anticipatedTransition.getTransition()).isEqualTo(anticipatedTransition2.getTransition()); + Assertions.assertThat(anticipatedTransition.getComment()).isEqualTo(anticipatedTransition2.getComment()); + Assertions.assertThat(anticipatedTransition.getFilePath()).isEqualTo(anticipatedTransition2.getFilePath()); + Assertions.assertThat(anticipatedTransition.getLine()).isEqualTo(anticipatedTransition2.getLine()); + Assertions.assertThat(anticipatedTransition.getMessage()).isEqualTo(anticipatedTransition2.getMessage()); + Assertions.assertThat(anticipatedTransition.getLineHash()).isEqualTo(anticipatedTransition2.getLineHash()); + Assertions.assertThat(anticipatedTransition.getRuleKey()).isEqualTo(anticipatedTransition2.getRuleKey()); + } + + private AnticipatedTransition getAnticipatedTransition() { + return new AnticipatedTransition( + "projectKey", + "branch", + "userUuid", + RuleKey.parse("rule:key"), + "message", + "filepath", + 1, + "lineHash", + "transition", + "comment" + ); + } + +} |