aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-08-22 17:34:28 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-08-24 11:54:24 +0200
commit8bdb9fde4be635c666ce0b09a851789a5ecfc870 (patch)
treed805da4bcb12289c8a38304cc99eaa924611373c
parent71291b751aed27c2b62effcd2852e5e89dd4a9e9 (diff)
downloadsonarqube-8bdb9fde4be635c666ce0b09a851789a5ecfc870.tar.gz
sonarqube-8bdb9fde4be635c666ce0b09a851789a5ecfc870.zip
SONAR-7493 support long issue messages on Oracle
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java10
-rw-r--r--tests/src/test/java/org/sonarqube/tests/issue/IssueCreationTest.java38
3 files changed, 49 insertions, 5 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
index f51d9bb30be..f9c36b3bc2a 100644
--- a/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/issue/DefaultIssueTest.java
@@ -36,7 +36,7 @@ import static org.mockito.Mockito.mock;
public class DefaultIssueTest {
- DefaultIssue issue = new DefaultIssue();
+ private DefaultIssue issue = new DefaultIssue();
@Test
public void test_setters_and_getters() throws Exception {
@@ -152,8 +152,8 @@ public class DefaultIssueTest {
@Test
public void message_should_be_abbreviated_if_too_long() {
- issue.setMessage(StringUtils.repeat("a", 5000));
- assertThat(issue.message()).hasSize(4000);
+ issue.setMessage(StringUtils.repeat("a", 5_000));
+ assertThat(issue.message()).hasSize(1_333);
}
@Test
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
index 314d704cba2..4ed5b6750c9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/Issue.java
@@ -38,8 +38,14 @@ public interface Issue extends Serializable {
/**
* Maximum number of characters in the message.
- */
- int MESSAGE_MAX_SIZE = 4000;
+ * In theory it should be 4_000 UTF-8 characters but unfortunately
+ * Oracle DB does not support more than 4_000 bytes, even if column
+ * issues.message is created with type VARCHAR2(4000 CHAR).
+ * In order to have the same behavior on all databases, message
+ * is truncated to 4_000 / 3 (maximum bytes per UTF-8 character)
+ * = 1_333 characters.
+ */
+ int MESSAGE_MAX_SIZE = 1_333;
/**
* Default status when creating an issue.
diff --git a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationTest.java b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationTest.java
index b6afaf17304..6c7d72ed9d5 100644
--- a/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationTest.java
+++ b/tests/src/test/java/org/sonarqube/tests/issue/IssueCreationTest.java
@@ -19,6 +19,7 @@
*/
package org.sonarqube.tests.issue;
+import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.sonar.wsclient.issue.Issue;
@@ -32,6 +33,7 @@ import static util.ItUtils.runProjectAnalysis;
public class IssueCreationTest extends AbstractIssueTest {
private static final String SAMPLE_PROJECT_KEY = "sample";
+ private static final int ISSUE_MESSAGE_MAX_LENGTH = 1_333;
@Before
public void resetData() {
@@ -75,4 +77,40 @@ public class IssueCreationTest extends AbstractIssueTest {
assertThat(issue.severity()).isEqualTo("BLOCKER");
}
}
+
+ /**
+ * SONAR-7493
+ */
+ @Test
+ public void issue_message_should_support_1_333_utf8_characters_encoded_on_3_bytes() {
+ String longMessage = StringUtils.repeat("を", ISSUE_MESSAGE_MAX_LENGTH);
+
+ assertThat(generateIssueWithMessage(longMessage)).isEqualTo(longMessage);
+ }
+
+ /**
+ * Test the maximum size of DB column issues.message, when all characters
+ * are encoded on 3-bytes
+ *
+ * SONAR-7493
+ */
+ @Test
+ public void issue_message_should_be_abbreviated_if_longer_than_1333_utf8_characters_encoded_on_3_bytes() {
+ String character = "を";
+ String message = generateIssueWithMessage(StringUtils.repeat(character, 10_000));
+
+ String abbreviatedMessage = StringUtils.repeat(character, ISSUE_MESSAGE_MAX_LENGTH - 3) + "...";
+ assertThat(message).isEqualTo(abbreviatedMessage);
+ }
+
+ private String generateIssueWithMessage(String longMessage) {
+ ORCHESTRATOR.getServer().provisionProject(SAMPLE_PROJECT_KEY, SAMPLE_PROJECT_KEY);
+ ItUtils.restoreProfile(ORCHESTRATOR, getClass().getResource("/issue/IssueCreationTest/with-custom-message.xml"));
+ ORCHESTRATOR.getServer().associateProjectToQualityProfile(SAMPLE_PROJECT_KEY, "xoo", "with-custom-message");
+
+ runProjectAnalysis(ORCHESTRATOR, "shared/xoo-sample", "sonar.customMessage.message", longMessage);
+
+ Issue issue = issueClient().find(IssueQuery.create()).list().get(0);
+ return issue.message();
+ }
}