public IssueChangeDto insertChange(IssueChangeDto issueChangeDto) { db.getDbClient().issueChangeDao().insert(db.getSession(), issueChangeDto); db.commit(); return issueChangeDto; }
@Test public void deletePermissions_deletes_permissions_of_private_project() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); addPermissions(organization, project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deletePermissions(project.getId()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); }
@Test public void keep_isSystemAdministrator_flag_in_cache() { organizationFlags.setEnabled(false); UserDto user = db.users().insertUser(); db.users().insertPermissionOnUser(db.getDefaultOrganization(), user, SYSTEM_ADMIN); UserSession session = newUserSession(user); session.checkIsSystemAdministrator(); db.getDbClient().userDao().deactivateUser(db.getSession(), user); db.commit(); // should fail but succeeds because flag is kept in cache session.checkIsSystemAdministrator(); }
@Test public void shouldCleanConditions() { dbTester.prepareDbUnit(getClass(), "shouldCleanConditions.xml"); underTest.deleteConditionsWithInvalidMetrics(dbTester.getSession()); dbTester.commit(); dbTester.assertDbUnit(getClass(), "shouldCleanConditions-result.xml", new String[] {"created_at", "updated_at"}, "quality_gate_conditions"); } }
@Test public void shouldDeleteComponentsAndChildrenTables() { dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml"); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deleteComponents("uuid_1"); assertThat(dbTester.countRowsOfTable("projects")).isZero(); assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3); assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1); }
@Test public void update_index_when_project_tags_are_updated() { ComponentDto project = db.components().insertPrivateProject(p -> p.setTagsString("foo")); indexProject(project, PROJECT_CREATION); assertThatProjectHasTag(project, "foo"); project.setTagsString("bar"); db.getDbClient().componentDao().updateTags(db.getSession(), project); IndexingResult result = indexProject(project, PROJECT_TAGS_UPDATE); assertThatProjectHasTag(project, "bar"); assertThat(result.getTotal()).isEqualTo(1L); assertThat(result.getSuccess()).isEqualTo(1L); }
@Test public void fail_when_default_qgate_defined_does_not_exists() { ComponentDto project = db.components().insertPrivateProject(); QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(db.getDefaultOrganization(), qg -> qg.setName("Sonar way")); db.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession); db.commit(); assertThat(underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project)).isEmpty(); }
@Test public void delete_by_uuid() { dbTester.events().insertEvent(newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()))).setUuid("E1")); underTest.delete(dbTester.getSession(), "E1"); dbTester.commit(); assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0); }
private ComponentDto insertProjectWithBranchAndRelatedData() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); ComponentDto file = db.components().insertComponent(newFileDto(subModule)); db.issues().insert(rule, branch, file); db.issues().insert(rule, branch, subModule); db.issues().insert(rule, branch, module); return project; }
@Test public void activate_one_rule() { OrganizationDto organization = db.organizations().insert(); QProfileDto qProfile = db.qualityProfiles().insert(organization); RuleDefinitionDto rule = db.rules().insert(r -> r.setLanguage(qProfile.getLanguage())); RuleActivation ruleActivation = RuleActivation.create(rule.getId(), Severity.CRITICAL, Collections.emptyMap()); qProfileRules.activateAndCommit(db.getSession(), qProfile, singleton(ruleActivation)); assertThat(db.getDbClient().activeRuleDao().selectByProfile(db.getSession(), qProfile)) .extracting(ActiveRuleDto::getRuleKey, ActiveRuleDto::getSeverityString) .containsExactlyInAnyOrder(tuple(rule.getKey(), Severity.CRITICAL)); }
@Test public void selectByOrganization() { OrganizationDto organization = db.organizations().insert(); db.getDbClient().almAppInstallDao().insertOrUpdate(db.getSession(), ALM.GITHUB, "the-owner", false, "123456", null); // could be improved, insertOrUpdate should return the DTO with its uuid Optional<AlmAppInstallDto> install = db.getDbClient().almAppInstallDao().selectByOwnerId(db.getSession(), ALM.GITHUB, "the-owner"); db.getDbClient().organizationAlmBindingDao().insert(db.getSession(), organization, install.get(), "xxx", "xxx"); db.commit(); assertThat(underTest.selectByOrganization(db.getSession(), GITHUB, organization).get().getUuid()).isEqualTo(install.get().getUuid()); assertThat(underTest.selectByOrganization(db.getSession(), BITBUCKETCLOUD, organization)).isEmpty(); assertThat(underTest.selectByOrganization(db.getSession(), GITHUB, new OrganizationDto().setUuid("other-organization"))).isEmpty(); }
@Test public void cancelWornOuts_does_not_update_queueStatus() { CEQueueStatus queueStatusMock = mock(CEQueueStatus.class); CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1")); db.executeUpdateSql("update ce_queue set status = 'PENDING', started_at = 123 where uuid = '" + task.getUuid() + "'"); db.commit(); InternalCeQueueImpl underTest = new InternalCeQueueImpl(system2, db.getDbClient(), null, queueStatusMock, null, null); underTest.cancelWornOuts(); assertThat(db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid())).isPresent(); verifyZeroInteractions(queueStatusMock); }
@Test public void fail_to_create_condition_on_greater_than_E() { MetricDto metric = insertMetric(RATING, SQALE_RATING_KEY); QualityGateDto qualityGate = db.qualityGates().insertQualityGate(db.getDefaultOrganization()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("There's no worse rating than E (5)"); underTest.createCondition(db.getSession(), qualityGate, metric.getKey(), "GT", "5"); }
@Test public void select_descendants_with_leaves_strategy() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newModuleDto("module-1-uuid", project)); db.components().insertComponent(newFileDto(project, null, "file-1-uuid")); db.components().insertComponent(newFileDto(project, null, "file-2-uuid")); db.commit(); ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).setStrategy(LEAVES).build(); List<ComponentDto> result = underTest.selectDescendants(dbSession, query); assertThat(result).extracting("uuid").containsOnly("file-1-uuid", "file-2-uuid", "module-1-uuid"); }
@Test public void change_project_visibility_to_private() { userSession.logIn().setSystemAdministrator(); wsTester.newRequest() .setParam(PARAM_PROJECT_VISIBILITY, "private") .execute(); assertThat(dbTester.getDbClient().organizationDao().getNewProjectPrivate(dbTester.getSession(), dbTester.getDefaultOrganization())).isTrue(); }
@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); }
private DbData insertData() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); RuleDefinitionDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, project); SnapshotDto analysis = db.components().insertSnapshot(project); mockResourceTypeAsValidProject(); return new DbData(project, analysis, issue); }
@Test public void fail_when_search_query_has_less_than_3_characters() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("'q' length (2) is shorter than the minimum authorized (3)"); db.components().insertComponent(newPrivateProjectDto(db.organizations().insert(), "project-uuid")); db.commit(); ws.newRequest() .setParam(PARAM_COMPONENT_ID, "project-uuid") .setParam(Param.TEXT_QUERY, "fi") .execute(); }
@Test public void loadQualityGate_returns_hardcoded_gate_for_pull_requests() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); BranchDto pullRequest = newBranchDto(project).setBranchType(BranchType.PULL_REQUEST); db.components().insertProjectBranch(project, pullRequest); QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, pullRequest); assertThat(result).isSameAs(ShortLivingBranchQualityGate.GATE); }
@Test public void search_on_default_organization_when_no_organization_set() { userSession.addPermission(ADMINISTER, db.getDefaultOrganization()); OrganizationDto otherOrganization = db.organizations().insert(); db.components().insertComponents( ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey(PROJECT_KEY_1), ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey(PROJECT_KEY_2), ComponentTesting.newPrivateProjectDto(otherOrganization).setDbKey(PROJECT_KEY_3)); SearchWsResponse response = call(SearchRequest.builder().build()); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly(PROJECT_KEY_1, PROJECT_KEY_2); }