diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2019-02-21 15:23:29 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-02-21 20:21:18 +0100 |
commit | 746ff42c58b6ee5c051de33cc13e3a0af45e7647 (patch) | |
tree | a17100615a9aaa635feec3d49f0b8afd63fcbaf3 /server/sonar-db-dao | |
parent | 857c27b744321ddbdd7dbc12e761ee11b83e6288 (diff) | |
download | sonarqube-746ff42c58b6ee5c051de33cc13e3a0af45e7647.tar.gz sonarqube-746ff42c58b6ee5c051de33cc13e3a0af45e7647.zip |
stabilize BranchDaoTest on Oracle
Diffstat (limited to 'server/sonar-db-dao')
3 files changed, 32 insertions, 11 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java index d2deefe5a59..4b8a56bfbc7 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDao.java @@ -74,7 +74,7 @@ public class BranchDao implements Dao { */ public int updateManualBaseline(DbSession dbSession, String uuid, @Nullable String analysisUuid) { long now = system2.now(); - return mapper(dbSession).updateManualBaseline(uuid, analysisUuid, now); + return mapper(dbSession).updateManualBaseline(uuid, analysisUuid == null || analysisUuid.isEmpty() ? null : analysisUuid, now); } public Optional<BranchDto> selectByBranchKey(DbSession dbSession, String projectUuid, String key) { diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java index 411f1138554..564dba19135 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java @@ -201,7 +201,7 @@ public class BranchDto { } public BranchDto setManualBaseline(@Nullable String manualBaseline) { - this.manualBaseline = manualBaseline; + this.manualBaseline = manualBaseline == null || manualBaseline.isEmpty() ? null : manualBaseline; return this; } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java index aab5f139966..5de6c618c90 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java @@ -101,30 +101,44 @@ public class BranchDaoTest { } @Test - @UseDataProvider("nullOrEmptyOrValue") - public void insert_manual_baseline_analysis_uuid(@Nullable String manualBaselineAnalysisUuid) { + @UseDataProvider("nullOrEmpty") + public void insert_null_or_empty_manual_baseline_analysis_uuid_is_null(@Nullable String nullOrEmpty) { BranchDto dto = new BranchDto(); dto.setProjectUuid("U1"); dto.setUuid("U1"); dto.setBranchType(BranchType.LONG); dto.setKey("foo"); - dto.setManualBaseline(manualBaselineAnalysisUuid); + dto.setManualBaseline(nullOrEmpty); underTest.insert(dbSession, dto); - assertThat(underTest.selectByUuid(dbSession, dto.getUuid()).get().getManualBaseline()).isEqualTo(manualBaselineAnalysisUuid); + assertThat(underTest.selectByUuid(dbSession, dto.getUuid()).get().getManualBaseline()).isNull(); } @DataProvider - public static Object[][] nullOrEmptyOrValue() { + public static Object[][] nullOrEmpty() { return new Object[][] { {null}, - {""}, - {randomAlphabetic(12)} + {""} }; } @Test + public void insert_manual_baseline_analysis_uuid() { + String manualBaselineAnalysisUuid = randomAlphabetic(12); + BranchDto dto = new BranchDto(); + dto.setProjectUuid("U1"); + dto.setUuid("U1"); + dto.setBranchType(BranchType.LONG); + dto.setKey("foo"); + dto.setManualBaseline(manualBaselineAnalysisUuid); + + underTest.insert(dbSession, dto); + + assertThat(underTest.selectByUuid(dbSession, dto.getUuid()).get().getManualBaseline()).isEqualTo(manualBaselineAnalysisUuid); + } + + @Test @UseDataProvider("oldAndNewValuesCombinations") public void update_manualBaselineAnalysisUuid_if_new_value_is_different(@Nullable String oldValue, @Nullable String newValue) { BranchDto dto = new BranchDto(); @@ -146,9 +160,9 @@ public class BranchDaoTest { assertThat(underTest.updateManualBaseline(dbSession, dto.getUuid(), newValue)).isEqualTo(1); assertThat(underTest.selectByUuid(dbSession, dto.getUuid()).get().getManualBaseline()) - .isEqualTo(newValue); + .isEqualTo(emptyToNull(newValue)); assertThat(underTest.selectByUuid(dbSession, otherDtoThatShouldNotChange.getUuid()).get().getManualBaseline()) - .isEqualTo(oldValue); + .isEqualTo(emptyToNull(oldValue)); } @DataProvider @@ -157,9 +171,12 @@ public class BranchDaoTest { String value2 = randomAlphabetic(20); return new Object[][] { {null, value1}, + {"", value1}, {value1, null}, + {value1, ""}, {value1, value2}, {null, null}, + {"", null}, {value1, value1} }; } @@ -515,4 +532,8 @@ public class BranchDaoTest { assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW)).isEqualTo(1); assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW + 100)).isEqualTo(0); } + + private static String emptyToNull(@Nullable String newValue) { + return newValue == null || newValue.isEmpty() ? null : newValue; + } } |