]> source.dussan.org Git - sonarqube.git/commitdiff
Return leak period date when retrieving snapshot from tech project
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 25 Jul 2017 10:05:07 +0000 (12:05 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 31 Jul 2017 09:27:51 +0000 (11:27 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ViewsSnapshotDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java

index 11db59068efe0ce3b1269430b96cbdce5621c412..d0da3799d101dbecc201e614c3149b787f4cfe8d 100644 (file)
  */
 package org.sonar.db.component;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
 public class ViewsSnapshotDto {
   private String uuid;
   private Long createdAt;
+  private Long leakDate;
 
   public String getUuid() {
     return uuid;
@@ -38,4 +42,14 @@ public class ViewsSnapshotDto {
   public void setCreatedAt(Long createdAt) {
     this.createdAt = createdAt;
   }
+
+  @CheckForNull
+  public Long getLeakDate() {
+    return leakDate;
+  }
+
+  public ViewsSnapshotDto setLeakDate(@Nullable Long leakDate) {
+    this.leakDate = leakDate;
+    return this;
+  }
 }
index 3ba07ab067c59a721cfe847b4d4efa9887306c47..8060e105448de0112583b9730a688628b4001019 100644 (file)
@@ -19,7 +19,8 @@
 
   <sql id="viewsSnapshotColumns">
     s.uuid,
-    s.created_at as createdAt
+    s.created_at as createdAt,
+    s.period1_date as leakDate
   </sql>
 
   <select id="selectByUuids" parameterType="List" resultType="Snapshot">
index d8c38d9a25bcdecd424cdd8bf51a43b30755dea2..aad175a6f50050baefdc1913bb31a37bbeaa4c7c 100644 (file)
@@ -133,7 +133,7 @@ public class SnapshotDaoTest {
     SnapshotDto lastSnapshotOfFirstProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(true));
     ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2"));
     SnapshotDto lastSnapshotOfSecondProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(secondProject).setLast(true));
-    db.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()));
+    db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization()));
 
     List<SnapshotDto> result = underTest.selectLastAnalysesByRootComponentUuids(dbSession, newArrayList(firstProject.uuid(), secondProject.uuid()));
 
@@ -188,7 +188,7 @@ public class SnapshotDaoTest {
 
   @Test
   public void select_first_snapshots() throws Exception {
-    ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+    ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization());
     db.getDbClient().componentDao().insert(dbSession, project);
 
     db.getDbClient().snapshotDao().insert(dbSession,
@@ -231,7 +231,26 @@ public class SnapshotDaoTest {
       Arrays.asList(from, otherFrom, otherFrom));
 
     assertThat(result).extracting(SnapshotDto::getUuid)
-    .containsExactlyInAnyOrder(finishedAnalysis.getUuid(), otherFinishedAnalysis.getUuid(), analysisOnSecondProject.getUuid());
+      .containsExactlyInAnyOrder(finishedAnalysis.getUuid(), otherFinishedAnalysis.getUuid(), analysisOnSecondProject.getUuid());
+  }
+
+  @Test
+  public void selectSnapshotBefore() {
+    ComponentDto project = db.components().insertPrivateProject();
+    SnapshotDto analysis1 = newAnalysis(project).setCreatedAt(50L).setPeriodDate(20L);
+    SnapshotDto analysis2 = newAnalysis(project).setCreatedAt(20L).setPeriodDate(10L);
+    SnapshotDto analysis3 = newAnalysis(project).setCreatedAt(10L).setPeriodDate(null);
+    db.components().insertSnapshots(analysis1, analysis2, analysis3);
+
+    assertThat(underTest.selectSnapshotBefore(project.uuid(), 50L, dbSession))
+      .extracting(ViewsSnapshotDto::getUuid, ViewsSnapshotDto::getCreatedAt, ViewsSnapshotDto::getLeakDate)
+      .containsExactlyInAnyOrder(analysis2.getUuid(), analysis2.getCreatedAt(), analysis2.getPeriodDate());
+
+    assertThat(underTest.selectSnapshotBefore(project.uuid(), 20L, dbSession))
+      .extracting(ViewsSnapshotDto::getUuid, ViewsSnapshotDto::getLeakDate)
+      .containsExactlyInAnyOrder(analysis3.getUuid(), null);
+
+    assertThat(underTest.selectSnapshotBefore(project.uuid(), 5L, dbSession)).isNull();
   }
 
   @Test
@@ -343,7 +362,7 @@ public class SnapshotDaoTest {
   }
 
   private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) {
-    SnapshotDto snapshot = newAnalysis(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
+    SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
       .setLast(isLastFlag)
       .setStatus(status)
       .setUuid(uuid);