private ComponentDto insertComponent(ComponentDto component) { dbClient.componentDao().insert(dbTester.getSession(), component); dbTester.getSession().commit(); return component; }
private MetricDto insertMetric(MetricDto metric) { db.getDbClient().metricDao().insert(db.getSession(), metric); db.getSession().commit(); return metric; }
@Test public void scrollIndexingRulesByKeys_scrolls_nothing_if_key_does_not_exist() { Accumulator<RuleForIndexingDto> accumulator = new Accumulator<>(); db.rules().insert(); int nonExistingRuleId = 42; underTest.scrollIndexingRulesByKeys(db.getSession(), singletonList(nonExistingRuleId), accumulator); assertThat(accumulator.list).isEmpty(); }
private void loginWithBrowsePermission(UserDto user, String permission, IssueDto issueDto) { userSession.logIn(user).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get(), dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getComponentUuid()).get()); }
@Test public void deleteDeprecatedRuleKeys_with_non_existing_uuid_has_no_effect() { db.rules().insertDeprecatedKey(d -> d.setUuid("A1")); db.rules().insertDeprecatedKey(d -> d.setUuid("A2")); assertThat(underTest.selectAllDeprecatedRuleKeys(db.getSession())).hasSize(2); underTest.deleteDeprecatedRuleKeys(db.getSession(), asList("B1", "B2")); assertThat(underTest.selectAllDeprecatedRuleKeys(db.getSession())).hasSize(2); }
@Test public void do_nothing_if_project_has_not_been_analyzed() { // project has no snapshots List<QGChangeEvent> result = run(file1, newIncrementalFormula()); assertThat(db.countRowsOfTable(db.getSession(), "live_measures")).isEqualTo(0); assertThatProjectNotChanged(result, project); }
@Test public void insert_entry_in_changelog_when_setting_tags() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "new-tag"); List<FieldDiffs> fieldDiffs = dbClient.issueChangeDao().selectChangelogByIssue(db.getSession(), issueDto.getKey()); assertThat(fieldDiffs).hasSize(1); assertThat(fieldDiffs.get(0).diffs()).hasSize(1); assertThat(fieldDiffs.get(0).diffs().get("tags").oldValue()).isEqualTo("old-tag"); assertThat(fieldDiffs.get(0).diffs().get("tags").newValue()).isEqualTo("new-tag"); }
@Test public void delete() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertProvidedLink(project); underTest.delete(db.getSession(), link.getUuid()); db.getSession().commit(); assertThat(db.countRowsOfTable("project_links")).isEqualTo(0); }
@Test public void select_parameters_by_rule_keys() { RuleDefinitionDto rule1 = db.rules().insert(); db.rules().insertRuleParam(rule1); RuleDefinitionDto rule2 = db.rules().insert(); db.rules().insertRuleParam(rule2); assertThat(underTest.selectRuleParamsByRuleKeys(db.getSession(), Arrays.asList(rule1.getKey(), rule2.getKey()))).hasSize(2); assertThat(underTest.selectRuleParamsByRuleKeys(db.getSession(), singletonList(RuleKey.of("unknown", "Unknown")))).isEmpty(); }
private void assertThatRatingMeasureHasLeakValue(ComponentDto component, Rating expectedValue) { LiveMeasureDto measure = db.getDbClient().liveMeasureDao().selectMeasure(db.getSession(), component.uuid(), ratingMetric.getKey()).get(); assertThat(measure.getComponentUuid()).isEqualTo(component.uuid()); assertThat(measure.getProjectUuid()).isEqualTo(component.projectUuid()); assertThat(measure.getMetricId()).isEqualTo(ratingMetric.getId()); assertThat(measure.getVariation()).isEqualTo((double) expectedValue.getIndex()); }
@Test public void set_tags() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "bug", "todo"); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); verifyContentOfPreloadedSearchResponseData(issueDto); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getTags()).containsOnly("bug", "todo"); assertThat(issueChangePostProcessor.wasCalled()).isFalse(); }
@Test public void delete_branches() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertMainBranch(organization); ComponentDto branch = db.components().insertProjectBranch(project); logInAsAdministrator(organization); sendRequest(organization); verifyOrganizationDoesNotExist(organization); assertThat(db.countRowsOfTable(db.getSession(), "projects")).isZero(); assertThat(db.countRowsOfTable(db.getSession(), "project_branches")).isZero(); verify(projectLifeCycleListeners).onProjectsDeleted(ImmutableSet.of(Project.from(project))); }
@Test public void count_groups_by_logins() { db.users().insertMember(group1, user1); db.users().insertMember(group2, user1); db.users().insertMember(group3, user1); db.users().insertMember(group2, user2); assertThat(underTest.selectGroupsByLogins(db.getSession(), emptyList()).keys()).isEmpty(); Multimap<String, String> groupsByLogin = underTest.selectGroupsByLogins(db.getSession(), asList(user1.getLogin(), user2.getLogin(), user3.getLogin())); assertThat(groupsByLogin.get(user1.getLogin())).containsOnly(group1.getName(), group2.getName(), group3.getName()); assertThat(groupsByLogin.get(user2.getLogin())).containsOnly(group2.getName()); assertThat(groupsByLogin.get(user3.getLogin())).isEmpty(); }
@Test public void delete_comment_using_deprecated_key_parameter() { IssueDto issueDto = issueDbTester.insertIssue(); UserDto user = dbTester.users().insertUser(); IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it"); loginAndAddProjectPermission(user, issueDto, USER); tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute(); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); assertThat(dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey())).isNotPresent(); verifyContentOfPreloadedSearchResponseData(issueDto); }
@Test public void tags_are_stored_as_lowercase() { IssueDto issueDto = db.issues().insertIssue(newIssue().setTags(singletonList("old-tag"))); logIn(issueDto); call(issueDto.getKey(), "bug", "Convention"); IssueDto issueReloaded = dbClient.issueDao().selectByKey(db.getSession(), issueDto.getKey()).get(); assertThat(issueReloaded.getTags()).containsOnly("bug", "convention"); }
@Test public void persist_fails_with_ISE_if_no_component_for_main_branches() { analysisMetadataHolder.setBranch(createBranch(LONG, true, "master")); treeRootHolder.setRoot(MAIN); expectMissingComponentISE(); underTest.persist(dbTester.getSession()); }
@Test public void selectByKeys_populates_organizationUuid_even_when_organization_has_no_metadata() { OrganizationDto organization = db.organizations().insert(); RuleDefinitionDto rule = db.rules().insert(); assertThat(underTest.selectByKeys(db.getSession(), organization.getUuid(), singletonList(rule.getKey()))) .extracting(RuleDto::getOrganizationUuid) .containsExactly(organization.getUuid()); }
@Test public void selectOrFailByKey_fails_if_rule_not_found() { OrganizationDto organization = db.organizations().insert(); thrown.expect(RowNotFoundException.class); thrown.expectMessage("Rule with key 'NOT:FOUND' does not exist"); underTest.selectOrFailByKey(db.getSession(), organization, RuleKey.of("NOT", "FOUND")); }
@Test public void delete_organization_alm_binding() { OrganizationDto organization = db.organizations().insert(); db.alm().insertOrganizationAlmBinding(organization, db.alm().insertAlmAppInstall()); logInAsAdministrator(organization); sendRequest(organization); assertThat(db.getDbClient().organizationAlmBindingDao().selectByOrganization(db.getSession(), organization)).isNotPresent(); }
private void insertRulesProfile(BuiltInQProfile builtIn) { RulesProfileDto dto = new RulesProfileDto() .setIsBuiltIn(true) .setKee(RandomStringUtils.randomAlphabetic(40)) .setLanguage(builtIn.getLanguage()) .setName(builtIn.getName()); dbClient.qualityProfileDao().insert(db.getSession(), dto); db.commit(); }