]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5417 Reorganize unit tests
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 30 Jul 2014 11:04:56 +0000 (13:04 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 30 Jul 2014 11:04:56 +0000 (13:04 +0200)
server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_module.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_without_settings_from_parent.json [deleted file]

index 3722d871d27c99728a7cd48d5fc5e43e2046af60..d5a6c989dd6b27ed244a3873b693f01db5fbc35b 100644 (file)
@@ -191,26 +191,25 @@ public class ProjectReferentialsActionTest {
   }
 
   @Test
-  public void return_sub_module_settings_inherited_from_project() throws Exception {
+  public void return_sub_module_settings() throws Exception {
     MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.DRY_RUN_EXECUTION);
 
     when(componentDao.getRootProjectByKey(subModule.key(), session)).thenReturn(project);
     when(componentDao.getParentModuleByKey(module.key(), session)).thenReturn(project);
     when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
 
-    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
+    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
       new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
       new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
       new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
-    // No settings on module or sub module -> All setting should come from the project
+    ));
 
     WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings_inherited_from_project.json");
+    request.execute().assertJson(getClass(), "return_sub_module_settings.json");
   }
 
   @Test
-  public void return_sub_module_settings_inherited_from_module() throws Exception {
+  public void return_sub_module_settings_including_settings_from_parent_modules() throws Exception {
     MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.DRY_RUN_EXECUTION);
 
     when(componentDao.getRootProjectByKey(subModule.key(), session)).thenReturn(project);
@@ -218,22 +217,23 @@ public class ProjectReferentialsActionTest {
     when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
 
     when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
-      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR")
     ));
 
     when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER")
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
     ));
 
-    // No settings on sub module -> All setting should come from the project and the module
+    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
+      new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
+    ));
 
     WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings_inherited_from_module.json");
+    request.execute().assertJson(getClass(), "return_sub_module_settings_including_settings_from_parent_modules.json");
   }
 
   @Test
-  public void return_sub_module_settings() throws Exception {
+  public void return_sub_module_settings_only_inherited_from_project() throws Exception {
     MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.DRY_RUN_EXECUTION);
 
     when(componentDao.getRootProjectByKey(subModule.key(), session)).thenReturn(project);
@@ -241,37 +241,37 @@ public class ProjectReferentialsActionTest {
     when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
 
     when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR")
-      ));
-
-    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john")
-      ));
-
-    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
+      new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
       new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
       ));
+    // No settings on module or sub module -> All setting should come from the project
 
     WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings.json");
+    request.execute().assertJson(getClass(), "return_sub_module_settings_inherited_from_project.json");
   }
 
   @Test
-  public void return_sub_module_settings_without_settings_from_parent() throws Exception {
+  public void return_sub_module_settings_inherited_from_project_and_module() throws Exception {
     MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.DRY_RUN_EXECUTION);
 
     when(componentDao.getRootProjectByKey(subModule.key(), session)).thenReturn(project);
     when(componentDao.getParentModuleByKey(module.key(), session)).thenReturn(project);
     when(componentDao.getParentModuleByKey(subModule.key(), session)).thenReturn(module);
 
-    when(propertiesDao.selectProjectProperties(subModule.key(), session)).thenReturn(newArrayList(
-      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR"),
+    when(propertiesDao.selectProjectProperties(project.key(), session)).thenReturn(newArrayList(
       new PropertyDto().setKey("sonar.jira.login.secured").setValue("john"),
       new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java")
-      ));
+    ));
+
+    when(propertiesDao.selectProjectProperties(module.key(), session)).thenReturn(newArrayList(
+      new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER")
+    ));
+
+    // No settings on sub module -> All setting should come from the project and the module
 
     WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", subModule.key());
-    request.execute().assertJson(getClass(), "return_sub_module_settings_without_settings_from_parent.json");
+    request.execute().assertJson(getClass(), "return_sub_module_settings_inherited_from_project_and_module.json");
   }
 
   @Test
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_including_settings_from_parent_modules.json
new file mode 100644 (file)
index 0000000..f2a89a9
--- /dev/null
@@ -0,0 +1,19 @@
+{
+  "timestamp": 0,
+  "qprofilesByLanguage": {
+    "java": {
+      "key": "abcd",
+      "name": "Default",
+      "language": "java",
+      "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM"
+    }
+  },
+  "activeRules": [],
+  "settingsByModule": {
+    "org.codehaus.sonar:sonar-server-dao": {
+      "sonar.jira.project.key": "SONAR",
+      "sonar.jira.login.secured": "john",
+      "sonar.coverage.exclusions": "**/*.java"
+    }
+  }
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_module.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_module.json
deleted file mode 100644 (file)
index c99fd8e..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR-SERVER",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  }
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_inherited_from_project_and_module.json
new file mode 100644 (file)
index 0000000..c99fd8e
--- /dev/null
@@ -0,0 +1,19 @@
+{
+  "timestamp": 0,
+  "qprofilesByLanguage": {
+    "java": {
+      "key": "abcd",
+      "name": "Default",
+      "language": "java",
+      "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM"
+    }
+  },
+  "activeRules": [],
+  "settingsByModule": {
+    "org.codehaus.sonar:sonar-server-dao": {
+      "sonar.jira.project.key": "SONAR-SERVER",
+      "sonar.jira.login.secured": "john",
+      "sonar.coverage.exclusions": "**/*.java"
+    }
+  }
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_without_settings_from_parent.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_sub_module_settings_without_settings_from_parent.json
deleted file mode 100644 (file)
index f2a89a9..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-{
-  "timestamp": 0,
-  "qprofilesByLanguage": {
-    "java": {
-      "key": "abcd",
-      "name": "Default",
-      "language": "java",
-      "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM"
-    }
-  },
-  "activeRules": [],
-  "settingsByModule": {
-    "org.codehaus.sonar:sonar-server-dao": {
-      "sonar.jira.project.key": "SONAR",
-      "sonar.jira.login.secured": "john",
-      "sonar.coverage.exclusions": "**/*.java"
-    }
-  }
-}