@Test public void a_filter_predicate_can_be_evaluated_on_decimal_criteria() { List<Map> result = JsonPath.read (ARRAY2, "$[?(@.decimal == 0.1)]"); assertThat(result).hasSize(1); assertThat(result.get(0)).contains(entry("decimal", 0.1)); }
@Test public void getTrackedMessages() throws Exception { Map<Long, Map<Long, EhcacheEntityResponse>> result = message.getTrackedMessages(); assertThat(result).containsKeys(id1.toLong(), id2.toLong()); assertThat(result.get(id1.toLong())).contains(entry(3L, r3), entry(4L, r4)); assertThat(result.get(id2.toLong())).contains(entry(5L, r5)); }
@Test public void countTags() { OrganizationDto org = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(org); indexIssues( newDoc("issue1", project).setTags(ImmutableSet.of("convention", "java8", "bug")), newDoc("issue2", project).setTags(ImmutableSet.of("convention", "bug")), newDoc("issue3", project).setTags(emptyList()), newDoc("issue4", project).setTags(ImmutableSet.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED), newDoc("issue5", project).setTags(ImmutableSet.of("convention"))); assertThat(underTest.countTags(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L)); assertThat(underTest.countTags(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L); assertThat(underTest.countTags(projectQuery("other"), 10)).isEmpty(); }
@Test public void boolean_criteria_evaluates() { List<Map> result = JsonPath.read (ARRAY2, "$[?(@.bool == true)]"); assertThat(result).hasSize(1); assertThat(result.get(0)).contains(entry("foo", "foo-val-7")); }
@Test public void a_filter_predicate_can_be_evaluated_on_int_criteria() { List<Map> result = JsonPath.read (ARRAY2, "$[?(@.int == 1)]"); assertThat(result).hasSize(1); assertThat(result.get(0)).contains(entry("int", 1)); }
@Test public void multiple_criteria_can_be_used() { List<Map> result = JsonPath.read (ARRAY2, "$[?(@.decimal == 0.1 && @.int == 1)]"); assertThat(result).hasSize(1); assertThat(result.get(0)).contains(entry("foo", "foo-val-1")); }
@Test public void field_existence_can_be_checked() { List<Map> result = JsonPath.read (ARRAY2, "$[?(@.bool)]"); assertThat(result).hasSize(1); assertThat(result.get(0)).contains(entry("foo", "foo-val-7")); }
@Test public void add_file_data() { FileData fileData = new FileData("123", "456"); repository.addFileData("/Abc.java", fileData); assertThat(repository.fileData()).hasSize(1); assertThat(repository.fileData()).contains(Maps.immutableEntry("/Abc.java", fileData)); assertThat(repository.fileDataByPath("/Abc.java")).isEqualTo(fileData); }
@Test public void load_properties_from_file() throws Exception { File homeDir = temp.newFolder(); File propsFile = new File(homeDir, "conf/sonar.properties"); FileUtils.write(propsFile, "foo=bar"); AppSettingsLoaderImpl underTest = new AppSettingsLoaderImpl(new String[0], homeDir); AppSettings settings = underTest.load(); assertThat(settings.getProps().rawProperties()).contains(entry("foo", "bar")); }
@Test public void command_line_arguments_make_precedence_over_properties_files() throws Exception { File homeDir = temp.newFolder(); File propsFile = new File(homeDir, "conf/sonar.properties"); FileUtils.write(propsFile, "sonar.foo=file"); AppSettingsLoaderImpl underTest = new AppSettingsLoaderImpl(new String[]{"-Dsonar.foo=cli"}, homeDir); AppSettings settings = underTest.load(); assertThat(settings.getProps().rawProperties()).contains(entry("sonar.foo", "cli")); }
@Test public void command_line_arguments_are_included_to_settings() throws Exception { File homeDir = temp.newFolder(); AppSettingsLoaderImpl underTest = new AppSettingsLoaderImpl(new String[] {"-Dsonar.foo=bar", "-Dhello=world"}, homeDir); AppSettings settings = underTest.load(); assertThat(settings.getProps().rawProperties()) .contains(entry("sonar.foo", "bar")) .contains(entry("hello", "world")); }
@Test public void createWebCommand_returns_command_for_default_settings() { JavaCommand command = newFactory(new Properties()).createWebCommand(true); assertThat(command.getClassName()).isEqualTo("org.sonar.server.app.WebServer"); assertThat(command.getWorkDir().getAbsolutePath()).isEqualTo(homeDir.getAbsolutePath()); assertThat(command.getClasspath()) .containsExactly("./lib/common/*"); assertThat(command.getJvmOptions().getAll()) // enforced values .contains("-Djava.awt.headless=true", "-Dfile.encoding=UTF-8") // default settings .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath(), "-Dfile.encoding=UTF-8") .contains("-Xmx512m", "-Xms128m", "-XX:+HeapDumpOnOutOfMemoryError"); assertThat(command.getProcessId()).isEqualTo(ProcessId.WEB_SERVER); assertThat(command.getEnvVariables()) .isNotEmpty(); assertThat(command.getArguments()) // default settings .contains(entry("sonar.web.javaOpts", "-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError")) .contains(entry("sonar.cluster.enabled", "false")); assertThat(command.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS"); }
@Test public void reload_configuration_then_reset_all() throws IOException { AppSettings settings = new TestAppSettings().set("foo", "bar"); AppSettings newSettings = new TestAppSettings() .set("foo", "newBar") .set("newProp", "newVal"); when(settingsLoader.load()).thenReturn(newSettings); underTest.reload(settings); assertThat(settings.getProps().rawProperties()) .contains(entry("foo", "newBar")) .contains(entry("newProp", "newVal")); verify(logging).configure(); verify(state).reset(); verify(fs).reset(); }
@Test public void createWebCommand_configures_command_with_overridden_settings() { Properties props = new Properties(); props.setProperty("sonar.web.port", "1234"); props.setProperty("sonar.web.javaOpts", "-Xmx10G"); JavaCommand command = newFactory(props).createWebCommand(true); assertThat(command.getJvmOptions().getAll()) // enforced values .contains("-Djava.awt.headless=true", "-Dfile.encoding=UTF-8") // default settings .contains("-Djava.io.tmpdir=" + tempDir.getAbsolutePath(), "-Dfile.encoding=UTF-8") // overridden values .contains("-Xmx10G") .doesNotContain("-Xms128m", "-XX:+HeapDumpOnOutOfMemoryError"); assertThat(command.getArguments()) // default settings .contains(entry("sonar.web.javaOpts", "-Xmx10G")) .contains(entry("sonar.cluster.enabled", "false")); assertThat(command.getSuppressedEnvVariables()).containsOnly("JAVA_TOOL_OPTIONS"); }
@Test public void update_index_when_updating_user_login() { UserDto oldUser = db.users().insertUser(); createDefaultGroup(); userIndexer.indexOnStartup(null); underTest.updateAndCommit(session, oldUser, new UpdateUser() .setLogin("new_login"), u -> { }); List<SearchHit> indexUsers = es.getDocuments(UserIndexDefinition.INDEX_TYPE_USER); assertThat(indexUsers).hasSize(1); assertThat(indexUsers.get(0).getSource()) .contains(entry("login", "new_login")); }
@Test public void tags_facet_should_return_top_100_items() { // default number of items returned in tag facet = 100 String[] tags = get101Tags(); createRule(setSystemTags(tags)); index(); RuleQuery query = new RuleQuery() .setOrganization(db.getDefaultOrganization()); SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS)); SearchIdResult result = underTest.search(query, options); assertThat(result.getFacets().get(FACET_TAGS).size()).isEqualTo(100); assertThat(result.getFacets().get(FACET_TAGS)).contains(entry("tag0", 1L), entry("tag25", 1L), entry("tag99", 1L)); assertThat(result.getFacets().get(FACET_TAGS)).doesNotContain(entry("tagA", 1L)); }
@Test public void tags_facet_should_find_tags_of_specified_organization() { OrganizationDto organization = db.organizations().insert(); RuleDefinitionDto rule = createRule(setSystemTags()); createRuleMetadata(rule, organization, setTags("bla")); index(); RuleQuery query = new RuleQuery().setOrganization(organization); SearchOptions options = new SearchOptions().addFacets(singletonList(FACET_TAGS)); SearchIdResult result = underTest.search(query, options); assertThat(result.getFacets().get(FACET_TAGS)).contains(entry("bla", 1L)); }
@Test public void insert() { underTest.insert(db.getSession(), new QProfileEditGroupsDto() .setUuid("ABCD") .setGroupId(100) .setQProfileUuid("QPROFILE") ); assertThat(db.selectFirst(db.getSession(), "select uuid as \"uuid\", group_id as \"groupId\", qprofile_uuid as \"qProfileUuid\", created_at as \"createdAt\" from qprofile_edit_groups")).contains( entry("uuid", "ABCD"), entry("groupId", 100L), entry("qProfileUuid", "QPROFILE"), entry("createdAt", NOW)); }
@Test public void insert() { underTest.insert(db.getSession(), new QProfileEditUsersDto() .setUuid("ABCD") .setUserId(100) .setQProfileUuid("QPROFILE") ); assertThat(db.selectFirst(db.getSession(), "select uuid as \"uuid\", user_id as \"userId\", qprofile_uuid as \"qProfileUuid\", created_at as \"createdAt\" from qprofile_edit_users")).contains( entry("uuid", "ABCD"), entry("userId", 100L), entry("qProfileUuid", "QPROFILE"), entry("createdAt", NOW)); }
@Test public void insert() { when(uuidFactory.create()).thenReturn("ABCD"); OrganizationDto organization = db.organizations().insert(); UserDto user = db.users().insertUser(); AlmAppInstallDto almAppInstall = db.alm().insertAlmAppInstall(); underTest.insert(db.getSession(), organization, almAppInstall, "http://myorg.com", user.getUuid()); assertThat(db.selectFirst(db.getSession(), "select" + " uuid as \"uuid\", organization_uuid as \"organizationUuid\", alm_app_install_uuid as \"almAppInstallUuid\", url as \"url\", alm_id as \"almId\"," + " user_uuid as \"userUuid\", created_at as \"createdAt\"" + " from organization_alm_bindings" + " where organization_uuid='" + organization.getUuid() + "'")) .contains( entry("uuid", "ABCD"), entry("organizationUuid", organization.getUuid()), entry("almAppInstallUuid", almAppInstall.getUuid()), entry("almId", "github"), entry("url", "http://myorg.com"), entry("userUuid", user.getUuid()), entry("createdAt", NOW)); }