]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7779 fix persistence of View analysis
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 7 Jul 2016 09:32:57 +0000 (11:32 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 7 Jul 2016 15:07:11 +0000 (17:07 +0200)
persistence was using a generated UUID rather than the one from AnalysisMetadataHolder

server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistAnalysisStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ReportPersistAnalysisStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/ViewsPersistAnalysisStepTest.java

index ddfc67f25dc2e3735f8183483a8902084fce1c34..f095b4d328b1cef18e6c15c13d5fda23fbca8ad4 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.computation.step;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
-import org.sonar.core.util.Uuids;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.SnapshotDto;
@@ -88,7 +87,7 @@ public class PersistAnalysisStep implements ComputationStep {
 
     @Override
     public void visitView(Component view, Path<SnapshotDtoHolder> path) {
-      SnapshotDto snapshot = createAnalysis(Uuids.create(), view, false);
+      SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view, false);
       updateSnapshotPeriods(snapshot);
       persist(snapshot, dbSession);
     }
index ca4dd935da1e8481f3aa915939f0b90814004fe4..f525378f92487c9ea2f3cbe670bd603ae8f437ba 100644 (file)
@@ -123,6 +123,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
     assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
 
     SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
+    assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
     assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid());
     assertThat(projectSnapshot.getVersion()).isEqualTo("1.0");
     assertThat(projectSnapshot.getLast()).isFalse();
index 638b8f1aeda15d64565090c396782e708ff75899..e50f5c7a14f97a47cb309ea7e90ba7cb9118a4a2 100644 (file)
@@ -41,7 +41,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE;
-import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newProjectDto;
 import static org.sonar.db.component.ComponentTesting.newSubView;
 import static org.sonar.db.component.ComponentTesting.newView;
@@ -55,13 +54,10 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest {
 
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
-
   @Rule
   public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule();
-
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
-
   @Rule
   public PeriodsHolderRule periodsHolder = new PeriodsHolderRule();
 
@@ -99,9 +95,8 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest {
   @Test
   public void persist_analysis() {
     ComponentDto viewDto = save(newView("UUID_VIEW").setKey("KEY_VIEW"));
-    ComponentDto subViewDto = save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW"));
-    ComponentDto projectDto = save(newProjectDto("proj"));
-    ComponentDto projectViewDto = save(newProjectCopy("UUID_PROJECT_COPY", projectDto, subViewDto).setKey("KEY_PROJECT_COPY"));
+    save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW"));
+    save(newProjectDto("proj"));
     dbTester.getSession().commit();
 
     Component projectView = ViewsComponent.builder(PROJECT_VIEW, "KEY_PROJECT_COPY").setUuid("UUID_PROJECT_COPY").build();
@@ -114,6 +109,7 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest {
     assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
 
     SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid());
+    assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
     assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid());
     assertThat(viewSnapshot.getVersion()).isNull();
     assertThat(viewSnapshot.getLast()).isFalse();