]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7300 Return global values when component does not exist 1525/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Jan 2017 12:51:02 +0000 (13:51 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Thu, 12 Jan 2017 13:53:56 +0000 (14:53 +0100)
it/it-tests/src/test/java/it/settings/DeprecatedPropertiesWsTest.java
server/sonar-server/src/main/java/org/sonar/server/property/ws/IndexAction.java
server/sonar-server/src/test/java/org/sonar/server/property/ws/IndexActionTest.java

index a6d02dbf2326d4f064c4df95c330c8bf9c4e599a..cff8e72f41cf90ad40d1b24f4f475225303a80f7 100644 (file)
@@ -212,6 +212,13 @@ public class DeprecatedPropertiesWsTest {
     assertThat(getProperty("sonar.coverage.exclusions", PROJECT_KEY).getValue()).isEqualTo("file");
   }
 
+  @Test
+  public void get_global_value_when_component_is_unknown() throws Exception {
+    setProperty("some-property", "value", null);
+
+    assertThat(getProperty("some-property", PROJECT_KEY).getValue()).isEqualTo("value");
+  }
+
   @Test
   public void get_all_component_settings() throws Exception {
     List<Properties.Property> properties = getProperties(PROJECT_KEY);
index d4626462d925e22957b06a98cd07b6058c46bb41..d8db9d0fb602cac207759d77f3e62b0a1ee688ba 100644 (file)
@@ -44,7 +44,6 @@ import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.property.PropertyDto;
-import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.user.UserSession;
 import org.sonar.server.ws.WsAction;
 
@@ -67,13 +66,11 @@ public class IndexAction implements WsAction {
   public static final String PARAM_COMPONENT = "resource";
 
   private final DbClient dbClient;
-  private final ComponentFinder componentFinder;
   private final UserSession userSession;
   private final PropertyDefinitions propertyDefinitions;
 
-  public IndexAction(DbClient dbClient, ComponentFinder componentFinder, UserSession userSession, PropertyDefinitions propertyDefinitions) {
+  public IndexAction(DbClient dbClient, UserSession userSession, PropertyDefinitions propertyDefinitions) {
     this.dbClient = dbClient;
-    this.componentFinder = componentFinder;
     this.userSession = userSession;
     this.propertyDefinitions = propertyDefinitions;
   }
@@ -122,15 +119,15 @@ public class IndexAction implements WsAction {
     if (component == null) {
       return Optional.empty();
     }
-    return Optional.of(loadComponent(dbSession, component));
+    return loadComponent(dbSession, component);
   }
 
-  private ComponentDto loadComponent(DbSession dbSession, String component) {
+  private Optional<ComponentDto> loadComponent(DbSession dbSession, String component) {
     try {
       Long componentId = Long.parseLong(component);
-      return componentFinder.getById(dbSession, componentId);
+      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull());
     } catch (NumberFormatException e) {
-      return componentFinder.getByKey(dbSession, component);
+      return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull());
     }
   }
 
index e5a6530b255583f9065fb591421741a4ffe6d655..7efbf222358ab8849c6fd11011849aca3fae8296 100644 (file)
@@ -38,7 +38,6 @@ import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.property.PropertyDbTester;
-import org.sonar.server.component.ComponentFinder;
 import org.sonar.server.tester.UserSessionRule;
 import org.sonar.server.ws.TestRequest;
 import org.sonar.server.ws.WsActionTester;
@@ -77,7 +76,7 @@ public class IndexActionTest {
 
   ComponentDto project;
 
-  WsActionTester ws = new WsActionTester(new IndexAction(dbClient, new ComponentFinder(dbClient), userSession, definitions));
+  WsActionTester ws = new WsActionTester(new IndexAction(dbClient, userSession, definitions));
 
   @Before
   public void setUp() throws Exception {
@@ -165,6 +164,16 @@ public class IndexActionTest {
     executeAndVerify(project.key(), null, "return_project_values.json");
   }
 
+  @Test
+  public void return_global_values_when_project_does_not_exist() throws Exception {
+    setAuthenticatedUser();
+    definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").build());
+    propertyDb.insertProperties(
+      newGlobalPropertyDto().setKey("property").setValue("one"));
+
+    executeAndVerify("unknown", null, "return_global_values.json");
+  }
+
   @Test
   public void return_values_even_if_no_property_definition() throws Exception {
     setAuthenticatedUser();