aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java/org/sonar/batch/phases
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-01-23 09:47:58 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-01-23 09:52:57 +0100
commitdc19e6d7dceb39c04ba7cfc2e7ba99f2650f1504 (patch)
treecf491c7c6ba02d2276038404d2a64ccd953033e7 /sonar-batch/src/test/java/org/sonar/batch/phases
parentb9798b1f7f3a6014a84aac497f2db04d326d035d (diff)
downloadsonarqube-dc19e6d7dceb39c04ba7cfc2e7ba99f2650f1504.tar.gz
sonarqube-dc19e6d7dceb39c04ba7cfc2e7ba99f2650f1504.zip
SONAR-3024 Perform one shot migration of all project resources
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar/batch/phases')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java76
1 files changed, 37 insertions, 39 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java
index cf8d3aaf20c..e029d097752 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/FileIndexerTest.java
@@ -20,7 +20,6 @@
package org.sonar.batch.phases;
import com.google.common.base.Charsets;
-import edu.emory.mathcs.backport.java.util.Collections;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.CharEncoding;
import org.junit.Before;
@@ -40,8 +39,10 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Resource;
import org.sonar.api.scan.filesystem.FileQuery;
+import org.sonar.api.scan.filesystem.internal.DefaultInputFile;
import org.sonar.api.scan.filesystem.internal.InputFile;
import org.sonar.api.scan.filesystem.internal.InputFileBuilder;
+import org.sonar.batch.index.ResourceKeyMigration;
import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
import java.io.File;
@@ -88,19 +89,13 @@ public class FileIndexerTest {
}
@Test
- public void should_index_java_files() {
- File javaFile1 = new File(baseDir, "src/main/java/foo/bar/Foo.java");
- File javaFile2 = new File(baseDir, "src/main/java2/foo/bar/Foo.java");
- when(fs.inputFiles(FileQuery.onSource().onLanguage(Java.KEY))).thenReturn((Iterable) Arrays.asList(
- new InputFileBuilder(javaFile1, Charsets.UTF_8, "src/main/java/foo/bar/Foo.java").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java").build(),
- new InputFileBuilder(javaFile2, Charsets.UTF_8, "src/main/java2/foo/bar/Foo.java").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java").build()));
- File javaTestFile1 = new File(baseDir, "src/test/java/foo/bar/FooTest.java");
- when(fs.inputFiles(FileQuery.onTest().onLanguage(Java.KEY))).thenReturn(
- (Iterable) Arrays.asList(
- new InputFileBuilder(javaTestFile1, Charsets.UTF_8, "src/test/java/foo/bar/FooTest.java").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/FooTest.java")
- .build()));
+ public void should_index_java_files() throws IOException {
+ when(fs.inputFiles(FileQuery.all())).thenReturn((Iterable) Arrays.asList(
+ newInputFile("src/main/java/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false),
+ newInputFile("src/main/java2/foo/bar/Foo.java", "", "foo/bar/Foo.java", "java", false),
+ newInputFile("src/test/java/foo/bar/FooTest.java", "", "foo/bar/FooTest.java", "java", true)));
when(project.getLanguageKey()).thenReturn(Java.KEY);
- FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings);
+ FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings, mock(ResourceKeyMigration.class));
indexer.execute();
verify(sonarIndex).index(JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false));
@@ -118,17 +113,13 @@ public class FileIndexerTest {
@Test
public void should_index_cobol_files() throws IOException {
- File cobolFile1 = new File(baseDir, "src/foo/bar/Foo.cbl");
- File cobolFile2 = new File(baseDir, "src2/foo/bar/Foo.cbl");
- when(fs.inputFiles(FileQuery.onSource().onLanguage("cobol"))).thenReturn((Iterable) Arrays.asList(
- new InputFileBuilder(cobolFile1, Charsets.UTF_8, "src/foo/bar/Foo.cbl").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.cbl").build(),
- new InputFileBuilder(cobolFile2, Charsets.UTF_8, "src2/foo/bar/Foo.cbl").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.cbl").build()));
- File cobolTestFile1 = new File(baseDir, "src/test/foo/bar/FooTest.cbl");
- when(fs.inputFiles(FileQuery.onTest().onLanguage("cobol"))).thenReturn((Iterable) Arrays.asList(
- new InputFileBuilder(cobolTestFile1, Charsets.UTF_8, "src/test/foo/bar/FooTest.cbl").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/FooTest.cbl").build()));
+ when(fs.inputFiles(FileQuery.all())).thenReturn((Iterable) Arrays.asList(
+ newInputFile("src/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false),
+ newInputFile("src2/foo/bar/Foo.cbl", "", "foo/bar/Foo.cbl", "cobol", false),
+ newInputFile("src/test/foo/bar/FooTest.cbl", "", "foo/bar/FooTest.cbl", "cobol", true)));
when(project.getLanguageKey()).thenReturn("cobol");
- FileIndexer indexer = new FileIndexer(project, fs, new Languages(cobolLanguage), sonarIndex, settings);
+ FileIndexer indexer = new FileIndexer(project, fs, new Languages(cobolLanguage), sonarIndex, settings, mock(ResourceKeyMigration.class));
indexer.execute();
verify(sonarIndex).index(org.sonar.api.resources.File.create("/src/foo/bar/Foo.cbl", "foo/bar/Foo.cbl", cobolLanguage, false));
@@ -140,14 +131,10 @@ public class FileIndexerTest {
public void shouldImportSource() throws IOException {
settings.setProperty(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY, "true");
- File javaFile1 = new File(baseDir, "src/main/java/foo/bar/Foo.java");
- FileUtils.write(javaFile1, "sample code");
- when(fs.inputFiles(FileQuery.onSource().onLanguage(Java.KEY))).thenReturn((Iterable) Arrays.asList(
- new InputFileBuilder(javaFile1, Charsets.UTF_8, "src/main/java/foo/bar/Foo.java").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java").build()));
- when(fs.inputFiles(FileQuery.onTest().onLanguage(Java.KEY))).thenReturn(
- (Iterable) Collections.emptyList());
+ when(fs.inputFiles(FileQuery.all())).thenReturn((Iterable) Arrays.asList(
+ newInputFile("src/main/java/foo/bar/Foo.java", "sample code", "foo/bar/Foo.java", "java", false)));
when(project.getLanguageKey()).thenReturn(Java.KEY);
- FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings);
+ FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings, mock(ResourceKeyMigration.class));
indexer.execute();
Resource sonarFile = JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false);
@@ -155,6 +142,16 @@ public class FileIndexerTest {
verify(sonarIndex).setSource(sonarFile, "sample code");
}
+ private DefaultInputFile newInputFile(String path, String content, String sourceRelativePath, String languageKey, boolean unitTest) throws IOException {
+ File file = new File(baseDir, path);
+ FileUtils.write(file, content);
+ return new InputFileBuilder(file, Charsets.UTF_8, path)
+ .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, sourceRelativePath)
+ .attribute(InputFile.ATTRIBUTE_LANGUAGE, languageKey)
+ .attribute(InputFile.ATTRIBUTE_TYPE, unitTest ? InputFile.TYPE_TEST : InputFile.TYPE_SOURCE)
+ .build();
+ }
+
@Test
public void should_use_mac_roman_charset_for_reading_source_files() throws Exception {
String encoding = "MacRoman";
@@ -182,12 +179,13 @@ public class FileIndexerTest {
File javaFile1 = new File(baseDir, "src/main/java/foo/bar/Foo.java");
FileUtils.write(javaFile1, "\uFEFFpublic class Test", Charsets.UTF_8);
- when(fs.inputFiles(FileQuery.onSource().onLanguage(Java.KEY))).thenReturn((Iterable) Arrays.asList(
- new InputFileBuilder(javaFile1, Charsets.UTF_8, "src/main/java/foo/bar/Foo.java").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java").build()));
- when(fs.inputFiles(FileQuery.onTest().onLanguage(Java.KEY))).thenReturn(
- (Iterable) Collections.emptyList());
+ when(fs.inputFiles(FileQuery.all())).thenReturn((Iterable) Arrays.asList(
+ new InputFileBuilder(javaFile1, Charset.forName("UTF-8"), "src/main/java/foo/bar/Foo.java")
+ .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java")
+ .attribute(InputFile.ATTRIBUTE_LANGUAGE, "java")
+ .build()));
when(project.getLanguageKey()).thenReturn(Java.KEY);
- FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings);
+ FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings, mock(ResourceKeyMigration.class));
indexer.execute();
Resource sonarFile = JavaFile.create("src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false);
@@ -206,15 +204,15 @@ public class FileIndexerTest {
File javaFile1 = new File(baseDir, "src/main/java/foo/bar/Foo.java");
FileUtils.copyFile(getFile(testFile), javaFile1);
- when(fs.inputFiles(FileQuery.onSource().onLanguage(Java.KEY)))
+ when(fs.inputFiles(FileQuery.all()))
.thenReturn(
(Iterable) Arrays.asList(
- new InputFileBuilder(javaFile1, Charset.forName(encoding), "src/main/java/foo/bar/Foo.java").attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java")
+ new InputFileBuilder(javaFile1, Charset.forName(encoding), "src/main/java/foo/bar/Foo.java")
+ .attribute(InputFile.ATTRIBUTE_SOURCE_RELATIVE_PATH, "foo/bar/Foo.java")
+ .attribute(InputFile.ATTRIBUTE_LANGUAGE, "java")
.build()));
- when(fs.inputFiles(FileQuery.onTest().onLanguage(Java.KEY))).thenReturn(
- (Iterable) Collections.emptyList());
when(project.getLanguageKey()).thenReturn(Java.KEY);
- FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings);
+ FileIndexer indexer = new FileIndexer(project, fs, new Languages(Java.INSTANCE), sonarIndex, settings, mock(ResourceKeyMigration.class));
indexer.execute();
Resource sonarFile = JavaFile.create("/src/main/java/foo/bar/Foo.java", "foo/bar/Foo.java", false);