aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-03-22 16:33:44 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2018-03-27 16:49:59 +0200
commitf5cee605d7e9cc4642f1223d8401fa2e42ed88cc (patch)
treeb551d14d088b4c6784cc1398f4c7117b77bf7851
parent917359a23040adb556e0bfac2b3659d2f35706ab (diff)
downloadsonarqube-f5cee605d7e9cc4642f1223d8401fa2e42ed88cc.tar.gz
sonarqube-f5cee605d7e9cc4642f1223d8401fa2e42ed88cc.zip
SONAR-10480 support reading long version in snapshot
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java7
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java17
3 files changed, 24 insertions, 2 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
index 1dfec6f1b93..cca2afb12dd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
@@ -127,6 +127,13 @@ public final class SnapshotDto {
return this;
}
+ /**
+ * Used by MyBatis
+ */
+ private void setRawVersion(@Nullable String version) {
+ this.version = version;
+ }
+
public SnapshotDto setPeriodMode(@Nullable String p) {
periodMode = p;
return this;
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
index d22ffebb330..3cf493d3241 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
@@ -11,7 +11,7 @@
s.status as status,
s.purge_status as purgeStatus,
s.islast as last,
- s.version as version,
+ s.version as rawVersion,
s.period1_mode as periodMode,
s.period1_param as periodParam,
s.period1_date as periodDate
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
index d7128820a72..45372008dcc 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
+import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -190,7 +191,7 @@ public class SnapshotDaoTest {
}
@Test
- public void select_first_snapshots() throws Exception {
+ public void select_first_snapshots() {
ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization());
db.getDbClient().componentDao().insert(dbSession, project);
@@ -399,6 +400,20 @@ public class SnapshotDaoTest {
assertThat(result.getComponentUuid()).isEqualTo("P1");
}
+ @Test
+ public void snashotDto_can_hold_version_larger_than_100_read_from_database() {
+ SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false);
+ db.commit();
+ String tooLongVersion = StringUtils.repeat("d", 200);
+ db.executeUpdateSql("update snapshots set version='" + tooLongVersion + "' where uuid='" + analysis.getUuid() + "'");
+ db.commit();
+
+ assertThat(underTest.selectByUuid(dbSession, analysis.getUuid())
+ .map(SnapshotDto::getVersion))
+ .contains(tooLongVersion);
+
+ }
+
private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) {
SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
.setLast(isLastFlag)