*/
package org.sonar.plugins.core.issue.notification;
+import com.google.common.io.Resources;
+import org.apache.commons.codec.Charsets;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
import org.sonar.plugins.emailnotifications.api.EmailMessage;
-import org.sonar.test.TestUtils;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
String message = email.getMessage();
- String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt");
- expectedMessage = StringUtils.remove(expectedMessage, '\r');
- assertThat(message).isEqualTo(expectedMessage);
+ String expected = Resources.toString(Resources.getResource(
+ "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt"),
+ Charsets.UTF_8
+ );
+ expected = StringUtils.remove(expected, '\r');
+ assertThat(message).isEqualTo(expected);
assertThat(email.getFrom()).isNull();
}
assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
String message = email.getMessage();
- String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt");
- expectedMessage = StringUtils.remove(expectedMessage, '\r');
- assertThat(message).isEqualTo(expectedMessage);
+ String expected = Resources.toString(Resources.getResource(
+ "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt"),
+ Charsets.UTF_8
+ );
+ expected = StringUtils.remove(expected, '\r');
+ assertThat(message).isEqualTo(expected);
assertThat(email.getFrom()).isNull();
}
@Test
- public void test_email_with_multiple_changes() {
+ public void test_email_with_multiple_changes() throws Exception {
Notification notification = generateNotification()
.setFieldValue("comment", "How to fix it?")
.setFieldValue("old.assignee", "simon")
assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
String message = email.getMessage();
- String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt");
- expectedMessage = StringUtils.remove(expectedMessage, '\r');
- assertThat(message).isEqualTo(expectedMessage);
+ String expected = Resources.toString(Resources.getResource(
+ "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"), Charsets.UTF_8);
+ expected = StringUtils.remove(expected, '\r');
+ assertThat(message).isEqualTo(expected);
assertThat(email.getFrom()).isNull();
}
*/
package org.sonar.batch.bootstrap;
+import com.google.common.io.Resources;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.sonar.core.plugins.RemotePlugin;
import org.sonar.home.cache.FileCache;
import org.sonar.home.cache.FileCacheBuilder;
-import org.sonar.test.TestUtils;
import java.io.File;
import java.io.IOException;
}
@Test
- public void shouldLoadPlugin() throws IOException {
+ public void shouldLoadPlugin() throws Exception {
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
PluginDownloader downloader = mock(PluginDownloader.class);
}
@Test
- public void shouldLoadPluginExtension() throws IOException {
+ public void shouldLoadPluginExtension() throws Exception {
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
}
@Test
- public void shouldExcludePluginAndItsExtensions() throws IOException {
+ public void shouldExcludePluginAndItsExtensions() throws Exception {
RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
assertThat(repository.getMetadata()).isEmpty();
}
- private File fileFromCache(String filename) throws IOException {
- File file = TestUtils.getResource("/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename);
+ private File fileFromCache(String filename) throws Exception {
+ File file = new File(Resources.getResource("org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename).toURI());
File destDir = new File(userHome, "cache/foomd5");
FileUtils.forceMkdir(destDir);
FileUtils.copyFileToDirectory(file, destDir);
package org.sonar.batch.issue.ignore.scanner;
-import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer;
-import org.sonar.batch.issue.ignore.pattern.IssuePattern;
-import org.sonar.batch.issue.ignore.pattern.LineRange;
-import org.sonar.batch.issue.ignore.pattern.PatternMatcher;
-import org.sonar.batch.issue.ignore.scanner.IssueExclusionsRegexpScanner;
-
import com.google.common.collect.Sets;
+import com.google.common.io.Resources;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.sonar.test.TestUtils;
+import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer;
+import org.sonar.batch.issue.ignore.pattern.IssuePattern;
+import org.sonar.batch.issue.ignore.pattern.LineRange;
+import org.sonar.batch.issue.ignore.pattern.PatternMatcher;
-import java.io.IOException;
+import java.io.File;
import java.util.Arrays;
import java.util.Set;
}
@Test
- public void shouldDoNothing() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-no-regexp.txt"), UTF_8);
+ public void shouldDoNothing() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-no-regexp.txt").toURI()), UTF_8);
verifyNoMoreInteractions(patternsInitializer);
}
@Test
- public void shouldAddPatternToExcludeFile() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-single-regexp.txt"), UTF_8);
+ public void shouldAddPatternToExcludeFile() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-single-regexp.txt").toURI()), UTF_8);
verify(patternsInitializer).getPatternMatcher();
verify(patternMatcher, times(1)).addPatternToExcludeResource(javaFile);
}
@Test
- public void shouldAddPatternToExcludeFileEvenIfAlsoDoubleRegexps() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-single-regexp-and-double-regexp.txt"), UTF_8);
+ public void shouldAddPatternToExcludeFileEvenIfAlsoDoubleRegexps() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-single-regexp-and-double-regexp.txt").toURI()), UTF_8);
verify(patternsInitializer).getPatternMatcher();
verify(patternMatcher, times(1)).addPatternToExcludeResource(javaFile);
}
@Test
- public void shouldAddPatternToExcludeLines() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp.txt"), UTF_8);
+ public void shouldAddPatternToExcludeLines() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp.txt").toURI()), UTF_8);
Set<LineRange> lineRanges = Sets.newHashSet();
lineRanges.add(new LineRange(21, 25));
}
@Test
- public void shouldAddPatternToExcludeLinesTillTheEnd() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-unfinished.txt"), UTF_8);
+ public void shouldAddPatternToExcludeLinesTillTheEnd() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-unfinished.txt").toURI()), UTF_8);
Set<LineRange> lineRanges = Sets.newHashSet();
lineRanges.add(new LineRange(21, 34));
}
@Test
- public void shouldAddPatternToExcludeSeveralLineRanges() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-twice.txt"), UTF_8);
+ public void shouldAddPatternToExcludeSeveralLineRanges() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-twice.txt").toURI()), UTF_8);
Set<LineRange> lineRanges = Sets.newHashSet();
lineRanges.add(new LineRange(21, 25));
}
@Test
- public void shouldAddPatternToExcludeLinesWithWrongOrder() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-wrong-order.txt"), UTF_8);
+ public void shouldAddPatternToExcludeLinesWithWrongOrder() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-wrong-order.txt").toURI()), UTF_8);
Set<LineRange> lineRanges = Sets.newHashSet();
lineRanges.add(new LineRange(25, 35));
}
@Test
- public void shouldAddPatternToExcludeLinesWithMess() throws IOException {
- regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-mess.txt"), UTF_8);
+ public void shouldAddPatternToExcludeLinesWithMess() throws Exception {
+ regexpScanner.scan(javaFile, new File(Resources.getResource(
+ "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-mess.txt").toURI()), UTF_8);
Set<LineRange> lineRanges = Sets.newHashSet();
lineRanges.add(new LineRange(21, 29));
*/
package org.sonar.batch.maven;
+import com.google.common.io.Resources;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.test.TestUtils;
import java.io.File;
import java.io.IOException;
@Test
public void moduleNameShouldEqualArtifactId() throws Exception {
- File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/");
+ File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/").toURI());
MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true);
MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false);
MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false);
@Test
public void moduleNameDifferentThanArtifactId() throws Exception {
- File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/");
+ File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/").toURI());
MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true);
MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false);
MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false);
@Test
public void should_find_module_with_maven_project_file_naming_different_from_pom_xml() throws Exception {
- File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/");
+ File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/").toURI());
MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true);
MavenProject module = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false);
@Test
public void testSingleProjectWithoutModules() throws Exception {
- File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/");
+ File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/").toURI());
MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true);
ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom);
package org.sonar.batch.scan.report;
import com.google.common.collect.Lists;
+import com.google.common.io.Resources;
+import org.apache.commons.codec.Charsets;
import org.json.JSONException;
import org.junit.Before;
import org.junit.Test;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.scan.filesystem.InputFileCache;
import org.sonar.core.user.DefaultUser;
-import org.sonar.test.TestUtils;
import java.io.File;
import java.io.IOException;
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
- JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/report/JsonReportTest/report.json"),
- writer.toString(), false);
+ String expected = Resources.toString(Resources.getResource("org/sonar/batch/scan/report/JsonReportTest/report.json"), Charsets.UTF_8);
+ JSONAssert.assertEquals(expected, writer.toString(), false);
}
@Test
.setCloseDate(SIMPLE_DATE_FORMAT.parse("2013-04-26"))
.setNew(false);
when(ruleFinder.findByKey(ruleKey)).thenReturn(Rule.create(ruleKey.repository(), ruleKey.rule()).setName("Avoid Cycles"));
- when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
+ when(jsonReport.getIssues()).thenReturn(Lists.newArrayList(issue));
StringWriter writer = new StringWriter();
jsonReport.writeJson(writer);
- JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"),
- writer.toString(), false);
+ String expected = Resources.toString(Resources.getResource(
+ "org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"), Charsets.UTF_8);
+ JSONAssert.assertEquals(expected, writer.toString(), false);
}
@Test
<artifactId>dbunit</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-testing-harness</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>com.github.tlrx</groupId>
<artifactId>elasticsearch-test</artifactId>
package org.sonar.server.debt;
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
import org.junit.Test;
import org.sonar.api.server.debt.DebtCharacteristic;
-import org.sonar.test.TestUtils;
import java.util.List;
}
private String getFileContent(String file) throws Exception {
- return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
+ return Resources.toString(Resources.getResource(getClass(), "DebtCharacteristicsXMLImporterTest/" + file), Charsets.UTF_8);
}
}
*/
package org.sonar.server.debt;
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
import org.apache.commons.lang.CharUtils;
import org.apache.commons.lang.SystemUtils;
import org.custommonkey.xmlunit.Diff;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
-import org.sonar.test.TestUtils;
import java.util.Collections;
import java.util.List;
}
private String getFileContent(String file) throws Exception {
- return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
+ return Resources.toString(Resources.getResource(getClass(), "DebtModelXMLExporterTest/" + file), Charsets.UTF_8);
}
}
package org.sonar.server.debt;
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
import org.junit.Test;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.server.debt.DebtRemediationFunction;
import org.sonar.api.utils.ValidationMessages;
-import org.sonar.test.TestUtils;
import java.util.List;
String xml = getFileContent("import_rules.xml");
List<RuleDebt> results = importer.importXML(xml, validationMessages);
-
+
assertThat(results).hasSize(2);
assertThat(validationMessages.getErrors()).isEmpty();
assertThat(validationMessages.getWarnings()).isEmpty();
}
private String getFileContent(String file) throws Exception {
- return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
+ return Resources.toString(Resources.getResource(getClass(), "DebtRulesXMLImporterTest/" + file),
+ Charsets.UTF_8);
}
}
*/
package org.sonar.server.es;
+import com.google.common.io.Resources;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
import org.elasticsearch.client.AdminClient;
import org.sonar.api.config.Settings;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.utils.ZipUtils;
-import org.sonar.test.TestUtils;
import java.io.File;
import java.io.IOException;
@Test
public void should_restore_status_on_startup() throws Exception {
- ZipUtils.unzip(TestUtils.getResource(ESNodeTest.class, "data-es-clean.zip"), dataDir);
+ File zip = new File(Resources.getResource(getClass(), "ESNodeTest/data-es-clean.zip").toURI());
+ ZipUtils.unzip(zip, dataDir);
ESNode node = new ESNode(fs, new Settings());
node.start();
@Test(expected = IllegalStateException.class)
public void should_fail_on_corrupt_index() throws Exception {
- ZipUtils.unzip(TestUtils.getResource(ESNodeTest.class, "data-es-corrupt.zip"), dataDir);
+ File zip = new File(Resources.getResource(getClass(), "ESNodeTest/data-es-corrupt.zip").toURI());
+ ZipUtils.unzip(zip, dataDir);
ESNode node = new ESNode(fs, new Settings(), "5s");
try {
*/
package org.sonar.server.platform;
+import com.google.common.io.Resources;
import org.junit.Test;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.core.persistence.Database;
import org.sonar.core.persistence.dialect.Dialect;
import org.sonar.core.persistence.dialect.H2;
import org.sonar.core.persistence.dialect.MySql;
-import org.sonar.test.TestUtils;
import java.io.File;
import java.util.List;
public class DefaultServerFileSystemTest {
- private static final String PATH = "/org/sonar/server/platform/DefaultServerFileSystemTest/";
+ private static final String PATH = "org/sonar/server/platform/DefaultServerFileSystemTest/";
@Test
- public void get_jdbc_driver() {
+ public void get_jdbc_driver() throws Exception {
Database database = mock(Database.class);
when(database.getDialect()).thenReturn(new MySql());
- File driver = new DefaultServerFileSystem(database, TestUtils.getResource(PATH + "testGetJdbcDriver"), null).getJdbcDriver();
+ File file = new File(Resources.getResource(PATH + "testGetJdbcDriver").toURI());
+ File driver = new DefaultServerFileSystem(database, file, null).getJdbcDriver();
assertThat(driver).isNotNull();
}
}
@Test(expected = IllegalStateException.class)
- public void fail_if_jdbc_driver_not_found() {
+ public void fail_if_jdbc_driver_not_found() throws Exception {
Database database = mock(Database.class);
Dialect fakeDialect = mock(Dialect.class);
when(fakeDialect.getId()).thenReturn("none");
when(database.getDialect()).thenReturn(fakeDialect);
- new DefaultServerFileSystem(database, TestUtils.getResource(PATH + "testGetJdbcDriver"), null).getJdbcDriver();
+ new DefaultServerFileSystem(database, new File(Resources.getResource(PATH + "testGetJdbcDriver").toURI()), null).getJdbcDriver();
}
@Test
- public void find_plugins() {
- List<File> plugins = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldFindPlugins"), null).getUserPlugins();
+ public void find_plugins() throws Exception {
+ List<File> plugins = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldFindPlugins").toURI()), null).getUserPlugins();
assertThat(plugins).hasSize(2);
}
@Test
- public void not_fail_if_no_plugins() {
- List<File> plugins = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldNotFailIfNoPlugins"), null).getUserPlugins();
+ public void not_fail_if_no_plugins() throws Exception {
+ List<File> plugins = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldNotFailIfNoPlugins").toURI()), null).getUserPlugins();
assertThat(plugins).isEmpty();
}
@Test
- public void find_checkstyle_extensions() {
- ServerFileSystem fs = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldFindCheckstyleExtensions"), null);
+ public void find_checkstyle_extensions() throws Exception {
+ ServerFileSystem fs = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), null);
List<File> xmls = fs.getExtensions("checkstyle", "xml");
assertThat(xmls).hasSize(1);
}
@Test
- public void not_fail_if_no_checkstyle_extensions() {
- ServerFileSystem fs = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions"), null);
+ public void not_fail_if_no_checkstyle_extensions() throws Exception {
+ ServerFileSystem fs = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), null);
List<File> xmls = fs.getExtensions("checkstyle", "xml");
assertThat(xmls).isEmpty();
*/
package org.sonar.server.plugins;
+import com.google.common.io.Resources;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.sonar.api.utils.MessageException;
import org.sonar.core.persistence.Database;
import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.test.TestUtils;
import java.io.File;
-import java.io.IOException;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
@Before
- public void before() throws IOException {
+ public void before() throws Exception {
when(server.getVersion()).thenReturn("3.1");
when(server.getDeployDir()).thenReturn(temp.newFolder("deploy"));
jarsInstaller = new ServerPluginJarsInstaller(server, upgradeStatus, fileSystem, jarInstaller);
}
- private File jar(String name) {
- return TestUtils.getResource(ServerPluginJarsInstallerTest.class, name);
+ private File jar(String name) throws Exception {
+ return new File(Resources.getResource(getClass(), "ServerPluginJarsInstallerTest/" + name).toURI());
}
@Test
}
@Test
- public void deploy_installed_plugin() throws IOException {
+ public void deploy_installed_plugin() throws Exception {
when(upgradeStatus.isFreshInstall()).thenReturn(false);
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
}
@Test
- public void ignore_non_plugin_jars() throws IOException {
+ public void ignore_non_plugin_jars() throws Exception {
when(upgradeStatus.isFreshInstall()).thenReturn(false);
FileUtils.copyFileToDirectory(jar("not-a-plugin.jar"), pluginsDir);
}
@Test
- public void fail_if_plugin_requires_greater_SQ_version() throws IOException {
+ public void fail_if_plugin_requires_greater_SQ_version() throws Exception {
exception.expect(IllegalStateException.class);
exception.expectMessage("Plugin switchoffviolations needs a more recent version of SonarQube than 2.0. At least 2.5 is expected");
}
@Test
- public void move_downloaded_plugins() throws IOException {
+ public void move_downloaded_plugins() throws Exception {
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), downloadsDir);
when(upgradeStatus.isFreshInstall()).thenReturn(false);
}
@Test
- public void downloaded_plugins_overrides_existing_plugin() throws IOException {
+ public void downloaded_plugins_overrides_existing_plugin() throws Exception {
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
FileUtils.copyFileToDirectory(jar("foo-plugin-2.0.jar"), downloadsDir);
when(upgradeStatus.isFreshInstall()).thenReturn(false);
}
@Test
- public void downloaded_plugins_overrides_existing_plugin_even_if_same_filename() throws IOException {
+ public void downloaded_plugins_overrides_existing_plugin_even_if_same_filename() throws Exception {
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir, true);
// foo-plugin-1.0.jar in extensions/downloads is in fact version 2.0. It's used to verify
// that it has correctly overridden extensions/plugins/foo-plugin-1.0.jar
}
@Test
- public void delete_trash() throws IOException {
+ public void delete_trash() throws Exception {
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), trashDir);
when(upgradeStatus.isFreshInstall()).thenReturn(false);
}
@Test
- public void fail_if_two_installed_plugins_with_same_key() throws IOException {
+ public void fail_if_two_installed_plugins_with_same_key() throws Exception {
when(upgradeStatus.isFreshInstall()).thenReturn(false);
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
FileUtils.copyFileToDirectory(jar("foo-plugin-2.0.jar"), pluginsDir);
}
@Test
- public void uninstall_plugin() throws IOException {
+ public void uninstall_plugin() throws Exception {
when(upgradeStatus.isFreshInstall()).thenReturn(false);
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
}
@Test
- public void cancel_uninstallation() throws IOException {
+ public void cancel_uninstallation() throws Exception {
when(upgradeStatus.isFreshInstall()).thenReturn(false);
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
}
@Test
- public void deploy_core_plugins() throws IOException {
+ public void deploy_core_plugins() throws Exception {
when(upgradeStatus.isFreshInstall()).thenReturn(false);
FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), coreDir);
*/
package org.sonar.server.plugins;
+import com.google.common.io.Resources;
import org.junit.After;
import org.junit.Test;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.test.TestUtils;
import java.io.File;
import java.util.Arrays;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
}
@Test
- public void testStart() {
+ public void testStart() throws Exception {
ServerPluginJarsInstaller deployer = mock(ServerPluginJarsInstaller.class);
- File pluginFile = TestUtils.getResource("/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar");
+ File pluginFile = new File(Resources.getResource("org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar").toURI());
PluginMetadata plugin = DefaultPluginMetadata.create(pluginFile)
.setKey("artifactsize")
.setMainClass("org.sonar.plugins.artifactsize.ArtifactSizePlugin")
repository = new ServerPluginRepository(deployer);
repository.start();
- assertThat(repository.getPlugin("artifactsize"), not(nullValue()));
- assertThat(repository.getClassLoader("artifactsize"), not(nullValue()));
- assertThat(repository.getClass("artifactsize", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), not(nullValue()));
- assertThat(repository.getClass("artifactsize", "org.Unknown"), nullValue());
- assertThat(repository.getClass("other", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), nullValue());
+ assertThat(repository.getPlugin("artifactsize")).isNotNull();
+ assertThat(repository.getClassLoader("artifactsize")).isNotNull();
+ assertThat(repository.getClass("artifactsize", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics")).isNotNull();
+ assertThat(repository.getClass("artifactsize", "org.Unknown")).isNull();
+ assertThat(repository.getClass("other", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics")).isNull();
}
}
package org.sonar.server.qualityprofile;
import com.github.tlrx.elasticsearch.test.EsSetup;
+import com.google.common.base.Charsets;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-import org.apache.commons.io.IOUtils;
+import com.google.common.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.sonar.server.es.ESIndex;
import org.sonar.server.es.ESNode;
import org.sonar.server.rule.RuleRegistry;
-import org.sonar.test.TestUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
-import static org.elasticsearch.index.query.FilterBuilders.*;
+import static org.elasticsearch.index.query.FilterBuilders.hasChildFilter;
+import static org.elasticsearch.index.query.FilterBuilders.hasParentFilter;
+import static org.elasticsearch.index.query.FilterBuilders.termFilter;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Test
public void should_not_fail_on_empty_delete_list() {
- esActiveRule.deleteActiveRules(ImmutableList.<Integer> of());
+ esActiveRule.deleteActiveRules(ImmutableList.<Integer>of());
}
@Test
SqlSession session = mock(SqlSession.class);
when(myBatis.openSession()).thenReturn(session);
when(activeRuleDao.selectAll(session)).thenReturn(activeRules);
- when(activeRuleDao.selectAllParams(session)).thenReturn(Lists.<ActiveRuleParamDto> newArrayList());
+ when(activeRuleDao.selectAllParams(session)).thenReturn(Lists.<ActiveRuleParamDto>newArrayList());
esActiveRule.bulkRegisterActiveRules();
assertThat(esSetup.exists("rules", "active_rule", "1"));
}
private String testFileAsString(String testFile) throws Exception {
- return IOUtils.toString(TestUtils.getResource(getClass(), testFile).toURI());
+ return Resources.toString(Resources.getResource(getClass(), "ESActiveRuleTest/" + testFile), Charsets.UTF_8);
}
}
package org.sonar.server.qualityprofile;
import com.github.tlrx.elasticsearch.test.EsSetup;
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.junit.After;
import org.sonar.server.es.ESNode;
import org.sonar.server.paging.Paging;
import org.sonar.server.rule.RuleRegistry;
-import org.sonar.test.TestUtils;
import java.util.List;
esSetup = new EsSetup(ImmutableSettings.builder()
.loadFromUrl(ESNode.class.getResource("config/elasticsearch.json"))
.build()
- );
+ );
esSetup.execute(EsSetup.deleteAll());
ESNode searchNode = mock(ESNode.class);
esSetup.client().prepareBulk()
// id = 2303, tags = empty
.add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_empty.json")))
- // active rule with parent having no tag
+ // active rule with parent having no tag
.add(Requests.indexRequest().index("rules").type("active_rule").parent("2303").source(testFileAsString("find_inactive_rules_with_tags/active_rule_empty.json")))
- // id = 2304, tags = taga
+ // id = 2304, tags = taga
.add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_a.json")))
- // id = 2305, tags = taga, tagb
+ // id = 2305, tags = taga, tagb
.add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_ab.json")))
- // id = 2306, tags = tagb, tagc
+ // id = 2306, tags = tagb, tagc
.add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_bc.json")))
- // id = 2307, tags = taga, tagc, tage
+ // id = 2307, tags = taga, tagc, tage
.add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_ace.json")))
- // active rule with parent having tags
+ // active rule with parent having tags
.add(Requests.indexRequest().index("rules").type("active_rule").parent("2307").source(testFileAsString("find_inactive_rules_with_tags/active_rule_ace.json")))
.setRefresh(true)
.execute().actionGet();
}
private String testFileAsString(String testFile) throws Exception {
- return IOUtils.toString(TestUtils.getResource(getClass(), testFile).toURI());
+ return Resources.toString(Resources.getResource(getClass(), "QProfileRuleLookupTest/" + testFile), Charsets.UTF_8);
}
}
package org.sonar.server.rule;
import com.github.tlrx.elasticsearch.test.EsSetup;
+import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
-import org.apache.commons.io.IOUtils;
+import com.google.common.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.junit.After;
import org.sonar.api.rule.Severity;
import org.sonar.core.persistence.MyBatis;
import org.sonar.core.profiling.Profiling;
-import org.sonar.core.rule.*;
+import org.sonar.core.rule.RuleDao;
+import org.sonar.core.rule.RuleDto;
+import org.sonar.core.rule.RuleParamDto;
+import org.sonar.core.rule.RuleRuleTagDto;
+import org.sonar.core.rule.RuleTagType;
import org.sonar.core.technicaldebt.db.CharacteristicDao;
import org.sonar.core.technicaldebt.db.CharacteristicDto;
import org.sonar.server.es.ESIndex;
import org.sonar.server.es.ESNode;
-import org.sonar.test.TestUtils;
import java.util.HashMap;
import java.util.List;
@Test
public void index_overridden_characteristic_if_both_default_and_overridden_characteristics_exists_when_indexing_one_rule() {
RuleDto ruleDto = new RuleDto().setId(10).setRepositoryKey("repo").setRuleKey("key1").setSeverity(Severity.MINOR)
- // default and overridden debt values are set
- .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("LINEAR").setDefaultRemediationCoefficient("2h")
- .setSubCharacteristicId(13).setRemediationFunction("LINEAR_OFFSET").setRemediationCoefficient("1h").setRemediationOffset("15min");
+ // default and overridden debt values are set
+ .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("LINEAR").setDefaultRemediationCoefficient("2h")
+ .setSubCharacteristicId(13).setRemediationFunction("LINEAR_OFFSET").setRemediationCoefficient("1h").setRemediationOffset("15min");
when(characteristicDao.selectById(12, session)).thenReturn(new CharacteristicDto().setId(12).setKey("REUSABILITY").setName("Reusability"));
when(characteristicDao.selectById(13, session)).thenReturn(new CharacteristicDto().setId(13).setKey("MODULARITY").setName("Modularity").setParentId(12));
@Test
public void index_overridden_function_if_both_default_and_overridden_functions_exists_when_indexing_one_rule() {
RuleDto ruleDto = new RuleDto().setId(10).setRepositoryKey("repo").setRuleKey("key1").setSeverity(Severity.MINOR)
- // default and overridden debt values are set
- .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("15min")
- .setSubCharacteristicId(11).setRemediationFunction("LINEAR").setRemediationCoefficient("1h");
+ // default and overridden debt values are set
+ .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("15min")
+ .setSubCharacteristicId(11).setRemediationFunction("LINEAR").setRemediationCoefficient("1h");
when(characteristicDao.selectById(10, session)).thenReturn(new CharacteristicDto().setId(10).setKey("REUSABILITY").setName("Reusability"));
when(characteristicDao.selectById(11, session)).thenReturn(new CharacteristicDto().setId(11).setKey("MODULARITY").setName("Modularity").setParentId(10));
}
private String testFileAsString(String testFile) throws Exception {
- return IOUtils.toString(TestUtils.getResource(getClass(), testFile).toURI());
+ return Resources.toString(Resources.getResource(getClass(), "RuleRegistryTest/" + testFile), Charsets.UTF_8);
}
}
import com.google.common.base.Charsets;
import com.google.common.io.Files;
+import com.google.common.io.Resources;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.test.TestUtils;
import java.io.File;
@Test
public void test_deploy() throws Exception {
DefaultServerFileSystem fs = mock(DefaultServerFileSystem.class);
- File initialDriver = TestUtils.getResource(getClass(), "deploy/my-driver.jar");
+ File initialDriver = new File(Resources.getResource(getClass(), "JdbcDriverDeployerTest/deploy/my-driver.jar").toURI());
when(fs.getJdbcDriver()).thenReturn(initialDriver);
File deployDir = temp.newFolder("deploy");
*/
package org.sonar.test;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.utils.SonarException;
import java.io.File;
-import java.io.IOException;
import java.net.URL;
/**
return null;
}
- public static String getResourceContent(String path) {
- URL url = TestUtils.class.getResource(path);
- if (url == null) {
- return null;
- }
-
- try {
- return IOUtils.toString(url, Charsets.UTF_8);
- } catch (IOException e) {
- throw new SonarException("Can not load the resource: " + path, e);
- }
- }
-
/**
* Search for a resource in the classpath. For example calling the method getResource(getClass(), "myTestName/foo.txt") from
* the class org.sonar.Foo loads the file $basedir/src/test/resources/org/sonar/Foo/myTestName/foo.txt