diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-04 10:16:50 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-11-04 10:17:18 +0100 |
commit | 88554cc3c9747e266247f7d27ab3c22c93c6fa0d (patch) | |
tree | 7cd18655d9787b222825b022682201933ff6faed /sonar-batch/src/test | |
parent | 8c4d787e20a63ece8620eac0a7686cb16dc536a7 (diff) | |
download | sonarqube-88554cc3c9747e266247f7d27ab3c22c93c6fa0d.tar.gz sonarqube-88554cc3c9747e266247f7d27ab3c22c93c6fa0d.zip |
SONAR-2967 extract the new component ProjectFilter from ProjectTree
Diffstat (limited to 'sonar-batch/src/test')
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java | 91 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java | 46 |
2 files changed, 137 insertions, 0 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java new file mode 100644 index 00000000000..d01f5150bf9 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectFilterTest.java @@ -0,0 +1,91 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.bootstrap; + +import org.junit.Test; +import org.sonar.api.config.Settings; +import org.sonar.api.resources.Project; +import org.sonar.batch.config.ProjectSettings; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class ProjectFilterTest { + + @Test + public void testSkippedModule() { + Settings settings = new Settings(); + settings.setProperty("sonar.skippedModules", "foo,bar"); + + ProjectFilter filter = new ProjectFilter(settings); + assertTrue(filter.isExcluded(new Project("my:foo"))); + } + + @Test + public void testNotExcluded() { + Settings settings = new Settings(); + settings.setProperty("sonar.skippedModules", "foo,bar"); + + ProjectFilter filter = new ProjectFilter(settings); + assertFalse(filter.isExcluded(new Project("my:other"))); + } + + @Test + public void testNoSkippedModules() { + Settings settings = new Settings(); + + ProjectFilter filter = new ProjectFilter(settings); + assertFalse(filter.isExcluded(new Project("my:other"))); + } + + @Test + public void testIncludedModules() { + Settings settings = new Settings(); + settings.setProperty("sonar.includedModules", "foo"); + + ProjectFilter filter = new ProjectFilter(settings); + assertFalse(filter.isExcluded(new Project("my:foo"))); + + filter = new ProjectFilter(settings); + assertTrue(filter.isExcluded(new Project("my:bar"))); + } + + @Test + public void shouldBeExcludedIfParentIsExcluded() { + Settings settings = new Settings(); + settings.setProperty("sonar.skippedModules", "parent"); + + Project parent = new Project("my:parent"); + Project child = new Project("my:child"); + child.setParent(parent); + + ProjectFilter filter = new ProjectFilter(settings); + assertTrue(filter.isExcluded(child)); + } + + @Test + public void testGetArtifactId() { + assertThat(ProjectFilter.getArtifactId(new Project("org:foo")), is("foo")); + assertThat(ProjectFilter.getArtifactId(new Project("foo")), is("foo")); + assertThat(ProjectFilter.getArtifactId(new Project("org:foo:1.x").setBranch("1.x")), is("foo")); + } +} diff --git a/sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java b/sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java new file mode 100644 index 00000000000..0cd4f31c023 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/config/ProjectSettingsTest.java @@ -0,0 +1,46 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar 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. + * + * Sonar 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 Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.batch.config; + +import org.hamcrest.core.Is; +import org.junit.Test; +import org.sonar.api.batch.bootstrap.ProjectDefinition; + +import java.util.List; + +import static org.junit.Assert.assertThat; + +public class ProjectSettingsTest { + + @Test + public void testOrderedProjects() { + ProjectDefinition grandParent = ProjectDefinition.create(); + ProjectDefinition parent = ProjectDefinition.create(); + ProjectDefinition child = ProjectDefinition.create(); + grandParent.addSubProject(parent); + parent.addSubProject(child); + + List<ProjectDefinition> hierarchy = ProjectSettings.getOrderedProjects(child); + assertThat(hierarchy.get(0), Is.is(grandParent)); + assertThat(hierarchy.get(1), Is.is(parent)); + assertThat(hierarchy.get(2), Is.is(child)); + + } +} |