private ThreadLocalSettings create(Map<String, String> systemProps) { Properties p = new Properties(); p.putAll(systemProps); return new ThreadLocalSettings(new PropertyDefinitions(), p, dbSettingLoader); }
@Test public void test_categories_on_annotation_plugin() { PropertyDefinitions def = new PropertyDefinitions(Categories.class); assertThat(def.getCategory("inCateg")).isEqualTo("categ"); assertThat(def.getCategory("noCateg")).isEqualTo(""); }
@Test public void getProperties_return_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() { SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); doThrow(toBeThrown).when(settingLoaderMock).loadAll(); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); assertThat(underTest.getProperties()) .isEmpty(); }
@Test public void change_setting_loader() { underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties()); assertThat(underTest.getSettingLoader()).isNotNull(); SettingLoader newLoader = mock(SettingLoader.class); underTest.setSettingLoader(newLoader); assertThat(underTest.getSettingLoader()).isSameAs(newLoader); }
@Test public void should_inspect_plugin_classes() { PropertyDefinitions def = new PropertyDefinitions(PluginWithProperty.class, PluginWithProperties.class); assertProperties(def); }
@Before public void init_definitions() { definitions = new PropertyDefinitions(); definitions.addComponent(Init.class); }
@Test public void get_returns_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() { SettingLoader settingLoaderMock = mock(SettingLoader.class); PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB"); String key = randomAlphanumeric(3); doThrow(toBeThrown).when(settingLoaderMock).load(key); underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock); assertThat(underTest.get(key)).isEmpty(); }
@Test public void test_default_category_on_annotation_plugin() { PropertyDefinitions def = new PropertyDefinitions(); def.addComponent(Categories.class, "default"); assertThat(def.getCategory("inCateg")).isEqualTo("categ"); assertThat(def.getCategory("noCateg")).isEqualTo("default"); }
@Test public void should_rename_deprecated_keys() { PropertiesDao dao = mock(PropertiesDao.class); PropertyDefinitions definitions = new PropertyDefinitions(FakeExtension.class); RenameDeprecatedPropertyKeys task = new RenameDeprecatedPropertyKeys(dao, definitions); task.start(); verify(dao).renamePropertyKey("old_key", "new_key"); verifyNoMoreInteractions(dao); }
private List<QGChangeEvent> run(Collection<ComponentDto> components, IssueMetricFormula... formulas) { IssueMetricFormulaFactory formulaFactory = new TestIssueMetricFormulaFactory(asList(formulas)); when(qGateComputer.loadQualityGate(any(DbSession.class), any(OrganizationDto.class), any(ComponentDto.class), any(BranchDto.class))) .thenReturn(qualityGate); when(qGateComputer.getMetricsRelatedTo(qualityGate)).thenReturn(singleton(CoreMetrics.ALERT_STATUS_KEY)); when(qGateComputer.refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class))) .thenReturn(newQualityGate); MapSettings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all())); ProjectConfigurationLoader configurationLoader = new TestProjectConfigurationLoader(settings.asConfig()); LiveMeasureComputerImpl underTest = new LiveMeasureComputerImpl(db.getDbClient(), formulaFactory, qGateComputer, configurationLoader, projectIndexer); return underTest.refresh(db.getSession(), components); }
@Test public void should_return_special_categories() { PropertyDefinitions def = new PropertyDefinitions(); assertThat(def.propertiesByCategory(null).get(new Category("general")).keySet()).containsOnly(new SubCategory("email")); assertThat(def.propertiesByCategory(null).get(new Category("general")).keySet().iterator().next().isSpecial()).isTrue(); assertThat(def.propertiesByCategory(null).get(new Category("security")).keySet()).containsOnly(new SubCategory("encryption")); assertThat(def.propertiesByCategory(null).get(new Category("security")).keySet().iterator().next().isSpecial()).isTrue(); assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet()).containsOnly(new SubCategory("server_id")); assertThat(def.propertiesByCategory(null).get(new Category("licenses")).keySet().iterator().next().isSpecial()).isTrue(); }
@Before public void init() { settings = new MapSettings(new PropertyDefinitions(IssueExclusionProperties.all())); patternsInitializer = new IssueInclusionPatternInitializer(settings.asConfig()); }
@Test public void should_load_global_settings() { when(globalServerSettings.properties()).thenReturn(ImmutableMap.of("sonar.cpd.cross", "true")); GlobalConfiguration globalConfig = new GlobalConfigurationProvider().provide(globalServerSettings, scannerProps, new PropertyDefinitions()); assertThat(globalConfig.get("sonar.cpd.cross")).hasValue("true"); } }
@Test public void set_property_string_throws_NPE_if_key_is_null() { String key = randomAlphanumeric(3); Settings underTest = new MapSettings(new PropertyDefinitions(singletonList(PropertyDefinition.builder(key).multiValues(true).build()))); expectKeyNullNPE(); underTest.setProperty(null, new String[] {"1", "2"}); }
@Test public void delete_files_and_directories() { MapSettings settings = new MapSettings(new PropertyDefinitions(PurgeProperties.all())); settings.setProperty(PurgeConstants.DAYS_BEFORE_DELETING_CLOSED_ISSUES, 5); Date now = new Date(); PurgeConfiguration underTest = PurgeConfiguration.newDefaultPurgeConfiguration(settings.asConfig(), new IdUuidPair(42L, "any-uuid"), emptyList()); assertThat(underTest.getScopesWithoutHistoricalData()) .containsExactlyInAnyOrder(Scopes.DIRECTORY, Scopes.FILE); assertThat(underTest.maxLiveDateOfClosedIssues(now)).isEqualTo(DateUtils.addDays(now, -5)); } }
@Test public void validKey_throws_NPE_if_key_is_null() { PropertyDefinitions underTest = new PropertyDefinitions(); expectedException.expect(NullPointerException.class); expectedException.expectMessage("key can't be null"); underTest.validKey(null); }
@Test public void get_throws_NPE_if_key_is_null() { PropertyDefinitions underTest = new PropertyDefinitions(); expectedException.expect(NullPointerException.class); expectedException.expectMessage("key can't be null"); underTest.get(null); }
@Test public void getDefaultValues() { Configuration config = new DefaultConfiguration(new PropertyDefinitions(Arrays.asList( PropertyDefinition.builder("single").multiValues(false).defaultValue("default").build(), PropertyDefinition.builder("multiA").multiValues(true).defaultValue("foo,bar").build())), new Encryption(null), ImmutableMap.of()) { }; assertThat(config.get("multiA")).hasValue("foo,bar"); assertThat(config.getStringArray("multiA")).containsExactly("foo", "bar"); assertThat(config.get("single")).hasValue("default"); assertThat(config.getStringArray("single")).containsExactly("default"); }
@Test public void should_inspect_annotation_plugin_objects() { PropertyDefinitions def = new PropertyDefinitions(new PluginWithProperty(), new PluginWithProperties()); assertProperties(def); }
@Test public void should_inspect_plugin_objects() { PropertyDefinitions def = new PropertyDefinitions( PropertyDefinition.builder("foo").name("Foo").build(), PropertyDefinition.builder("one").name("One").build(), PropertyDefinition.builder("two").name("Two").defaultValue("2").build()); assertProperties(def); }