@Before public void setUp() throws Exception { artifactDest = temporaryFolder.newFolder("fetch_dest"); checksums = mock(ArtifactMd5Checksums.class); goPublisher = new StubGoPublisher(); zip = temporaryFolder.newFile("zip_location"); agentDest = temporaryFolder.newFolder("agent_fetch_dest"); dirHandler = new DirHandler("fetch_dest",agentDest); }
@BeforeClass public static void beforeClass() throws IOException { temporaryFolder = new TemporaryFolder(); temporaryFolder.create(); }
@Before public void setUp() throws Exception { folderToSaveDowloadFiles = temporaryFolder.newFolder(); httpClientFactory = mock(HttpService.HttpClientFactory.class); httpClient = mock(GoAgentServerHttpClient.class); when(httpClientFactory.httpClient()).thenReturn(httpClient); service = new HttpService(httpClientFactory); }
@Test public void load_properties_from_file() throws Exception { File propsFile = temp.newFile(); FileUtils.write(propsFile, "sonar.foo=bar\nprocess.key=web\nprocess.index=1\nprocess.sharedDir=" + temp.newFolder().getAbsolutePath().replaceAll("\\\\", "/")); ProcessEntryPoint entryPoint = ProcessEntryPoint.createForArguments(new String[] {propsFile.getAbsolutePath()}); assertThat(entryPoint.getProps().value("sonar.foo")).isEqualTo("bar"); assertThat(entryPoint.getProps().value("process.key")).isEqualTo("web"); }
@Test public void write_project_basedir() throws Exception { String path = "some/dir"; Path relativePathFromScmRoot = Paths.get(path); when(scmProvider.relativePathFromScmRoot(any(Path.class))).thenReturn(relativePathFromScmRoot); File outputDir = temp.newFolder(); underTest.publish(new ScannerReportWriter(outputDir)); ScannerReportReader reader = new ScannerReportReader(outputDir); ScannerReport.Metadata metadata = reader.readMetadata(); assertThat(metadata.getRelativePathFromScmRoot()).isEqualTo(path); }
@Before public void setUp() throws IOException { root = new DefaultInputModule(ProjectDefinition.create().setKey("org.sonarsource.sonarqube:sonarqube").setBaseDir(temp.newFolder()).setWorkDir(temp.getRoot())); when(moduleHierarchy.root()).thenReturn(root); when(server.getPublicRootUrl()).thenReturn("https://localhost"); when(server.getVersion()).thenReturn("6.4"); when(properties.metadataFilePath()).thenReturn(temp.newFolder().toPath() .resolve("folder") .resolve("report-task.txt")); }
@Before public void setUp() throws IOException { temporaryFolder.create(); subversion = mock(Subversion.class); when(subversion.getUrl()).thenReturn(new UrlArgument(URL)); when(subversion.getPassword()).thenReturn(""); when(subversion.getUserName()).thenReturn(""); when(subversion.isCheckExternals()).thenReturn(false); svnMaterial = SvnMaterial.createSvnMaterialWithMock(subversion); svnMaterial.setUrl(URL); }
@Test public void create_temp_dir_if_missing() throws Exception { ServerFileSystem fs = mock(ServerFileSystem.class); File tmpDir = temp.newFolder(); when(fs.getTempDir()).thenReturn(tmpDir); FileUtils.forceDelete(tmpDir); TempFolder folder = underTest.provide(fs); assertThat(folder).isNotNull(); File newDir = folder.newDir(); assertThat(newDir).exists().isDirectory(); assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath()); } }
@Before public void prepare_fs() throws IOException { File homeDir = temp.newFolder(); when(fs.getHomeDir()).thenReturn(homeDir); File batchDir = new File(homeDir, "lib/scanner"); FileUtils.forceMkdir(batchDir); jar = new File(batchDir, "sonar-batch.jar"); FileUtils.writeStringToFile(new File(batchDir, "sonar-batch.jar"), "foo"); }
@Before public void setUp() throws Exception { initMocks(this); bundleDir = temporaryFolder.newFolder("bundleDir"); pluginExternalDir = temporaryFolder.newFolder("externalDir"); newJarFile = temporaryFolder.newFile("jar-file.jar"); nonJarFile = temporaryFolder.newFile("some-picture.jpg"); when(systemEnvironment.get(PLUGIN_BUNDLE_PATH)).thenReturn(bundleDir.getAbsolutePath()); when(systemEnvironment.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(pluginExternalDir.getAbsolutePath()); }
@Before public void setUp() throws IOException { sourceFolder = temp.newFolder("source").toPath(); targetFolder = temp.newFolder("target").toPath(); targetJarPath = targetFolder.resolve("test.jar"); Files.createFile(targetJarPath); }
@Before public void setUp() throws Exception { super.setUp(); temporaryFolder.create(); initMocks(this); bundledPluginDir = temporaryFolder.newFolder("bundled-plugins"); pluginExternalDir = temporaryFolder.newFolder("external-plugins"); when(systemEnvironment.get(PLUGIN_LOCATION_MONITOR_INTERVAL_IN_SECONDS)).thenReturn(1); when(systemEnvironment.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(bundledPluginDir.getAbsolutePath()); when(systemEnvironment.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(pluginExternalDir.getAbsolutePath()); monitor = new DefaultPluginJarLocationMonitor(systemEnvironment); monitor.initialize(); }
@Test public void deleteDirectory_throws_IOE_if_file_is_symbolicLink() throws IOException { assumeTrue(SystemUtils.IS_OS_UNIX); Path folder = temporaryFolder.newFolder().toPath(); Path file1 = Files.createFile(folder.resolve("file1.txt")); Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1); assertThat(file1).isRegularFile(); assertThat(symLink).isSymbolicLink(); expectedException.expect(IOException.class); expectedException.expectMessage("Directory '" + symLink.toFile().getAbsolutePath() + "' is a symbolic link"); FileUtils2.deleteDirectory(symLink.toFile()); }
@Before public void prepare() throws IOException { baseDir = temp.newFolder(); Path filepath = baseDir.toPath().resolve(FILE_PATH); Files.write(filepath, FILE_CONTENT.getBytes()); String md5sum = new FileMetadata() .readMetadata(Files.newInputStream(filepath), StandardCharsets.UTF_8, FILE_PATH) .hash(); tester.addFileData(FILE_PATH, new FileData(md5sum, "1.1")); }
@Test public void should_not_delete_report_if_property_is_set() throws IOException { when(properties.shouldKeepReport()).thenReturn(true); Path reportDir = temp.getRoot().toPath().resolve("scanner-report"); Files.createDirectory(reportDir); underTest.start(); underTest.stop(); assertThat(reportDir).isDirectory(); }