Search in sources :

Example 1 with ServerFileSystem

use of org.sonar.server.platform.ServerFileSystem in project sonarqube by SonarSource.

the class PluginDownloaderTest method before.

@Before
public void before() throws Exception {
    updateCenterMatrixFactory = mock(UpdateCenterMatrixFactory.class);
    updateCenter = mock(UpdateCenter.class);
    when(updateCenterMatrixFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter));
    httpDownloader = mock(HttpDownloader.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock inv) throws Throwable {
            File toFile = (File) inv.getArguments()[1];
            touch(toFile);
            return null;
        }
    }).when(httpDownloader).download(any(URI.class), any(File.class));
    ServerFileSystem fs = mock(ServerFileSystem.class);
    downloadDir = testFolder.newFolder("downloads");
    when(fs.getDownloadedPluginsDir()).thenReturn(downloadDir);
    pluginDownloader = new PluginDownloader(updateCenterMatrixFactory, httpDownloader, fs);
}
Also used : ServerFileSystem(org.sonar.server.platform.ServerFileSystem) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) UpdateCenter(org.sonar.updatecenter.common.UpdateCenter) HttpDownloader(org.sonar.api.utils.HttpDownloader) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) URI(java.net.URI) Before(org.junit.Before)

Example 2 with ServerFileSystem

use of org.sonar.server.platform.ServerFileSystem in project sonarqube by SonarSource.

the class PluginDownloaderTest method throw_exception_if_download_dir_is_invalid.

@Test
public void throw_exception_if_download_dir_is_invalid() throws Exception {
    ServerFileSystem fs = mock(ServerFileSystem.class);
    // download dir is a file instead of being a directory
    File downloadDir = testFolder.newFile();
    when(fs.getDownloadedPluginsDir()).thenReturn(downloadDir);
    pluginDownloader = new PluginDownloader(updateCenterMatrixFactory, httpDownloader, fs);
    try {
        pluginDownloader.start();
        fail();
    } catch (IllegalStateException e) {
    // ok
    }
}
Also used : ServerFileSystem(org.sonar.server.platform.ServerFileSystem) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)2 ServerFileSystem (org.sonar.server.platform.ServerFileSystem)2 URI (java.net.URI)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 HttpDownloader (org.sonar.api.utils.HttpDownloader)1 UpdateCenter (org.sonar.updatecenter.common.UpdateCenter)1