]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6589 Remove Settings from ComputationContext
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 27 May 2015 07:47:30 +0000 (09:47 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 27 May 2015 09:49:39 +0000 (11:49 +0200)
13 files changed:
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContainer.java
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
server/sonar-server/src/main/java/org/sonar/server/computation/ComputationService.java
server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectSettingsRepository.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/issue/IssueComputation.java
server/sonar-server/src/main/java/org/sonar/server/computation/step/PurgeDatastoresStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/computation/issue/IssueComputationTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/step/PurgeDatastoresStepTest.java
server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsFactoryTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsRespositoryFactoryTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsRespositoryTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsTest.java [deleted file]

index a402a7744b0864fa7ae6b609dd4a65581ad59e68..a669ba7778d2302f015ac31a0c370c2c2d302c6a 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.computation;
 import org.sonar.core.issue.db.UpdateConflictResolver;
 import org.sonar.core.platform.ComponentContainer;
 import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.ProjectSettingsRepository;
 import org.sonar.server.computation.issue.IssueCache;
 import org.sonar.server.computation.issue.IssueComputation;
 import org.sonar.server.computation.issue.RuleCache;
@@ -48,6 +49,7 @@ public class ComputationContainer {
     return Arrays.asList(
       // context-scope repositories
       PlatformLanguageRepository.class,
+      ProjectSettingsRepository.class,
 
       ComputationService.class,
       ComputationSteps.class,
index 34021ce47e3d046f46c39cc5533817a1efad283b..2e8ac5d603ddf281ea26e887113bc52082835e24 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.server.db.DbClient;
 
 public class ComputationContext implements org.sonar.server.computation.context.ComputationContext {
   private final BatchReportReader reportReader;
-  private final Settings projectSettings;
   private final DbClient dbClient;
   // cache of metadata as it's frequently accessed
   private final BatchReport.Metadata reportMetadata;
@@ -39,7 +38,6 @@ public class ComputationContext implements org.sonar.server.computation.context.
   public ComputationContext(BatchReportReader reportReader, String projectKey, Settings projectSettings, DbClient dbClient,
     ComponentTreeBuilder componentTreeBuilder, LanguageRepository languageRepository) {
     this.reportReader = reportReader;
-    this.projectSettings = projectSettings;
     this.dbClient = dbClient;
     this.reportMetadata = reportReader.readMetadata();
     this.component = componentTreeBuilder.build(this);
@@ -54,10 +52,6 @@ public class ComputationContext implements org.sonar.server.computation.context.
     return reportReader;
   }
 
-  public Settings getProjectSettings() {
-    return projectSettings;
-  }
-
   @Override
   public Component getRoot() {
     return component;
index c18ede0d0dba56015c8b58a2e21c3b2be8409c78..6b9796f10de08b088c82a91f7085781cea6aa90d 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.server.computation;
 
 import com.google.common.base.Throwables;
 import org.apache.commons.io.FileUtils;
-import org.sonar.api.config.Settings;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.TempFolder;
@@ -87,8 +86,7 @@ public class ComputationService {
     try {
       File reportDir = extractReportInDir(item);
       BatchReportReader reader = new BatchReportReader(reportDir);
-      Settings projectSettings = projectSettingsFactory.newProjectSettings(projectKey);
-      ComputationContext context = new ComputationContext(reader, null, projectSettings, dbClient, ComponentTreeBuilders.from(reader), languageRepository);
+      ComputationContext context = new ComputationContext(reader, null, null, dbClient, ComponentTreeBuilders.from(reader), languageRepository);
       for (ComputationStep step : steps.orderedSteps()) {
         Profiler stepProfiler = Profiler.createIfDebug(LOG).startDebug(step.getDescription());
         step.execute(context);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectSettingsRepository.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ProjectSettingsRepository.java
new file mode 100644 (file)
index 0000000..467049c
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.computation.component;
+
+import org.sonar.api.config.Settings;
+import org.sonar.server.properties.ProjectSettingsFactory;
+
+/**
+ * Lazy loading of project settings.
+ *
+ * Should be refactored to be able to load settings from any components.
+ */
+public class ProjectSettingsRepository {
+
+  private final ProjectSettingsFactory projectSettingsFactory;
+
+  private Settings projectSettings;
+
+  public ProjectSettingsRepository(ProjectSettingsFactory projectSettingsFactory) {
+    this.projectSettingsFactory = projectSettingsFactory;
+  }
+
+  public Settings getProjectSettings(String projectKey){
+    if (projectSettings == null) {
+      projectSettings = projectSettingsFactory.newProjectSettings(projectKey);
+    }
+    return projectSettings;
+  }
+
+}
index 8efbcf20648028e663bfe076b771edbfa8592777..17b8cfd64684ce59063c06094dcc829eb67938bf 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.api.utils.log.Loggers;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ProjectSettingsRepository;
 import org.sonar.server.user.index.UserDoc;
 import org.sonar.server.user.index.UserIndex;
 import org.sonar.server.util.cache.DiskCache;
@@ -49,22 +50,24 @@ public class IssueComputation {
   private final SourceLinesCache linesCache;
   private final DiskCache<DefaultIssue>.DiskAppender diskIssuesAppender;
   private final UserIndex userIndex;
+  private final ProjectSettingsRepository projectSettingsRepository;
   private boolean hasAssigneeBeenComputed = false;
   private String defaultAssignee = null;
 
   public IssueComputation(RuleCache ruleCache, SourceLinesCache linesCache, ScmAccountCache scmAccountCache,
-    IssueCache issueCache, UserIndex userIndex) {
+    IssueCache issueCache, UserIndex userIndex, ProjectSettingsRepository projectSettingsRepository) {
     this.ruleCache = ruleCache;
     this.linesCache = linesCache;
     this.scmAccountCache = scmAccountCache;
     this.userIndex = userIndex;
+    this.projectSettingsRepository = projectSettingsRepository;
     this.diskIssuesAppender = issueCache.newAppender();
   }
 
   public void processComponentIssues(ComputationContext context, Iterable<BatchReport.Issue> issues, String componentUuid, @Nullable Integer componentReportRef,
                                      String projectKey, String projectUuid) {
     linesCache.init(componentUuid, componentReportRef, context.getReportReader());
-    computeDefaultAssignee(context.getProjectSettings().getString(CoreProperties.DEFAULT_ISSUE_ASSIGNEE));
+    computeDefaultAssignee(projectSettingsRepository.getProjectSettings(projectKey).getString(CoreProperties.DEFAULT_ISSUE_ASSIGNEE));
     for (BatchReport.Issue reportIssue : issues) {
       DefaultIssue issue = toDefaultIssue(context, componentUuid, reportIssue, projectKey, projectUuid);
       if (issue.isNew()) {
index 0e0fa940e06eacaab40a7a44e13e7df4d57c9aab..14f8b6865da0186a1e8ca9fcbfbaf053ed14fd5a 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.purge.IdUuidPair;
 import org.sonar.server.computation.ComputationContext;
 import org.sonar.server.computation.component.DbComponentsRefCache;
+import org.sonar.server.computation.component.ProjectSettingsRepository;
 import org.sonar.server.db.DbClient;
 
 public class PurgeDatastoresStep implements ComputationStep {
@@ -33,11 +34,13 @@ public class PurgeDatastoresStep implements ComputationStep {
   private final ProjectCleaner projectCleaner;
   private final DbClient dbClient;
   private final DbComponentsRefCache dbComponentsRefCache;
+  private final ProjectSettingsRepository projectSettingsRepository;
 
-  public PurgeDatastoresStep(DbClient dbClient, ProjectCleaner projectCleaner, DbComponentsRefCache dbComponentsRefCache) {
+  public PurgeDatastoresStep(DbClient dbClient, ProjectCleaner projectCleaner, DbComponentsRefCache dbComponentsRefCache, ProjectSettingsRepository projectSettingsRepository) {
     this.projectCleaner = projectCleaner;
     this.dbClient = dbClient;
     this.dbComponentsRefCache = dbComponentsRefCache;
+    this.projectSettingsRepository = projectSettingsRepository;
   }
 
   @Override
@@ -45,7 +48,7 @@ public class PurgeDatastoresStep implements ComputationStep {
     DbSession session = dbClient.openSession(true);
     try {
       DbComponentsRefCache.DbComponent project = dbComponentsRefCache.getByRef(context.getReportMetadata().getRootComponentRef());
-      projectCleaner.purge(session, new IdUuidPair(project.getId(), project.getUuid()), context.getProjectSettings());
+      projectCleaner.purge(session, new IdUuidPair(project.getId(), project.getUuid()), projectSettingsRepository.getProjectSettings(project.getKey()));
       session.commit();
     } finally {
       MyBatis.closeQuietly(session);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/ProjectSettingsRepositoryTest.java
new file mode 100644 (file)
index 0000000..749ff73
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.computation.component;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.sonar.api.config.Settings;
+import org.sonar.core.component.ComponentDto;
+import org.sonar.core.persistence.DbSession;
+import org.sonar.core.persistence.DbTester;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+import org.sonar.server.component.ComponentTesting;
+import org.sonar.server.component.db.ComponentDao;
+import org.sonar.server.db.DbClient;
+import org.sonar.server.properties.ProjectSettingsFactory;
+import org.sonar.test.DbTests;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Category(DbTests.class)
+public class ProjectSettingsRepositoryTest {
+
+  private static final String PROJECT_KEY = "PROJECT_KEY";
+
+  @ClassRule
+  public static final DbTester dbTester = new DbTester();
+
+  DbClient dbClient;
+
+  DbSession session;
+
+  Settings globalSettings;
+
+  ProjectSettingsRepository sut;
+
+  @Before
+  public void createDao() {
+    dbTester.truncateTables();
+    globalSettings = new Settings();
+    PropertiesDao propertiesDao = new PropertiesDao(dbTester.myBatis());
+    dbClient = new DbClient(dbTester.database(), dbTester.myBatis(), propertiesDao, new ComponentDao());
+    session = dbClient.openSession(false);
+    sut = new ProjectSettingsRepository(new ProjectSettingsFactory(globalSettings, propertiesDao));
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    session.close();
+  }
+
+  @Test
+  public void get_project_settings_from_global_settings() throws Exception {
+    globalSettings.setProperty("key", "value");
+
+    Settings settings = sut.getProjectSettings(PROJECT_KEY);
+
+    assertThat(settings.getString("key")).isEqualTo("value");
+  }
+
+  @Test
+  public void get_project_settings_from_db() throws Exception {
+    ComponentDto project = ComponentTesting.newProjectDto().setKey(PROJECT_KEY);
+    dbClient.componentDao().insert(session, project);
+    dbClient.propertiesDao().setProperty(new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value"), session);
+    session.commit();
+
+    Settings settings = sut.getProjectSettings(PROJECT_KEY);
+
+    assertThat(settings.getString("key")).isEqualTo("value");
+  }
+
+  @Test
+  public void call_twice_get_project_settings() throws Exception {
+    globalSettings.setProperty("key", "value");
+
+    Settings settings = sut.getProjectSettings(PROJECT_KEY);
+    assertThat(settings.getString("key")).isEqualTo("value");
+
+    settings = sut.getProjectSettings(PROJECT_KEY);
+    assertThat(settings.getString("key")).isEqualTo("value");
+  }
+}
index 656f8cfcd9af2cabbe35a6c8356a9fa562bda404..f4e0ff6145a8d0992fa170a9b9be5abe600c1db2 100644 (file)
@@ -28,6 +28,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.Mockito;
 import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
 import org.sonar.api.issue.Issue;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.rule.RuleKey;
@@ -36,6 +37,7 @@ import org.sonar.api.utils.log.LogTester;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.core.rule.RuleDto;
 import org.sonar.server.computation.ComputationContext;
+import org.sonar.server.computation.component.ProjectSettingsRepository;
 import org.sonar.server.user.index.UserDoc;
 import org.sonar.server.user.index.UserIndex;
 
@@ -49,7 +51,8 @@ import static org.mockito.Mockito.when;
 
 public class IssueComputationTest {
 
-  public static final RuleKey RULE_KEY = RuleKey.of("squid", "R1");
+  private static final RuleKey RULE_KEY = RuleKey.of("squid", "R1");
+  private static final String PROJECT_KEY = "PROJECT_KEY";
 
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
@@ -69,6 +72,8 @@ public class IssueComputationTest {
     .setRuleRepository(RULE_KEY.repository())
     .setRuleKey(RULE_KEY.rule())
     .setStatus(Issue.STATUS_OPEN);
+  Settings projectSettings;
+  ProjectSettingsRepository projectSettingsRepository = mock(ProjectSettingsRepository.class);
   ComputationContext context = mock(ComputationContext.class, Mockito.RETURNS_DEEP_STUBS);
   UserIndex userIndex = mock(UserIndex.class);
 
@@ -79,7 +84,9 @@ public class IssueComputationTest {
   public void setUp() throws IOException {
     when(ruleCache.get(RULE_KEY)).thenReturn(rule);
     outputIssues = new IssueCache(temp.newFile(), System2.INSTANCE);
-    sut = new IssueComputation(ruleCache, lineCache, scmAccountCache, outputIssues, userIndex);
+    projectSettings = new Settings();
+    when(projectSettingsRepository.getProjectSettings(PROJECT_KEY)).thenReturn(projectSettings);
+    sut = new IssueComputation(ruleCache, lineCache, scmAccountCache, outputIssues, userIndex, projectSettingsRepository);
   }
 
   @After
@@ -193,7 +200,7 @@ public class IssueComputationTest {
   public void assign_default_assignee_when_available() {
     inputIssue.setIsNew(true);
     String wolinski = "wolinski";
-    when(context.getProjectSettings().getString(CoreProperties.DEFAULT_ISSUE_ASSIGNEE)).thenReturn(wolinski);
+    projectSettings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, wolinski);
     when(userIndex.getNullableByLogin(wolinski)).thenReturn(new UserDoc());
 
     process();
@@ -206,7 +213,7 @@ public class IssueComputationTest {
   public void do_not_assign_default_assignee_when_not_found_in_index() {
     inputIssue.setIsNew(true);
     String wolinski = "wolinski";
-    when(context.getProjectSettings().getString(CoreProperties.DEFAULT_ISSUE_ASSIGNEE)).thenReturn(wolinski);
+    projectSettings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, wolinski);
     when(userIndex.getNullableByLogin(wolinski)).thenReturn(null);
 
     process();
@@ -216,6 +223,6 @@ public class IssueComputationTest {
   }
 
   private void process() {
-    sut.processComponentIssues(context, Arrays.asList(inputIssue.build()), "FILE_A", 1, "PROJECT_KEY", "PROJECT_UUID");
+    sut.processComponentIssues(context, Arrays.asList(inputIssue.build()), "FILE_A", 1, PROJECT_KEY, "PROJECT_UUID");
   }
 }
index 35d0f55a366949e1b057d0040f34b5a8a7ec5e21..4d22e16fd635d02b607764d9f461b3d029aab2b1 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.sonar.server.computation.step;
 
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -29,15 +30,15 @@ import org.sonar.api.config.Settings;
 import org.sonar.batch.protocol.output.BatchReport;
 import org.sonar.batch.protocol.output.BatchReportReader;
 import org.sonar.batch.protocol.output.BatchReportWriter;
-import org.sonar.core.component.ComponentDto;
 import org.sonar.core.computation.dbcleaner.ProjectCleaner;
 import org.sonar.core.persistence.DbSession;
 import org.sonar.core.purge.IdUuidPair;
 import org.sonar.server.computation.ComputationContext;
 import org.sonar.server.computation.component.ComponentTreeBuilders;
+import org.sonar.server.computation.component.DbComponentsRefCache;
 import org.sonar.server.computation.component.DumbComponent;
+import org.sonar.server.computation.component.ProjectSettingsRepository;
 import org.sonar.server.computation.language.LanguageRepository;
-import org.sonar.server.computation.component.DbComponentsRefCache;
 import org.sonar.server.db.DbClient;
 
 import java.io.File;
@@ -47,17 +48,27 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 public class PurgeDatastoresStepTest extends BaseStepTest {
 
+  @Rule
+  public TemporaryFolder temp = new TemporaryFolder();
+
   private static final String PROJECT_KEY = "PROJECT_KEY";
 
   ProjectCleaner projectCleaner = mock(ProjectCleaner.class);
   DbComponentsRefCache dbComponentsRefCache = new DbComponentsRefCache();
-  PurgeDatastoresStep sut = new PurgeDatastoresStep(mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS), projectCleaner, dbComponentsRefCache);
+  ProjectSettingsRepository projectSettingsRepository = mock(ProjectSettingsRepository.class);
+  PurgeDatastoresStep sut = new PurgeDatastoresStep(mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS), projectCleaner, dbComponentsRefCache, projectSettingsRepository);
 
-  @Rule
-  public TemporaryFolder temp = new TemporaryFolder();
+  Settings projectSettings;
+
+  @Before
+  public void setUp() throws Exception {
+    projectSettings = new Settings();
+    when(projectSettingsRepository.getProjectSettings(PROJECT_KEY)).thenReturn(projectSettings);
+  }
 
   @Test
   public void call_purge_method_of_the_purge_task() throws IOException {
@@ -69,8 +80,8 @@ public class PurgeDatastoresStepTest extends BaseStepTest {
       .setRootComponentRef(1)
       .build());
 
-    ComponentDto project = mock(ComponentDto.class);
-    ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings(), mock(DbClient.class), ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class));
+    ComputationContext context = new ComputationContext(new BatchReportReader(reportDir), PROJECT_KEY, new Settings(),
+      mock(DbClient.class), ComponentTreeBuilders.from(DumbComponent.DUMB_PROJECT), mock(LanguageRepository.class));
 
     sut.execute(context);
 
diff --git a/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsFactoryTest.java
deleted file mode 100644 (file)
index bdaacdd..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.properties;
-
-import com.google.common.collect.Lists;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-import org.sonar.core.properties.PropertiesDao;
-import org.sonar.core.properties.PropertyDto;
-
-import java.util.Map;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-public class ProjectSettingsFactoryTest {
-
-  private ProjectSettingsFactory sut;
-
-  @Before
-  public void before() {
-    Settings settings = mock(Settings.class);
-    PropertiesDao dao = mock(PropertiesDao.class);
-
-    this.sut = new ProjectSettingsFactory(settings, dao);
-  }
-
-  @Test
-  public void newProjectSettings_returns_a_ProjectSettings() {
-    Settings projectSettings = sut.newProjectSettings("PROJECT_KEY");
-
-    assertThat(projectSettings).isInstanceOf(ProjectSettings.class);
-  }
-
-  @Test
-  public void transform_empty_list_into_empty_map() {
-    Map<String, String> propertyMap = sut.getPropertyMap(Lists.<PropertyDto>newArrayList());
-
-    assertThat(propertyMap).isEmpty();
-  }
-
-  @Test
-  public void transform_list_of_properties_in_map_key_value() {
-    PropertyDto property1 = new PropertyDto().setKey("1").setValue("val1");
-    PropertyDto property2 = new PropertyDto().setKey("2").setValue("val2");
-    PropertyDto property3 = new PropertyDto().setKey("3").setValue("val3");
-
-    Map<String, String> propertyMap = sut.getPropertyMap(newArrayList(property1, property2, property3));
-
-    assertThat(propertyMap.get("1")).isEqualTo("val1");
-    assertThat(propertyMap.get("2")).isEqualTo("val2");
-    assertThat(propertyMap.get("3")).isEqualTo("val3");
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsRespositoryFactoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsRespositoryFactoryTest.java
new file mode 100644 (file)
index 0000000..9e454ca
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.properties;
+
+import com.google.common.collect.Lists;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.properties.PropertiesDao;
+import org.sonar.core.properties.PropertyDto;
+
+import java.util.Map;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+public class ProjectSettingsRespositoryFactoryTest {
+
+  private ProjectSettingsFactory sut;
+
+  @Before
+  public void before() {
+    Settings settings = mock(Settings.class);
+    PropertiesDao dao = mock(PropertiesDao.class);
+
+    this.sut = new ProjectSettingsFactory(settings, dao);
+  }
+
+  @Test
+  public void newProjectSettings_returns_a_ProjectSettings() {
+    Settings projectSettings = sut.newProjectSettings("PROJECT_KEY");
+
+    assertThat(projectSettings).isInstanceOf(ProjectSettings.class);
+  }
+
+  @Test
+  public void transform_empty_list_into_empty_map() {
+    Map<String, String> propertyMap = sut.getPropertyMap(Lists.<PropertyDto>newArrayList());
+
+    assertThat(propertyMap).isEmpty();
+  }
+
+  @Test
+  public void transform_list_of_properties_in_map_key_value() {
+    PropertyDto property1 = new PropertyDto().setKey("1").setValue("val1");
+    PropertyDto property2 = new PropertyDto().setKey("2").setValue("val2");
+    PropertyDto property3 = new PropertyDto().setKey("3").setValue("val3");
+
+    Map<String, String> propertyMap = sut.getPropertyMap(newArrayList(property1, property2, property3));
+
+    assertThat(propertyMap.get("1")).isEqualTo("val1");
+    assertThat(propertyMap.get("2")).isEqualTo("val2");
+    assertThat(propertyMap.get("3")).isEqualTo("val3");
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsRespositoryTest.java b/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsRespositoryTest.java
new file mode 100644 (file)
index 0000000..214729c
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.properties;
+
+import com.google.common.collect.Maps;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+
+import java.util.HashMap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class ProjectSettingsRespositoryTest {
+
+  private ProjectSettings sut;
+
+  private Settings settings;
+
+  @Before
+  public void before() {
+    this.settings = mock(Settings.class);
+  }
+
+  @Test
+  public void call_global_settings_method_when_no_project_specific_settings() {
+    this.sut = new ProjectSettings(settings, Maps.<String, String>newHashMap());
+
+    sut.getInt("anyKey");
+    sut.getBoolean("anyKey");
+    sut.getString("anyKey");
+
+    verify(settings, times(1)).getBoolean(anyString());
+    verify(settings, times(1)).getInt(anyString());
+    verify(settings, times(1)).getString(anyString());
+  }
+
+  @Test(expected = NumberFormatException.class)
+  public void getInt_property_throws_exception_when_value_is_not_formatted_correctly() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("intKey", "wrongIntValue");
+    this.sut = new ProjectSettings(settings, properties);
+
+    sut.getInt("intKey");
+  }
+
+  @Test
+  public void getInt_property_return_0_when_empty_property() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("intKey", "");
+    this.sut = new ProjectSettings(settings, properties);
+
+    int value = sut.getInt("intKey");
+
+    assertThat(value).isEqualTo(0);
+  }
+
+  @Test
+  public void getInt_property_return_the_int_value() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("intKey", "123");
+    this.sut = new ProjectSettings(settings, properties);
+
+    int value = sut.getInt("intKey");
+
+    assertThat(value).isEqualTo(123);
+  }
+
+  @Test
+  public void getString_returns_String_property() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("stringKey", "stringValue");
+    this.sut = new ProjectSettings(settings, properties);
+
+    String value = sut.getString("stringKey");
+
+    assertThat(value).isEqualTo("stringValue");
+  }
+
+  @Test
+  public void getBoolean_returns_exception_when_value_is_not_formatted_correctly() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("boolKey", "wronglyFormattedBoolean");
+    this.sut = new ProjectSettings(settings, properties);
+
+    boolean key = sut.getBoolean("boolKey");
+
+    assertThat(key).isFalse();
+  }
+
+  @Test
+  public void getBoolean_returns_false_when_value_is_empty() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("boolKey", "");
+    this.sut = new ProjectSettings(settings, properties);
+
+    boolean key = sut.getBoolean("boolKey");
+
+    assertThat(key).isFalse();
+  }
+
+  @Test
+  public void getBoolean_returns_true_when_value_is_true_ignoring_case() {
+    HashMap<String, String> properties = Maps.newHashMap();
+    properties.put("boolKey1", "true");
+    properties.put("boolKey2", "True");
+    this.sut = new ProjectSettings(settings, properties);
+
+    boolean key1 = sut.getBoolean("boolKey1");
+    boolean key2 = sut.getBoolean("boolKey2");
+
+    assertThat(key1).isTrue();
+    assertThat(key2).isTrue();
+  }
+}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsTest.java b/server/sonar-server/src/test/java/org/sonar/server/properties/ProjectSettingsTest.java
deleted file mode 100644 (file)
index 633fb25..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.server.properties;
-
-import com.google.common.collect.Maps;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.config.Settings;
-
-import java.util.HashMap;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
-
-public class ProjectSettingsTest {
-
-  private ProjectSettings sut;
-
-  private Settings settings;
-
-  @Before
-  public void before() {
-    this.settings = mock(Settings.class);
-  }
-
-  @Test
-  public void call_global_settings_method_when_no_project_specific_settings() {
-    this.sut = new ProjectSettings(settings, Maps.<String, String>newHashMap());
-
-    sut.getInt("anyKey");
-    sut.getBoolean("anyKey");
-    sut.getString("anyKey");
-
-    verify(settings, times(1)).getBoolean(anyString());
-    verify(settings, times(1)).getInt(anyString());
-    verify(settings, times(1)).getString(anyString());
-  }
-
-  @Test(expected = NumberFormatException.class)
-  public void getInt_property_throws_exception_when_value_is_not_formatted_correctly() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("intKey", "wrongIntValue");
-    this.sut = new ProjectSettings(settings, properties);
-
-    sut.getInt("intKey");
-  }
-
-  @Test
-  public void getInt_property_return_0_when_empty_property() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("intKey", "");
-    this.sut = new ProjectSettings(settings, properties);
-
-    int value = sut.getInt("intKey");
-
-    assertThat(value).isEqualTo(0);
-  }
-
-  @Test
-  public void getInt_property_return_the_int_value() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("intKey", "123");
-    this.sut = new ProjectSettings(settings, properties);
-
-    int value = sut.getInt("intKey");
-
-    assertThat(value).isEqualTo(123);
-  }
-
-  @Test
-  public void getString_returns_String_property() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("stringKey", "stringValue");
-    this.sut = new ProjectSettings(settings, properties);
-
-    String value = sut.getString("stringKey");
-
-    assertThat(value).isEqualTo("stringValue");
-  }
-
-  @Test
-  public void getBoolean_returns_exception_when_value_is_not_formatted_correctly() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("boolKey", "wronglyFormattedBoolean");
-    this.sut = new ProjectSettings(settings, properties);
-
-    boolean key = sut.getBoolean("boolKey");
-
-    assertThat(key).isFalse();
-  }
-
-  @Test
-  public void getBoolean_returns_false_when_value_is_empty() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("boolKey", "");
-    this.sut = new ProjectSettings(settings, properties);
-
-    boolean key = sut.getBoolean("boolKey");
-
-    assertThat(key).isFalse();
-  }
-
-  @Test
-  public void getBoolean_returns_true_when_value_is_true_ignoring_case() {
-    HashMap<String, String> properties = Maps.newHashMap();
-    properties.put("boolKey1", "true");
-    properties.put("boolKey2", "True");
-    this.sut = new ProjectSettings(settings, properties);
-
-    boolean key1 = sut.getBoolean("boolKey1");
-    boolean key2 = sut.getBoolean("boolKey2");
-
-    assertThat(key1).isTrue();
-    assertThat(key2).isTrue();
-  }
-}