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);
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;
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;
}
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());
}
}
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;
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 {
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();