aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-01-25 16:20:08 +0300
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-01-25 16:20:08 +0300
commit0effb8e5016195ace8a295d44eaa245e265ff0b7 (patch)
tree772e69bd9674030a648d92e8802698ee63c774e0 /sonar-batch/src/test/java
parent10b9b9914cb775cb892036d4ae895c47ff602946 (diff)
downloadsonarqube-0effb8e5016195ace8a295d44eaa245e265ff0b7.tar.gz
sonarqube-0effb8e5016195ace8a295d44eaa245e265ff0b7.zip
Add new property "sonar.projectBinaries"
Diffstat (limited to 'sonar-batch/src/test/java')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java123
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/InMemoryPomTest.java67
2 files changed, 123 insertions, 67 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java
new file mode 100644
index 00000000000..b9336e43deb
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomCreatorTest.java
@@ -0,0 +1,123 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2009 SonarSource SA
+ * 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;
+
+import org.apache.maven.project.MavenProject;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.SonarException;
+import org.sonar.batch.bootstrapper.ProjectDefinition;
+
+import java.io.File;
+import java.util.Properties;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class InMemoryPomCreatorTest {
+
+ private Properties properties;
+ private ProjectDefinition project;
+
+ @Before
+ public void setUp() {
+ properties = new Properties();
+ File baseDir = new File(".");
+ project = new ProjectDefinition(baseDir, properties);
+ }
+
+ @Test
+ public void shouldCreate() throws Exception {
+ createRequiredProperties("org.example:example", "1.0-SNAPSHOT", "target");
+ properties.setProperty("sonar.projectBinaries", "junit.jar");
+
+ project.addSourceDir("src");
+ project.addTestDir("test");
+
+ MavenProject pom = create();
+
+ assertThat(pom.getBasedir(), is(project.getBaseDir()));
+ assertThat(pom.getGroupId(), is("org.example"));
+ assertThat(pom.getArtifactId(), is("example"));
+ assertThat(pom.getProperties(), is(project.getProperties()));
+ assertThat(pom.getBuild().getDirectory(), is("target"));
+ assertThat(pom.getBuild().getOutputDirectory(), is("target/classes"));
+ assertThat(pom.getReporting().getOutputDirectory(), is("target/site"));
+
+ assertThat(pom.getCompileSourceRoots().size(), is(1));
+ assertThat((String) pom.getCompileSourceRoots().get(0), is("src"));
+
+ assertThat(pom.getTestCompileSourceRoots().size(), is(1));
+ assertThat((String) pom.getTestCompileSourceRoots().get(0), is("test"));
+
+ assertThat(pom.getCompileClasspathElements().size(), is(1));
+ assertThat((String) pom.getCompileClasspathElements().get(0), is("junit.jar"));
+ }
+
+ @Test
+ public void nonStandardDirectoriesLayout() {
+ createRequiredProperties("org.example:example", "1.0-SNAPSHOT", "build");
+ properties.setProperty("project.build.outputDirectory", "bin");
+ properties.setProperty("project.reporting.outputDirectory", "build/reports");
+
+ MavenProject pom = create();
+
+ assertThat(pom.getBuild().getDirectory(), is("build"));
+ assertThat(pom.getBuild().getOutputDirectory(), is("bin"));
+ assertThat(pom.getReporting().getOutputDirectory(), is("build/reports"));
+ }
+
+ @Test
+ public void shouldNotFailIfNoBinaries() throws Exception {
+ createRequiredProperties("org.example:example", "1.0-SNAPSHOT", "build");
+
+ MavenProject pom = create();
+ assertThat(pom.getCompileClasspathElements().size(), is(0));
+ }
+
+ private void createRequiredProperties(String key, String version, String buildDirectory) {
+ properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, key);
+ properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, version);
+ properties.setProperty("project.build.directory", buildDirectory);
+ }
+
+ @Test(expected = SonarException.class)
+ public void shouldFailWhenKeyNotSpecified() {
+ create();
+ }
+
+ @Test(expected = SonarException.class)
+ public void shouldFailWhenVersionNotSpecified() {
+ properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example");
+ create();
+ }
+
+ @Test(expected = SonarException.class)
+ public void shouldFailWhenBuildDirectoryNotSpecified() {
+ properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example");
+ properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "0.1");
+ create();
+ }
+
+ private MavenProject create() {
+ return new InMemoryPomCreator(project).create();
+ }
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomTest.java b/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomTest.java
deleted file mode 100644
index 69d5a32826d..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/InMemoryPomTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.sonar.batch;
-
-import org.apache.maven.project.MavenProject;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.utils.SonarException;
-import org.sonar.batch.bootstrapper.ProjectDefinition;
-
-import java.io.File;
-import java.util.Properties;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-
-public class InMemoryPomTest {
-
- private Properties properties;
- private ProjectDefinition project;
-
- @Before
- public void setUp() {
- properties = new Properties();
- File baseDir = new File(".");
- project = new ProjectDefinition(baseDir, properties);
- }
-
- @Test
- public void shouldCreate() {
- properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example");
- properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0-SNAPSHOT");
- properties.setProperty("project.build.directory", "build");
-
- project.addSourceDir("src");
- project.addTestDir("test");
-
- MavenProject pom = ProjectTree.createInMemoryPom(project);
-
- assertThat(pom.getBasedir(), is(project.getBaseDir()));
- assertThat(pom.getGroupId(), is("org.example"));
- assertThat(pom.getArtifactId(), is("example"));
- assertThat(pom.getProperties(), is(project.getProperties()));
- assertThat(pom.getBuild().getDirectory(), is("build"));
-
- assertThat(pom.getCompileSourceRoots().size(), is(1));
- assertThat(pom.getTestCompileSourceRoots().size(), is(1));
- }
-
- @Test(expected = SonarException.class)
- public void shouldFailWhenKeyNotSpecified() {
- ProjectTree.createInMemoryPom(project);
- }
-
- @Test(expected = SonarException.class)
- public void shouldFailWhenVersionNotSpecified() {
- properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example");
- ProjectTree.createInMemoryPom(project);
- }
-
- @Test(expected = SonarException.class)
- public void shouldFailWhenBuildDirectoryNotSpecified() {
- properties.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "org.example:example");
- properties.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "0.1");
- ProjectTree.createInMemoryPom(project);
- }
-
-}