Search in sources :

Example 6 with TempDir

use of org.junit.jupiter.api.io.TempDir in project sonarlint-core by SonarSource.

the class ConnectedIssueExclusionsMediumTests method prepare.

@BeforeAll
static void prepare(@TempDir Path slHome) throws Exception {
    var storage = newStorage(SERVER_ID).withJavaPlugin().withProject("test-project").withProject(JAVA_MODULE_KEY, project -> project.withRuleSet("java", ruleSet -> ruleSet.withActiveRule("java:S106", "MAJOR").withActiveRule("java:S1220", "MINOR").withActiveRule("java:S1481", "BLOCKER"))).create(slHome);
    projectStorage = storage.getProjectStorages().get(1);
    var config = ConnectedGlobalConfiguration.builder().setConnectionId(SERVER_ID).setSonarLintUserHome(slHome).setStorageRoot(storage.getPath()).setLogOutput(createNoOpLogOutput()).addEnabledLanguage(Language.JAVA).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Language(org.sonarsource.sonarlint.core.commons.Language) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) TestUtils(testutils.TestUtils) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) StorageFixture.newStorage(org.sonarsource.sonarlint.core.mediumtest.fixtures.StorageFixture.newStorage) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) ProjectStorageFixture(org.sonarsource.sonarlint.core.mediumtest.fixtures.ProjectStorageFixture) Path(java.nio.file.Path) TestUtils.createNoOpLogOutput(testutils.TestUtils.createNoOpLogOutput) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) List(java.util.List) TempDir(org.junit.jupiter.api.io.TempDir) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with TempDir

use of org.junit.jupiter.api.io.TempDir in project janusgraph by JanusGraph.

the class BerkeleyTransactionTest method longRunningTxShouldBeRolledBack.

@Test
void longRunningTxShouldBeRolledBack(@TempDir File dir) throws InterruptedException {
    JanusGraph graph = JanusGraphFactory.open("berkeleyje:" + dir.getAbsolutePath());
    GraphTraversalSource traversal = graph.traversal();
    for (int i = 0; i < 10; i++) {
        traversal.addV().property("a", "2").next();
    }
    traversal.tx().commit();
    GraphTraversalSource g = graph.tx().createThreadedTx().traversal();
    CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
        g.V().has("a", "2").sideEffect(ignored -> {
            try {
                // artificially slow down the traversal execution so that
                // this test has a chance to interrupt it before it finishes
                Thread.sleep(100);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }).toList();
    });
    Thread.sleep(100);
    g.tx().rollback();
    graph.close();
    assertThrows(ExecutionException.class, future::get);
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) JanusGraphFactory(org.janusgraph.core.JanusGraphFactory) TempDir(org.junit.jupiter.api.io.TempDir) CompletableFuture(java.util.concurrent.CompletableFuture) CursorImpl(com.sleepycat.je.dbi.CursorImpl) JanusGraph(org.janusgraph.core.JanusGraph) GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) File(java.io.File) JanusGraph(org.janusgraph.core.JanusGraph) Test(org.junit.jupiter.api.Test)

Example 8 with TempDir

use of org.junit.jupiter.api.io.TempDir in project sonarlint-core by SonarSource.

the class ConnectedStorageProblemsMediumTests method corrupted_plugin_should_not_prevent_startup.

@Test
void corrupted_plugin_should_not_prevent_startup(@TempDir Path slHome, @TempDir Path baseDir) throws Exception {
    var storageId = "localhost";
    var storage = newStorage(storageId).withJSPlugin().withJavaPlugin().create(slHome);
    var cachedJSPlugin = storage.getPluginPaths().get(0);
    FileUtils.write(cachedJSPlugin.toFile(), "corrupted jar", StandardCharsets.UTF_8);
    List<String> logs = new CopyOnWriteArrayList<>();
    var config = ConnectedGlobalConfiguration.builder().setConnectionId(storageId).setSonarLintUserHome(slHome).setStorageRoot(storage.getPath()).setLogOutput((m, l) -> logs.add(m)).addEnabledLanguage(Language.JAVA).addEnabledLanguage(Language.JS).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    assertThat(logs).contains("Unable to load plugin " + cachedJSPlugin);
    var inputFile = prepareJavaInputFile(baseDir);
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(ConnectedAnalysisConfiguration.builder().setProjectKey(null).setBaseDir(baseDir).addInputFile(inputFile).build(), issues::add, null, null);
    assertThat(logs).contains("Execute Sensor: JavaSquidSensor");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Language(org.sonarsource.sonarlint.core.commons.Language) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) TestUtils(testutils.TestUtils) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StorageFixture.newStorage(org.sonarsource.sonarlint.core.mediumtest.fixtures.StorageFixture.newStorage) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TempDir(org.junit.jupiter.api.io.TempDir) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) Path(java.nio.file.Path) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.jupiter.api.Test)

Example 9 with TempDir

use of org.junit.jupiter.api.io.TempDir in project sonarlint-core by SonarSource.

the class ConnectedStorageProblemsMediumTests method test_stale_storage.

@Test
void test_stale_storage(@TempDir Path slHome, @TempDir Path baseDir) {
    var storageId = "localhost";
    newStorage(storageId).stale().create(slHome);
    var config = ConnectedGlobalConfiguration.builder().setConnectionId(storageId).setSonarLintUserHome(slHome).setLogOutput((msg, level) -> {
    }).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
    assertThat(sonarlint.getGlobalStorageStatus().isStale()).isTrue();
    assertThat(sonarlint.getProjectStorageStatus("foo")).isNull();
    assertThat(sonarlint.allProjectsByKey()).isEmpty();
    var thrown = assertThrows(IllegalStateException.class, () -> sonarlint.getActiveRuleDetails(null, null, "rule", null));
    assertThat(thrown).hasMessage("Unable to find rule details for 'rule'");
    var analysisConfig = ConnectedAnalysisConfiguration.builder().setBaseDir(baseDir).build();
    var thrown2 = assertThrows(StorageException.class, () -> sonarlint.analyze(analysisConfig, i -> {
    }, null, null));
    assertThat(thrown2).hasMessage("Outdated storage for connection");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Language(org.sonarsource.sonarlint.core.commons.Language) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) TestUtils(testutils.TestUtils) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StorageFixture.newStorage(org.sonarsource.sonarlint.core.mediumtest.fixtures.StorageFixture.newStorage) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TempDir(org.junit.jupiter.api.io.TempDir) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) Path(java.nio.file.Path) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Test(org.junit.jupiter.api.Test)

Example 10 with TempDir

use of org.junit.jupiter.api.io.TempDir in project sonarlint-core by SonarSource.

the class ConnectedIssueMediumTests method prepare.

@BeforeAll
static void prepare(@TempDir Path slHome) throws Exception {
    var storage = newStorage(SERVER_ID).withJSPlugin().withJavaPlugin().withProject("test-project").withProject(JAVA_MODULE_KEY, project -> project.withRuleSet("java", ruleSet -> ruleSet.withActiveRule("java:S106", "MAJOR").withActiveRule("java:S1220", "MINOR").withActiveRule("java:S1481", "BLOCKER"))).withProject("stale_module", ProjectStorageFixture.ProjectStorageBuilder::stale).create(slHome);
    var nodeJsHelper = new NodeJsHelper();
    nodeJsHelper.detect(null);
    var config = ConnectedGlobalConfiguration.builder().setConnectionId(SERVER_ID).setSonarLintUserHome(slHome).setStorageRoot(storage.getPath()).setLogOutput(createNoOpLogOutput()).addEnabledLanguages(Language.JAVA, Language.JS).setNodeJs(nodeJsHelper.getNodeJsPath(), nodeJsHelper.getNodeJsVersion()).setModulesProvider(() -> List.of(new ClientModuleInfo("key", mock(ClientModuleFileSystem.class)))).build();
    sonarlint = new ConnectedSonarLintEngineImpl(config);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) MockWebServerExtensionWithProtobuf(org.sonarsource.sonarlint.core.MockWebServerExtensionWithProtobuf) Language(org.sonarsource.sonarlint.core.commons.Language) ConnectedAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedAnalysisConfiguration) TestUtils(testutils.TestUtils) StringUtils(org.apache.commons.lang3.StringUtils) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) StorageFixture.newStorage(org.sonarsource.sonarlint.core.mediumtest.fixtures.StorageFixture.newStorage) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) SonarLintModuleFileSystem(org.sonarsource.sonarlint.core.analysis.sonarapi.SonarLintModuleFileSystem) Rules(org.sonarqube.ws.Rules) IssueListener(org.sonarsource.sonarlint.core.client.api.common.analysis.IssueListener) ModuleFileListener(org.sonarsource.sonarlint.plugin.api.module.file.ModuleFileListener) BeforeAll(org.junit.jupiter.api.BeforeAll) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) ProjectStorageFixture(org.sonarsource.sonarlint.core.mediumtest.fixtures.ProjectStorageFixture) TestUtils.createNoOpIssueListener(testutils.TestUtils.createNoOpIssueListener) Path(java.nio.file.Path) ClientModuleFileSystem(org.sonarsource.sonarlint.core.analysis.api.ClientModuleFileSystem) MockWebServerExtension.httpClient(org.sonarsource.sonarlint.core.commons.testutils.MockWebServerExtension.httpClient) TestUtils.createNoOpLogOutput(testutils.TestUtils.createNoOpLogOutput) ClientFileSystemFixtures.anEmptyClientFileSystem(org.sonarsource.sonarlint.core.client.api.common.ClientFileSystemFixtures.anEmptyClientFileSystem) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) StorageException(org.sonarsource.sonarlint.core.client.api.exceptions.StorageException) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) ClientFileSystemFixtures.aClientFileSystemWith(org.sonarsource.sonarlint.core.client.api.common.ClientFileSystemFixtures.aClientFileSystemWith) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ClientModuleFileEvent(org.sonarsource.sonarlint.core.analysis.api.ClientModuleFileEvent) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) ModuleFileEvent(org.sonarsource.sonarlint.plugin.api.module.file.ModuleFileEvent) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) SonarLintSide(org.sonarsource.api.sonarlint.SonarLintSide) Paths(java.nio.file.Paths) TempDir(org.junit.jupiter.api.io.TempDir) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ComponentContainer(org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer) NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) Mockito.mock(org.mockito.Mockito.mock) NodeJsHelper(org.sonarsource.sonarlint.core.NodeJsHelper) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) ProjectStorageFixture(org.sonarsource.sonarlint.core.mediumtest.fixtures.ProjectStorageFixture) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Test (org.junit.jupiter.api.Test)15 TempDir (org.junit.jupiter.api.io.TempDir)15 File (java.io.File)10 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Path (java.nio.file.Path)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 StandardCharsets (java.nio.charset.StandardCharsets)6 FileUtils (org.apache.commons.io.FileUtils)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Configuration (org.apache.hadoop.conf.Configuration)4 FileSystem (org.apache.hadoop.fs.FileSystem)4 Path (org.apache.hadoop.fs.Path)4 CompressionCodecName (org.apache.parquet.hadoop.metadata.CompressionCodecName)4 AfterEach (org.junit.jupiter.api.AfterEach)4 ConnectedSonarLintEngineImpl (org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl)4