From: Julien Lancelot Date: Mon, 25 Aug 2014 13:31:00 +0000 (+0200) Subject: SONAR-5417 Fix issue when setting a profile on a provisoned project X-Git-Tag: 4.5-RC1~104 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=93c7ad5736ad3071e114aa87c925e0cb45b5f0e8;p=sonarqube.git SONAR-5417 Fix issue when setting a profile on a provisoned project --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java index 20172488b7c..5610d673b61 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/batch/ProjectReferentialsAction.java @@ -123,6 +123,7 @@ public class ProjectReferentialsAction implements RequestHandler { } else { // Add settings of the provisioned project addSettings(ref, projectOrModuleKey, getPropertiesMap(propertiesDao.selectProjectProperties(projectOrModuleKey, session), hasScanPerm)); + projectKey = projectOrModuleKey; } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java index a2afc2d7a85..508d35a18b7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/batch/ProjectReferentialsActionTest.java @@ -210,6 +210,21 @@ public class ProjectReferentialsActionTest { request.execute().assertJson(getClass(), "return_project_settings.json"); } + @Test + public void return_provisioned_project_profile() throws Exception { + MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.DRY_RUN_EXECUTION); + + // No root project will be found on provisioned project + when(componentDao.getNullableRootProjectByKey(project.key(), session)).thenReturn(null); + + when(qProfileFactory.getByProjectAndLanguage(session, project.key(), "java")).thenReturn( + QualityProfileDto.createFor("abcd").setName("SonarQube way").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200") + ); + + WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", project.key()); + request.execute().assertJson(getClass(), "return_provisioned_project_profile.json"); + } + @Test public void return_sub_module_settings() throws Exception { MockUserSession.set().setLogin("john").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION, GlobalPermissions.DRY_RUN_EXECUTION); @@ -300,7 +315,7 @@ public class ProjectReferentialsActionTest { String projectKey = "org.codehaus.sonar:sonar"; when(qProfileFactory.getByProjectAndLanguage(session, projectKey, "java")).thenReturn( - QualityProfileDto.createFor("abcd").setName("Default").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200") + QualityProfileDto.createFor("abcd").setName("SonarQube way").setLanguage("java").setRulesUpdatedAt("2014-01-14T14:00:00+0200") ); WsTester.TestRequest request = tester.newGetRequest("batch", "project").setParam("key", projectKey); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json new file mode 100644 index 00000000000..282fafa5b33 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_provisioned_project_profile.json @@ -0,0 +1,13 @@ +{ + "timestamp": 0, + "qprofilesByLanguage": { + "java": { + "key": "abcd", + "name": "SonarQube way", + "language": "java", + "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM" + } + }, + "activeRules": [], + "settingsByModule": {} +} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json index a1bb33bb01f..282fafa5b33 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/batch/ProjectReferentialsActionTest/return_quality_profiles.json @@ -3,7 +3,7 @@ "qprofilesByLanguage": { "java": { "key": "abcd", - "name": "Default", + "name": "SonarQube way", "language": "java", "rulesUpdatedAt": "Jan 14, 2014 1:00:00 PM" }