]> source.dussan.org Git - sonarqube.git/commitdiff
Improve ComponentTesting and SnapshotTesting
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 31 Dec 2014 08:52:57 +0000 (09:52 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 31 Dec 2014 08:52:57 +0000 (09:52 +0100)
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsLoaderMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentTesting.java
server/sonar-server/src/test/java/org/sonar/server/component/SnapshotTesting.java
server/sonar-server/src/test/java/org/sonar/server/component/db/SnapshotDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueBulkChangeServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueCommentServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/IssueServiceMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/issue/ws/SearchActionMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/BackendCleanupMediumTest.java

index 3eae77a6be78c1c297d3cf36e82b4f210c0c529c..42a8b6bec2b5976c3e0ee3caa353e21e10b7125e 100644 (file)
@@ -150,7 +150,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, projectSnapshot));
 
     // Module properties
     tester.get(DbClient.class).propertiesDao().setProperty(
@@ -190,7 +190,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module, projectSnapshot));
 
     // No property on module -> should have the same as project
 
@@ -225,7 +225,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
     tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
 
     // Module properties
@@ -236,7 +236,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
     tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
 
     // Sub module properties
     tester.get(DbClient.class).propertiesDao().setProperty(
@@ -277,7 +277,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module1 = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module1);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module1, project, projectSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module1, projectSnapshot));
 
     // Module 1 properties
     tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module1.getId()), dbSession);
@@ -286,7 +286,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module2 = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module2);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module2, project, projectSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(module2, projectSnapshot));
 
     // Module 2 property
     tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-APPLICATION").setResourceId(module2.getId()), dbSession);
@@ -344,13 +344,13 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
     tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
     // No module properties
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
     tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
 
     // Sub module properties
     tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId()), dbSession);
@@ -384,7 +384,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
     tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
 
     // Module property
@@ -392,7 +392,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
     tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
 
     // Sub module properties
     tester.get(DbClient.class).propertiesDao().setProperty(new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId()), dbSession);
@@ -426,13 +426,13 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
     tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
     // No module property
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
     tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
     // No sub module property
 
     dbSession.commit();
@@ -463,7 +463,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto module = ComponentTesting.newModuleDto(project);
     tester.get(DbClient.class).componentDao().insert(dbSession, module);
-    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, project, projectSnapshot);
+    SnapshotDto moduleSnapshot = SnapshotTesting.createForComponent(module, projectSnapshot);
     tester.get(DbClient.class).snapshotDao().insert(dbSession, moduleSnapshot);
 
     // Module property
@@ -471,7 +471,7 @@ public class ProjectReferentialsLoaderMediumTest {
 
     ComponentDto subModule = ComponentTesting.newModuleDto(module);
     tester.get(DbClient.class).componentDao().insert(dbSession, subModule);
-    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, module, moduleSnapshot));
+    tester.get(DbClient.class).snapshotDao().insert(dbSession, SnapshotTesting.createForComponent(subModule, moduleSnapshot));
     // No sub module property
 
     dbSession.commit();
index 3376773d2a4e887b0c045ce25e937e969cbede27..d1a6db4a09ad74220f7137b1ae31f7008f3c5ba1 100644 (file)
@@ -28,20 +28,7 @@ import org.sonar.core.component.ComponentDto;
 public class ComponentTesting {
 
   public static ComponentDto newFileDto(ComponentDto subProjectOrProject) {
-    return new ComponentDto()
-      .setUuid(Uuids.create())
-      .setProjectUuid(subProjectOrProject.projectUuid())
-      .setModuleUuid(subProjectOrProject.uuid())
-      .setModuleUuidPath(subProjectOrProject.moduleUuidPath() == null ? subProjectOrProject.uuid() : subProjectOrProject.moduleUuidPath() + "." + subProjectOrProject.uuid())
-      .setKey("file")
-      .setName("File")
-      .setLongName("File")
-      .setParentProjectId(subProjectOrProject.getId())
-      .setScope(Scopes.FILE)
-      .setQualifier(Qualifiers.FILE)
-      .setPath("src/main/xoo/org/sonar/samples/File.xoo")
-      .setLanguage("xoo")
-      .setEnabled(true);
+    return newFileDto(subProjectOrProject, Uuids.create());
   }
 
   public static ComponentDto newFileDto(ComponentDto module, String fileUuid) {
@@ -80,19 +67,7 @@ public class ComponentTesting {
   }
 
   public static ComponentDto newProjectDto() {
-    String uuid = Uuids.create();
-    return new ComponentDto()
-      .setUuid(uuid)
-      .setProjectUuid(uuid)
-      .setKey("project")
-      .setName("Project")
-      .setLongName("Project")
-      .setParentProjectId(null)
-      .setScope(Scopes.PROJECT)
-      .setQualifier(Qualifiers.PROJECT)
-      .setPath(null)
-      .setLanguage(null)
-      .setEnabled(true);
+    return newProjectDto(Uuids.create());
   }
 
   public static ComponentDto newProjectDto(String uuid) {
index 1b174c9a11f1d02725613803210fb9240cfe3aba..57db17ac178efa76183263144ceb86240e38a8cb 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.server.component;
 
-import org.sonar.api.utils.DateUtils;
 import org.sonar.core.component.ComponentDto;
 import org.sonar.core.component.SnapshotDto;
 
@@ -31,7 +30,7 @@ public class SnapshotTesting {
   /**
    * Can be used for modules and files
    */
-  public static SnapshotDto createForComponent(ComponentDto component, ComponentDto parentProject, SnapshotDto parentSnapshot) {
+  public static SnapshotDto createForComponent(ComponentDto component, SnapshotDto parentSnapshot) {
     Long parentRootId = parentSnapshot.getRootId();
     return new SnapshotDto()
       .setResourceId(component.getId())
@@ -58,35 +57,4 @@ public class SnapshotTesting {
       .setBuildDate(new Date());
   }
 
-  public static SnapshotDto defaultSnapshot() {
-    return new SnapshotDto()
-      .setResourceId(3L)
-      .setRootProjectId(1L)
-      .setParentId(2L)
-      .setRootId(1L)
-      .setStatus("P")
-      .setLast(true)
-      .setPurgeStatus(1)
-      .setDepth(1)
-      .setScope("DIR")
-      .setQualifier("PAC")
-      .setVersion("2.1-SNAPSHOT")
-      .setPath("1.2.")
-      .setPeriodMode(1, "days1")
-      .setPeriodMode(2, "days2")
-      .setPeriodMode(3, "days3")
-      .setPeriodMode(4, "days4")
-      .setPeriodMode(5, "days5")
-      .setPeriodParam(1, "30")
-      .setPeriodParam(2, "31")
-      .setPeriodParam(3, "32")
-      .setPeriodParam(4, "33")
-      .setPeriodParam(5, "34")
-      .setPeriodDate(1, DateUtils.parseDate("2011-09-24"))
-      .setPeriodDate(2, DateUtils.parseDate("2011-09-25"))
-      .setPeriodDate(3, DateUtils.parseDate("2011-09-26"))
-      .setPeriodDate(4, DateUtils.parseDate("2011-09-27"))
-      .setPeriodDate(5, DateUtils.parseDate("2011-09-28"))
-      .setBuildDate(DateUtils.parseDate("2011-09-29"));
-  }
 }
index 3308afc1515b7126b91e9859910b47aee423f3c6..742cc8d8da6ac8fda754f8742447ac421d9d39f8 100644 (file)
@@ -28,7 +28,6 @@ import org.sonar.api.utils.System2;
 import org.sonar.core.component.SnapshotDto;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.DbSession;
-import org.sonar.server.component.SnapshotTesting;
 
 import java.util.Date;
 import java.util.List;
@@ -36,7 +35,6 @@ import java.util.List;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.sonar.server.component.SnapshotTesting.defaultSnapshot;
 
 public class SnapshotDaoTest extends AbstractDaoTestCase {
 
@@ -236,7 +234,7 @@ public class SnapshotDaoTest extends AbstractDaoTestCase {
 
   @Test
   public void is_last_snapshot_when_no_previous_snapshot() {
-    SnapshotDto snapshot = SnapshotTesting.defaultSnapshot();
+    SnapshotDto snapshot = defaultSnapshot();
 
     boolean isLast = sut.isLast(snapshot, null);
 
@@ -248,8 +246,8 @@ public class SnapshotDaoTest extends AbstractDaoTestCase {
     Date today = new Date();
     Date yesterday = DateUtils.addDays(today, -1);
 
-    SnapshotDto snapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(today);
-    SnapshotDto previousLastSnapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(yesterday);
+    SnapshotDto snapshot = defaultSnapshot().setCreatedAt(today);
+    SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(yesterday);
 
     boolean isLast = sut.isLast(snapshot, previousLastSnapshot);
 
@@ -261,11 +259,43 @@ public class SnapshotDaoTest extends AbstractDaoTestCase {
     Date today = new Date();
     Date yesterday = DateUtils.addDays(today, -1);
 
-    SnapshotDto snapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(yesterday);
-    SnapshotDto previousLastSnapshot = SnapshotTesting.defaultSnapshot().setCreatedAt(today);
+    SnapshotDto snapshot = defaultSnapshot().setCreatedAt(yesterday);
+    SnapshotDto previousLastSnapshot = defaultSnapshot().setCreatedAt(today);
 
     boolean isLast = sut.isLast(snapshot, previousLastSnapshot);
 
     assertThat(isLast).isFalse();
   }
+
+  private static SnapshotDto defaultSnapshot() {
+    return new SnapshotDto()
+      .setResourceId(3L)
+      .setRootProjectId(1L)
+      .setParentId(2L)
+      .setRootId(1L)
+      .setStatus("P")
+      .setLast(true)
+      .setPurgeStatus(1)
+      .setDepth(1)
+      .setScope("DIR")
+      .setQualifier("PAC")
+      .setVersion("2.1-SNAPSHOT")
+      .setPath("1.2.")
+      .setPeriodMode(1, "days1")
+      .setPeriodMode(2, "days2")
+      .setPeriodMode(3, "days3")
+      .setPeriodMode(4, "days4")
+      .setPeriodMode(5, "days5")
+      .setPeriodParam(1, "30")
+      .setPeriodParam(2, "31")
+      .setPeriodParam(3, "32")
+      .setPeriodParam(4, "33")
+      .setPeriodParam(5, "34")
+      .setPeriodDate(1, DateUtils.parseDate("2011-09-24"))
+      .setPeriodDate(2, DateUtils.parseDate("2011-09-25"))
+      .setPeriodDate(3, DateUtils.parseDate("2011-09-26"))
+      .setPeriodDate(4, DateUtils.parseDate("2011-09-27"))
+      .setPeriodDate(5, DateUtils.parseDate("2011-09-28"))
+      .setBuildDate(DateUtils.parseDate("2011-09-29"));
+  }
 }
index b741d9638dc2c552fbca4e0383432f27ee160b97..ccc3253e9473fdd94e0cc1767d12aa2f5651f895 100644 (file)
@@ -90,7 +90,7 @@ public class IssueBulkChangeServiceMediumTest {
 
     file = ComponentTesting.newFileDto(project).setKey("MyComponent");
     tester.get(ComponentDao.class).insert(session, file);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
 
     // project can be seen by anyone
     session.commit();
index 1d017d3ea1f51bd51e5b7ad7826caf877dc47e5f..8736d21262ca2436a7dba7d854c088315768c8f2 100644 (file)
@@ -87,7 +87,7 @@ public class IssueCommentServiceMediumTest {
 
     file = ComponentTesting.newFileDto(project);
     tester.get(ComponentDao.class).insert(session, file);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
 
     // project can be seen by anyone
     session.commit();
index 02d11147bff6153142b054cd17d65ccea0dcacae..9118e66429b0d9512db8873151142e2dc398b845 100644 (file)
@@ -100,7 +100,7 @@ public class IssueServiceMediumTest {
 
     file = ComponentTesting.newFileDto(project);
     tester.get(ComponentDao.class).insert(session, file);
-    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+    tester.get(SnapshotDao.class).insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
 
 
     // workaround for the test to have sufficient privileges
index 93a9d675744c5b401066d844daa4bbe642033e10..95720c2485a9b58a2f2047cc7a59663eaef3fc11 100644 (file)
@@ -429,11 +429,11 @@ public class SearchActionMediumTest {
       .setScope("PRJ")
       .setParentProjectId(project.getId());
     db.componentDao().insert(session, module);
-    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, project, projectSnapshot));
+    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(module, projectSnapshot));
 
     ComponentDto file = ComponentTesting.newFileDto(module).setKey("FileLinkedToModule");
     db.componentDao().insert(session, file);
-    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
 
     IssueDto issue = IssueTesting.newDto(rule, file, project);
     db.issueDao().insert(session, issue);
index b1d3a66077ddd02e07ae063957a7ae0d54f84d25..d65d6936d41ee5c31aa742748c2b4ca9fc8588ec 100644 (file)
@@ -81,7 +81,7 @@ public class BackendCleanupMediumTest {
 
     file = ComponentTesting.newFileDto(project).setKey("MyComponent");
     tester.get(ComponentDao.class).insert(session, file);
-    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, project, projectSnapshot));
+    db.snapshotDao().insert(session, SnapshotTesting.createForComponent(file, projectSnapshot));
     session.commit();
     // project can be seen by anyone
     MockUserSession.set().setLogin("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);