private boolean scannerContextExists(String uuid) { return dbTester.countSql("select count(1) from ce_scanner_context where task_uuid = '" + uuid + "'") == 1; }
private void assertThatNoPermission(String permission) { assertThat(db.countSql("select count(id) from group_roles where role='" + permission + "'")).isEqualTo(0); }
private void assertThatCustomProfileDoesNotExist(QProfileDto profile) { assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isEqualTo(0); assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(0); // TODO active_rule_parameters }
private void assertThatProjectHasNoPermissions(ComponentDto project) { assertThat(db.countSql(dbSession, "select count(id) from user_roles where resource_id=" + project.getId())).isEqualTo(0); }
private void assertThatCustomProfileExists(QProfileDto profile) { assertThat(db.countSql(dbSession, "select count(*) from org_qprofiles where uuid = '" + profile.getKee() + "'")).isGreaterThan(0); //assertThat(db.countSql(dbSession, "select count(*) from project_qprofiles where profile_key = '" + profile.getKee() + "'")).isGreaterThan(0); //assertThat(db.countSql(dbSession, "select count(*) from default_qprofiles where qprofile_uuid = '" + profile.getKee() + "'")).isGreaterThan(0); assertThat(db.countSql(dbSession, "select count(*) from rules_profiles where kee = '" + profile.getRulesProfileUuid() + "'")).isEqualTo(1); assertThat(db.countSql(dbSession, "select count(*) from active_rules where profile_id = " + profile.getId())).isGreaterThan(0); assertThat(db.countSql(dbSession, "select count(*) from qprofile_changes where rules_profile_uuid = '" + profile.getRulesProfileUuid() + "'")).isGreaterThan(0); // TODO active_rule_parameters }
@Test public void delete_EsQueueDto_does_not_throw_exception() { int nbOfInsert = 10 + new Random().nextInt(20); List<EsQueueDto> esQueueDtos = new ArrayList<>(); IntStream.rangeClosed(1, nbOfInsert).forEach( i -> esQueueDtos.add(EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())) ); underTest.insert(dbSession, esQueueDtos); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(nbOfInsert); underTest.delete(dbSession, esQueueDtos); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(0); }
private void assertThatProjectPermissionDoesNotExist(UserDto user, String permission, ComponentDto project) { assertThat(db.countSql(dbSession, "select count(id) from user_roles where role='" + permission + "' and user_id=" + user.getId() + " and resource_id=" + project.getId())) .isEqualTo(0); }
@Test public void insert_data() { int nbOfInsert = 10 + new Random().nextInt(20); List<EsQueueDto> esQueueDtos = new ArrayList<>(); IntStream.rangeClosed(1, nbOfInsert).forEach( i -> esQueueDtos.add(EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())) ); underTest.insert(dbSession, esQueueDtos); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(nbOfInsert); }
@Test public void delete_unknown_EsQueueDto_does_not_throw_exception() { int nbOfInsert = 10 + new Random().nextInt(20); List<EsQueueDto> esQueueDtos = new ArrayList<>(); IntStream.rangeClosed(1, nbOfInsert).forEach( i -> esQueueDtos.add(EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())) ); underTest.insert(dbSession, esQueueDtos); underTest.delete(dbSession, EsQueueDto.create("foo", UuidFactoryFast.getInstance().create())); assertThat(dbTester.countSql(dbSession, "select count(*) from es_queue")).isEqualTo(nbOfInsert); }
@Test public void delete_view_sub_view_and_tech_project() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); // view underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); }
@Test public void delete() { OrganizationDto organization = db.organizations().insert(); QGateWithOrgDto qualityGate = qualityGateDbTester.insertQualityGate(organization); QGateWithOrgDto otherQualityGate = qualityGateDbTester.insertQualityGate(organization); underTest.delete(qualityGate, dbSession); dbSession.commit(); assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, qualityGate.getUuid())).isNull(); assertThat(db.countSql(dbSession, format("select count(*) from org_quality_gates where quality_gate_uuid='%s'", qualityGate.getUuid()))).isZero(); assertThat(underTest.selectByOrganizationAndUuid(dbSession, organization, otherQualityGate.getUuid())).isNotNull(); assertThat(db.countSql(dbSession, format("select count(*) from org_quality_gates where quality_gate_uuid='%s'", otherQualityGate.getUuid()))).isEqualTo(1); }
@Test public void delete_view_and_child() { db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml"); underTest.deleteProject(dbSession, "A"); dbSession.commit(); assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero(); assertThat(db.countRowsOfTable("projects")).isZero(); }
@Test public void deleteGlobalPermission() { OrganizationDto organization = db.organizations().insert(); UserDto user1 = insertUser(organization); UserDto user2 = insertUser(organization); ComponentDto project1 = db.components().insertPrivateProject(organization); ComponentDto project2 = db.components().insertPrivateProject(organization); addGlobalPermission(organization, "perm1", user1); addGlobalPermission(organization, "perm2", user1); addProjectPermission(organization, "perm1", user1, project1); addProjectPermission(organization, "perm3", user2, project1); addProjectPermission(organization, "perm4", user2, project2); // user2 does not have global permissions -> do nothing underTest.deleteGlobalPermission(dbSession, user2.getId(), "perm1", db.getDefaultOrganization().getUuid()); assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); // global permission is not granted -> do nothing underTest.deleteGlobalPermission(dbSession, user1.getId(), "notGranted", db.getDefaultOrganization().getUuid()); assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); // permission is on project -> do nothing underTest.deleteGlobalPermission(dbSession, user1.getId(), "perm3", db.getDefaultOrganization().getUuid()); assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); // global permission on another organization-> do nothing underTest.deleteGlobalPermission(dbSession, user1.getId(), "notGranted", "anotherOrg"); assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(5); // global permission exists -> delete it, but not the project permission with the same name ! underTest.deleteGlobalPermission(dbSession, user1.getId(), "perm1", organization.getUuid()); assertThat(db.countSql(dbSession, "select count(id) from user_roles where role='perm1' and resource_id is null")).isEqualTo(0); assertThat(db.countRowsOfTable(dbSession, "user_roles")).isEqualTo(4); }
@Test public void delete_tasks_in_ce_queue_when_deleting_project() { ComponentDto projectToBeDeleted = db.components().insertPrivateProject(); ComponentDto anotherLivingProject = db.components().insertPrivateProject(); // Insert 3 rows in CE_QUEUE: two for the project that will be deleted (in order to check that status // is not involved in deletion), and one on another project dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.PENDING)); dbClient.ceQueueDao().insert(dbSession, createCeQueue(projectToBeDeleted, Status.IN_PROGRESS)); dbClient.ceQueueDao().insert(dbSession, createCeQueue(anotherLivingProject, Status.PENDING)); dbSession.commit(); underTest.deleteProject(dbSession, projectToBeDeleted.uuid()); dbSession.commit(); assertThat(db.countRowsOfTable("ce_queue")).isEqualTo(1); assertThat(db.countSql("select count(*) from ce_queue where main_component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0); }
@Test public void deleteByRootComponentId_on_private_project() { OrganizationDto org = db.organizations().insert(); GroupDto group1 = db.users().insertGroup(org); GroupDto group2 = db.users().insertGroup(org); ComponentDto project1 = db.components().insertPrivateProject(org); ComponentDto project2 = db.components().insertPrivateProject(org); db.users().insertPermissionOnGroup(group1, "perm1"); db.users().insertProjectPermissionOnGroup(group1, "perm2", project1); db.users().insertProjectPermissionOnGroup(group2, "perm3", project2); underTest.deleteByRootComponentId(dbSession, project1.getId()); dbSession.commit(); assertThat(db.countSql("select count(id) from group_roles where resource_id=" + project1.getId())).isEqualTo(0); assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2); }
@Test public void deleteByRootComponentId_on_public_project() { OrganizationDto org = db.organizations().insert(); GroupDto group1 = db.users().insertGroup(org); GroupDto group2 = db.users().insertGroup(org); ComponentDto project1 = db.components().insertPublicProject(org); ComponentDto project2 = db.components().insertPublicProject(org); db.users().insertPermissionOnGroup(group1, "perm1"); db.users().insertProjectPermissionOnGroup(group1, "perm2", project1); db.users().insertProjectPermissionOnGroup(group2, "perm3", project2); db.users().insertProjectPermissionOnAnyone("perm4", project1); db.users().insertProjectPermissionOnAnyone("perm5", project2); underTest.deleteByRootComponentId(dbSession, project1.getId()); dbSession.commit(); assertThat(db.countSql("select count(id) from group_roles where resource_id=" + project1.getId())).isEqualTo(0); assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3); }
IssueDto confirmOnNonSelected = db.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("CONFIRM")); assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(0); assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(0); assertThat(db.countSql("select count(*) from issues where resolution = 'REMOVED'")).isEqualTo(0); assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(1); assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4); for (IssueDto issue : Arrays.asList(openOnFile, confirmOnFile, openOnDir, confirmOnDir)) { assertThat(db.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())