aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-08-08 13:43:01 -0500
committerSonarTech <sonartech@sonarsource.com>2019-09-24 20:21:13 +0200
commit7eaf366fa7f51a69032d840b466f5068ce88239b (patch)
tree35f366da92ef96544bdcf3b99af55b9258812c41 /server/sonar-db-dao
parent14bd90f47ee950d4ee780cbd2a030cac5cb034c0 (diff)
downloadsonarqube-7eaf366fa7f51a69032d840b466f5068ce88239b.tar.gz
sonarqube-7eaf366fa7f51a69032d840b466f5068ce88239b.zip
SONAR-12394 Load analysis new code period based on hierarchy of New Code Period settings
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDaoTest.java7
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDbTester.java28
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java25
4 files changed, 36 insertions, 28 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java
index 7f15ce10ad6..0cb308b6991 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/newcodeperiod/NewCodePeriodDao.java
@@ -41,8 +41,8 @@ public class NewCodePeriodDao implements Dao {
return mapper(dbSession).selectByUuid(uuid);
}
- public NewCodePeriodDto selectGlobal(DbSession dbSession) {
- return mapper(dbSession).selectGlobal();
+ public Optional<NewCodePeriodDto> selectGlobal(DbSession dbSession) {
+ return Optional.ofNullable(mapper(dbSession).selectGlobal());
}
public void insert(DbSession dbSession, NewCodePeriodDto dto) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDaoTest.java
index 9e5d521f216..c9e07d6addb 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDaoTest.java
@@ -74,6 +74,11 @@ public class NewCodePeriodDaoTest {
}
@Test
+ public void select_global_with_no_value() {
+ assertThat(underTest.selectGlobal(dbSession)).isEmpty();
+ }
+
+ @Test
public void update_new_code_period() {
when(uuidFactory.create()).thenReturn(NEW_CODE_PERIOD_UUID);
@@ -230,7 +235,7 @@ public class NewCodePeriodDaoTest {
.setType(NewCodePeriodType.NUMBER_OF_DAYS)
.setValue("30"));
- NewCodePeriodDto result = underTest.selectGlobal(dbSession);
+ NewCodePeriodDto result = underTest.selectGlobal(dbSession).get();
assertThat(result.getUuid()).isEqualTo(NEW_CODE_PERIOD_UUID);
assertThat(result.getProjectUuid()).isNull();
assertThat(result.getBranchUuid()).isNull();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDbTester.java
index 169145e715b..0652dfe0cc3 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDbTester.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/newcodeperiod/NewCodePeriodDbTester.java
@@ -19,6 +19,7 @@
*/
package org.sonar.db.newcodeperiod;
+import javax.annotation.Nullable;
import org.sonar.db.DbTester;
public class NewCodePeriodDbTester {
@@ -35,4 +36,31 @@ public class NewCodePeriodDbTester {
return dto;
}
+ public NewCodePeriodDto insert(@Nullable String projectUuid, @Nullable String branchUuid, NewCodePeriodType type, @Nullable String value) {
+ NewCodePeriodDto dto = new NewCodePeriodDto()
+ .setProjectUuid(projectUuid)
+ .setBranchUuid(branchUuid)
+ .setType(type)
+ .setValue(value);
+ insert(dto);
+ return dto;
+ }
+
+ public NewCodePeriodDto insert(@Nullable String projectUuid, NewCodePeriodType type, @Nullable String value) {
+ NewCodePeriodDto dto = new NewCodePeriodDto()
+ .setProjectUuid(projectUuid)
+ .setType(type)
+ .setValue(value);
+ insert(dto);
+ return dto;
+ }
+
+ public NewCodePeriodDto insert(NewCodePeriodType type, @Nullable String value) {
+ NewCodePeriodDto dto = new NewCodePeriodDto()
+ .setType(type)
+ .setValue(value);
+ insert(dto);
+ return dto;
+ }
+
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index c71209e6fb2..2eced5e23ed 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -300,31 +300,6 @@ public class ComponentDbTester {
return branch;
}
- public final void setSpecificAnalysisNewCodePeriod(ComponentDto longOrMainBranchOfProject, SnapshotDto analysis) {
- checkArgument(longOrMainBranchOfProject.isRoot());
-
- BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(dbSession, longOrMainBranchOfProject.uuid())
- .orElseThrow(() -> new IllegalArgumentException("BranchDto not found for component " + longOrMainBranchOfProject));
- checkArgument(branchDto.getBranchType() == LONG, "must be a main or a Long Living branch");
-
- db.getDbClient().newCodePeriodDao().insert(dbSession, new NewCodePeriodDto()
- .setProjectUuid(branchDto.getProjectUuid())
- .setBranchUuid(branchDto.getUuid())
- .setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
- .setValue(analysis.getUuid()));
- db.commit();
- }
-
- public final void unsetBranchNewCodePeriod(ComponentDto longOrMainBranchOfProject) {
- checkArgument(longOrMainBranchOfProject.isRoot());
-
- BranchDto branchDto = db.getDbClient().branchDao().selectByUuid(dbSession, longOrMainBranchOfProject.uuid())
- .orElseThrow(() -> new IllegalArgumentException("BranchDto not found for component " + longOrMainBranchOfProject));
- checkArgument(branchDto.getBranchType() == LONG, "must be a main or a Long Living branch");
- db.getDbClient().newCodePeriodDao().deleteByBranch(dbSession, branchDto.getProjectUuid(), branchDto.getUuid());
- db.commit();
- }
-
private static <T> T firstNonNull(@Nullable T first, T second) {
return (first != null) ? first : second;
}