]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-1700 Some links to the projects end up in new session
authorFabrice Bellingard <bellingard@gmail.com>
Mon, 19 Mar 2012 13:13:00 +0000 (14:13 +0100)
committerFabrice Bellingard <bellingard@gmail.com>
Mon, 19 Mar 2012 13:13:00 +0000 (14:13 +0100)
sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java
sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml [new file with mode: 0644]
sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml [new file with mode: 0644]

index a6f736eea5654a88a71ca3f6491ef1ffcb91c541..0917fa776b2b9d59ac9876fd1fe0e3330b175c26 100644 (file)
@@ -72,6 +72,8 @@ public final class DefaultResourcePersister implements ResourcePersister {
       // assume that the parent project has already been saved
       parentSnapshot = snapshotsByResource.get(project.getParent());
       model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
+    } else {
+      model.setRootId(null);
     }
     model = session.save(model);
     project.setId(model.getId());
index a8b7e4d986b3a3d2493e3cf06d775330455e7b96..c85ca8a895f956181eb8a902540befc3c391de45 100644 (file)
@@ -137,4 +137,15 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
     checkTablesWithExcludedColumns("shouldUpdateExistingResource", new String[]{"build_date"}, "projects", "snapshots");
   }
 
+  // SONAR-1700
+  @Test
+  public void shouldRemoveRootIndexIfResourceIsProject() {
+    setupData("shouldRemoveRootIndexIfResourceIsProject");
+
+    ResourcePersister persister = new DefaultResourcePersister(getSession());
+    persister.saveProject(singleProject, null);
+
+    checkTablesWithExcludedColumns("shouldRemoveRootIndexIfResourceIsProject", new String[]{"build_date"}, "projects", "snapshots");
+  }
+
 }
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject-result.xml
new file mode 100644 (file)
index 0000000..147b3c3
--- /dev/null
@@ -0,0 +1,17 @@
+<dataset>
+
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="[null]"
+            name="Foo" long_name="Foo" description="some description"
+            enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" profile_id="[null]"/>
+
+  <!-- old snapshot -->
+  <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" build_date="2010-12-23 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+  <!-- new snapshot -->
+  <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3002" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-25 00:00:00.00" build_date="2010-12-25 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/DefaultResourcePersisterTest/shouldRemoveRootIndexIfResourceIsProject.xml
new file mode 100644 (file)
index 0000000..56b2ab2
--- /dev/null
@@ -0,0 +1,12 @@
+<dataset>
+
+  <!-- This project has a root_id which should be set to NULL (SONAR-1700) -->
+  <projects id="1001" scope="PRJ" qualifier="TRK" kee="foo" root_id="12345"
+            name="name" long_name="long name" description="description"
+            enabled="true" language="java" copy_resource_id="[null]" person_id="[null]" profile_id="[null]"/>
+
+  <snapshots purge_status="[null]" period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="3001" project_id="1001" parent_snapshot_id="[null]" root_project_id="1001" root_snapshot_id="[null]"
+             scope="PRJ" qualifier="TRK" created_at="2010-12-23 00:00:00.00" build_date="2010-12-23 00:00:00.00" version="[null]" path=""
+             status="U" islast="false" depth="0" />
+
+</dataset>
\ No newline at end of file