@Test public void createEmptyProfile() { Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> { c.createBuiltInQualityProfile("Foo", "xoo").done(); }); assertThat(profiles).containsOnlyKeys("xoo"); assertThat(profiles.get("xoo")).containsOnlyKeys("Foo"); BuiltInQualityProfile profile = profiles.get("xoo").get("Foo"); assertThat(profile.name()).isEqualTo("Foo"); assertThat(profile.language()).isEqualTo("xoo"); assertThat(profile.isDefault()).isFalse(); }
@Test public void classloader_exposes_license_api_from_main_classloader() { PluginClassLoaderDef def = basePluginDef(); Map<PluginClassLoaderDef, ClassLoader> map = factory.create(asList(def)); assertThat(map).containsOnlyKeys(def); ClassLoader classLoader = map.get(def); assertThat(canLoadClass(classLoader, FooBar.class.getCanonicalName())).isTrue(); }
@Test public void constructorWhenAuthoritiesIdTokenProvidedThenCreated() { DefaultOidcUser user = new DefaultOidcUser(AUTHORITIES, ID_TOKEN); assertThat(user.getClaims()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB); assertThat(user.getIdToken()).isEqualTo(ID_TOKEN); assertThat(user.getName()).isEqualTo(SUBJECT); assertThat(user.getAuthorities()).hasSize(1); assertThat(user.getAuthorities().iterator().next()).isEqualTo(AUTHORITY); assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB); }
@Test public void constructorWhenAuthoritiesIdTokenNameAttributeKeyProvidedThenCreated() { DefaultOidcUser user = new DefaultOidcUser(AUTHORITIES, ID_TOKEN, IdTokenClaimNames.SUB); assertThat(user.getClaims()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB); assertThat(user.getIdToken()).isEqualTo(ID_TOKEN); assertThat(user.getName()).isEqualTo(SUBJECT); assertThat(user.getAuthorities()).hasSize(1); assertThat(user.getAuthorities().iterator().next()).isEqualTo(AUTHORITY); assertThat(user.getAttributes()).containsOnlyKeys(IdTokenClaimNames.ISS, IdTokenClaimNames.SUB); }
@Test public void constructorWhenAuthoritiesIdTokenUserInfoProvidedThenCreated() { DefaultOidcUser user = new DefaultOidcUser(AUTHORITIES, ID_TOKEN, USER_INFO); assertThat(user.getClaims()).containsOnlyKeys( IdTokenClaimNames.ISS, IdTokenClaimNames.SUB, StandardClaimNames.NAME, StandardClaimNames.EMAIL); assertThat(user.getIdToken()).isEqualTo(ID_TOKEN); assertThat(user.getUserInfo()).isEqualTo(USER_INFO); assertThat(user.getName()).isEqualTo(SUBJECT); assertThat(user.getAuthorities()).hasSize(1); assertThat(user.getAuthorities().iterator().next()).isEqualTo(AUTHORITY); assertThat(user.getAttributes()).containsOnlyKeys( IdTokenClaimNames.ISS, IdTokenClaimNames.SUB, StandardClaimNames.NAME, StandardClaimNames.EMAIL); }
@Test public void constructorWhenAllParametersProvidedAndValidThenCreated() { OidcUserAuthority userAuthority = new OidcUserAuthority(AUTHORITY, ID_TOKEN, USER_INFO); assertThat(userAuthority.getIdToken()).isEqualTo(ID_TOKEN); assertThat(userAuthority.getUserInfo()).isEqualTo(USER_INFO); assertThat(userAuthority.getAuthority()).isEqualTo(AUTHORITY); assertThat(userAuthority.getAttributes()).containsOnlyKeys( IdTokenClaimNames.ISS, IdTokenClaimNames.SUB, StandardClaimNames.NAME, StandardClaimNames.EMAIL); } }
@Test public void constructorWhenAllParametersProvidedAndValidThenCreated() { DefaultOAuth2User user = new DefaultOAuth2User(AUTHORITIES, ATTRIBUTES, ATTRIBUTE_NAME_KEY); assertThat(user.getName()).isEqualTo(USERNAME); assertThat(user.getAuthorities()).hasSize(1); assertThat(user.getAuthorities().iterator().next()).isEqualTo(AUTHORITY); assertThat(user.getAttributes()).containsOnlyKeys(ATTRIBUTE_NAME_KEY); }
@Test public void uninstall() throws Exception { File installedJar = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); File uninstallDir = temp.newFolder("uninstallDir"); underTest.start(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); underTest.uninstall("testbase", uninstallDir); assertThat(installedJar).doesNotExist(); // still up. Will be dropped after next startup assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); assertThat(uninstallDir.list()).containsOnly(installedJar.getName()); }
@Test public void install_downloaded_plugins_on_startup() throws Exception { File downloadedJar = copyTestPluginTo("test-base-plugin", fs.getDownloadedPluginsDir()); underTest.start(); // plugin is moved to extensions/plugins then loaded assertThat(downloadedJar).doesNotExist(); assertThat(new File(fs.getInstalledPluginsDir(), downloadedJar.getName())).isFile().exists(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); }
@Test public void downloaded_file_overrides_existing_installed_file_on_startup() throws Exception { File installedV1 = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); File downloadedV2 = copyTestPluginTo("test-base-plugin-v2", fs.getDownloadedPluginsDir()); underTest.start(); // plugin is moved to extensions/plugins and replaces v1 assertThat(downloadedV2).doesNotExist(); assertThat(installedV1).doesNotExist(); assertThat(new File(fs.getInstalledPluginsDir(), downloadedV2.getName())).exists(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); assertThat(underTest.getPluginInfo("testbase").getVersion()).isEqualTo(Version.create("0.2-SNAPSHOT")); }
@Test public void standard_startup_loads_installed_plugins() throws Exception { copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); underTest.start(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); }
@Test public void compare_disjoint() { qProfileRules.activateAndCommit(dbSession, left, singleton(RuleActivation.create(xooRule1.getId()))); qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule2.getId()))); QProfileComparisonResult result = comparison.compare(dbSession, left, right); assertThat(result.left().getKee()).isEqualTo(left.getKee()); assertThat(result.right().getKee()).isEqualTo(right.getKee()); assertThat(result.same()).isEmpty(); assertThat(result.inLeft()).isNotEmpty().containsOnlyKeys(xooRule1.getKey()); assertThat(result.inRight()).isNotEmpty().containsOnlyKeys(xooRule2.getKey()); assertThat(result.modified()).isEmpty(); assertThat(result.collectRuleKeys()).containsOnly(xooRule1.getKey(), xooRule2.getKey()); }
@Test public void compare_only_right() { qProfileRules.activateAndCommit(dbSession, right, singleton(RuleActivation.create(xooRule1.getId()))); QProfileComparisonResult result = comparison.compare(dbSession, left, right); assertThat(result.left().getKee()).isEqualTo(left.getKee()); assertThat(result.right().getKee()).isEqualTo(right.getKee()); assertThat(result.same()).isEmpty(); assertThat(result.inLeft()).isEmpty(); assertThat(result.inRight()).isNotEmpty().containsOnlyKeys(xooRule1.getKey()); assertThat(result.modified()).isEmpty(); assertThat(result.collectRuleKeys()).containsOnly(xooRule1.getKey()); }
@Test public void compare_only_left() { RuleActivation activation = RuleActivation.create(xooRule1.getId()); qProfileRules.activateAndCommit(dbSession, left, singleton(activation)); QProfileComparisonResult result = comparison.compare(dbSession, left, right); assertThat(result.left().getKee()).isEqualTo(left.getKee()); assertThat(result.right().getKee()).isEqualTo(right.getKee()); assertThat(result.same()).isEmpty(); assertThat(result.inLeft()).isNotEmpty().containsOnlyKeys(xooRule1.getKey()); assertThat(result.inRight()).isEmpty(); assertThat(result.modified()).isEmpty(); assertThat(result.collectRuleKeys()).containsOnly(xooRule1.getKey()); }
@Test public void test_plugin_requirements_at_startup() throws Exception { copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); copyTestPluginTo("test-require-plugin", fs.getInstalledPluginsDir()); underTest.start(); // both plugins are installed assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase", "testrequire"); }
@Test public void plugin_is_ignored_if_required_plugin_is_too_old_at_startup() throws Exception { copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); copyTestPluginTo("test-requirenew-plugin", fs.getInstalledPluginsDir()); underTest.start(); // the plugin "requirenew" is not installed as it requires base 0.2+ to be installed. assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); }
@Test public void install_plugin_and_its_extension_plugins_at_startup() throws Exception { copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); copyTestPluginTo("test-extend-plugin", fs.getInstalledPluginsDir()); underTest.start(); // both plugins are installed assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase", "testextend"); }
@Test public void facet_tags_returns_more_than_10_tags_when_tags_filter_contains_value_not_in_top_10() { index( newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")), newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")), newDoc().setTags(newArrayList("solo", "solo2"))); Map<String, Long> result = underTest.search(new ProjectMeasuresQuery().setTags(ImmutableSet.of("solo", "solo2")), new SearchOptions().addFacets(FIELD_TAGS)).getFacets() .get(FIELD_TAGS); assertThat(result).hasSize(12).containsOnlyKeys("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10", "solo", "solo2"); }
@Test public void facet_tags_returns_10_elements_by_default() { index( newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")), newDoc().setTags(newArrayList("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10")), newDoc().setTags(newArrayList("solo"))); Map<String, Long> result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(FIELD_TAGS)).getFacets().get(FIELD_TAGS); assertThat(result).hasSize(10).containsOnlyKeys("finance1", "finance2", "finance3", "finance4", "finance5", "finance6", "finance7", "finance8", "finance9", "finance10"); }
@Test public void non_main_branches_are_not_indexed() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc")); dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d)); ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("feature/foo")); dbTester.measures().insertLiveMeasure(branch, metric, m -> m.setValue(20d)); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById).hasSize(1).containsOnlyKeys(project.uuid()); assertThat(docsById.get(project.uuid()).getMeasures().getNumericMeasures().get(metric.getKey())).isEqualTo(10d); }