@Test(expected = IllegalArgumentException.class) public void sonarqube_requires_side() throws Exception { SonarRuntimeImpl.forSonarQube(A_VERSION, null); }
@Test public void sonarQube_environment() { SonarRuntime apiVersion = SonarRuntimeImpl.forSonarQube(A_VERSION, SonarQubeSide.SCANNER); assertThat(apiVersion.getApiVersion()).isEqualTo(A_VERSION); assertThat(apiVersion.getProduct()).isEqualTo(SonarProduct.SONARQUBE); assertThat(apiVersion.getSonarQubeSide()).isEqualTo(SonarQubeSide.SCANNER); }
private SensorContextTester(Path moduleBaseDir) { this.settings = new MapSettings(); this.fs = new DefaultFileSystem(moduleBaseDir).setEncoding(Charset.defaultCharset()); this.activeRules = new ActiveRulesBuilder().build(); this.sensorStorage = new InMemorySensorStorage(); this.project = new DefaultInputProject(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile())); this.module = new DefaultInputModule(ProjectDefinition.create().setKey("projectKey").setBaseDir(moduleBaseDir.toFile()).setWorkDir(moduleBaseDir.resolve(".sonar").toFile())); this.runtime = SonarRuntimeImpl.forSonarQube(ApiVersion.load(System2.INSTANCE), SonarQubeSide.SCANNER); }
@Test public void load_from_database_if_server_is_startup_follower() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); when(webServer.isStartupLeader()).thenReturn(false); testLoadingFromDatabase(runtime, false); }
@Test public void load_from_database_if_compute_engine_of_startup_follower_server() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); testLoadingFromDatabase(runtime, false); }
@Test public void generate_SERVER_STARTIME_but_do_not_persist_it_if_server_is_startup_leader() { when(system.now()).thenReturn(A_DATE); SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); when(webServer.isStartupLeader()).thenReturn(true); StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(metadata.getStartedAt()).isEqualTo(A_DATE); assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME); // keep a cache StartupMetadata secondMetadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(secondMetadata).isSameAs(metadata); }
private void test(SonarQubeSide side) { underTest = new ServerIdManager(serverIdChecksum, serverIdFactory, dbClient, SonarRuntimeImpl.forSonarQube(Version.create(6, 7), side), webServer); underTest.start(); } }
@Test public void load_from_database_if_compute_engine_of_startup_leader_server() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); testLoadingFromDatabase(runtime, true); }
@Test public void shouldLoadServerProperties() { Settings settings = new MapSettings(); settings.setProperty(CoreProperties.SERVER_ID, "123"); settings.setProperty(CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"); ScannerWsClient client = mock(ScannerWsClient.class); when(client.baseUrl()).thenReturn("http://foo.com"); DefaultServer metadata = new DefaultServer(((MapSettings) settings).asConfig(), client, SonarRuntimeImpl.forSonarQube(Version.parse("2.2"), SonarQubeSide.SCANNER)); assertThat(metadata.getId()).isEqualTo("123"); assertThat(metadata.getVersion()).isEqualTo("2.2"); assertThat(metadata.getStartedAt()).isNotNull(); assertThat(metadata.getURL()).isEqualTo("http://foo.com"); assertThat(metadata.getPermanentServerId()).isEqualTo("123"); assertThat(metadata.getRootDir()).isNull(); assertThat(metadata.getContextPath()).isNull(); assertThat(metadata.isDev()).isFalse(); assertThat(metadata.isSecured()).isFalse(); }
@Test public void fail_to_load_from_database_if_properties_are_not_persisted() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.COMPUTE_ENGINE); when(webServer.isStartupLeader()).thenReturn(false); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Property sonar.core.startTime is missing in database"); underTest.provide(system, runtime, webServer, dbTester.getDbClient()); }
@Test public void provide_extensions_for_7_2() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.2"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(55) .contains(OneExternalIssuePerLineSensor.class); }
@Before public void prepare() throws Exception { activeRules = new ActiveRulesBuilder().build(); fs = new DefaultFileSystem(temp.newFolder().toPath()); MetricFinder metricFinder = mock(MetricFinder.class); when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC); when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION); settings = new MapSettings(); sensorStorage = mock(SensorStorage.class); analysisMode = mock(AnalysisMode.class); runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER); hierarchy = new DefaultInputModuleHierarchy(new DefaultInputModule(ProjectDefinition.create() .setWorkDir(temp.newFolder()) .setBaseDir(temp.newFolder()).setKey("foo"))); adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, analysisMode, sensorStorage, runtime); }
@Test public void provide_extensions_for_6_6() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.6"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(51) .contains(XooBuiltInQualityProfilesDefinition.class); }
@Test public void provide_extensions_for_7_3() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.3"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(56) .contains(OneExternalIssuePerLineSensor.class); }
@Before public void setUp() { XooRulesDefinition def = new XooRulesDefinition(SonarRuntimeImpl.forSonarQube(Version.create(7, 3), SonarQubeSide.SCANNER)); context = new RulesDefinition.Context(); def.define(context); }
@Test public void provide_extensions_for_7_6() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("7.6"), SonarQubeSide.SCANNER); Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build(); new XooPlugin().define(context); assertThat(getExtensions(context)) .hasSize(58) .contains(GlobalProjectSensor.class) .contains(XooIgnoreCommand.class); }
@Test public void test_context() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(VERSION_5_6, SonarQubeSide.SERVER); MapSettings settings = new MapSettings().setProperty("foo", "bar"); Plugin.Context context = new PluginContextImpl.Builder() .setSonarRuntime(runtime) .setBootConfiguration(settings.asConfig()) .build(); assertThat(context.getSonarQubeVersion()).isEqualTo(VERSION_5_6); assertThat(context.getExtensions()).isEmpty(); context.addExtension("foo"); assertThat(context.getExtensions()).containsOnly("foo"); context.addExtensions(Arrays.asList("bar", "baz")); assertThat(context.getExtensions()).containsOnly("foo", "bar", "baz"); context.addExtensions("one", "two", "three", "four"); assertThat(context.getExtensions()).containsOnly("foo", "bar", "baz", "one", "two", "three", "four"); assertThat(context.getBootConfiguration().get("foo")).hasValue("bar"); } }
private WebhookCaller newSender() { SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.parse("6.2"), SonarQubeSide.SERVER); return new WebhookCallerImpl(system, new OkHttpClientProvider().provide(new MapSettings().asConfig(), runtime)); } }
private void addBootstrapComponents() { Version apiVersion = ApiVersion.load(System2.INSTANCE); add( // plugins ScannerPluginRepository.class, PluginLoader.class, PluginClassloaderFactory.class, ScannerPluginJarExploder.class, ScannerPluginPredicate.class, ExtensionInstaller.class, new SonarQubeVersion(apiVersion), SonarRuntimeImpl.forSonarQube(apiVersion, SonarQubeSide.SCANNER), StoragesManager.class, new GlobalServerSettingsProvider(), new GlobalConfigurationProvider(), new ScannerWsClientProvider(), DefaultServer.class, new GlobalTempFolderProvider(), DefaultHttpDownloader.class, UriReader.class, PluginFiles.class, System2.INSTANCE, Clock.systemDefaultZone(), new MetricsRepositoryProvider(), UuidFactoryImpl.INSTANCE); addIfMissing(ScannerPluginInstaller.class, PluginInstaller.class); add(CoreExtensionRepositoryImpl.class, CoreExtensionsLoader.class, ScannerCoreExtensionsInstaller.class); addIfMissing(DefaultSettingsLoader.class, SettingsLoader.class); addIfMissing(DefaultMetricsRepositoryLoader.class, MetricsRepositoryLoader.class); }
@Test public void testProvideGap_before_5_5() throws IOException { DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.xoo") .setLanguage(Xoo.KEY) .initMetadata("a\nb\nc\nd\ne\nf\ng\nh\ni\n") .build(); SensorContextTester context = SensorContextTester.create(temp.newFolder()); context.fileSystem().add(inputFile); context.settings().setProperty(OneIssuePerLineSensor.EFFORT_TO_FIX_PROPERTY, "1.2"); context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.parse("5.4"), SonarQubeSide.SCANNER)); sensor.execute(context); assertThat(context.allIssues()).hasSize(10); // One issue per line for (Issue issue : context.allIssues()) { assertThat(issue.gap()).isEqualTo(1.2d); } }