public class DefaultIssueTest {
- DefaultIssue issue = new DefaultIssue();
+ private DefaultIssue issue = new DefaultIssue();
@Test
public void test_setters_and_getters() throws Exception {
@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
/**
* 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.
*/
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;
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() {
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();
+ }
}