@Test public void generate_SERVER_STARTIME_but_do_not_persist_it_if_server_is_startup_leader() { when(system.now()).thenReturn(A_DATE); SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER); when(webServer.isStartupLeader()).thenReturn(true); StartupMetadata metadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(metadata.getStartedAt()).isEqualTo(A_DATE); assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME); // keep a cache StartupMetadata secondMetadata = underTest.provide(system, runtime, webServer, dbTester.getDbClient()); assertThat(secondMetadata).isSameAs(metadata); }
private void assertWithoutProjectCreatorFor(String permission) { Optional<PermissionTemplateCharacteristicDto> templatePermission = db.getDbClient().permissionTemplateCharacteristicDao().selectByPermissionAndTemplateId(db.getSession(), permission, template.getId()); assertThat(templatePermission).isPresent(); assertThat(templatePermission.get().getWithProjectCreator()).isFalse(); }
@Before public void setUp() throws Exception { dbSession = db.getDbClient().openSession(false); purgeMapper = dbSession.getMapper(PurgeMapper.class); }
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()); }
private EsQueueDto insertInQueue(IndexType indexType, String id) { EsQueueDto item = EsQueueDto.create(indexType.format(), id); db.getDbClient().esQueueDao().insert(db.getSession(), singletonList(item)); return item; }
private MetricDto insertMetric(MetricDto metric) { db.getDbClient().metricDao().insert(db.getSession(), metric); db.getSession().commit(); return metric; }
@Test public void update_with_the_same_values() throws Exception { loginAsAdmin(db.getDefaultOrganization()); call(template.getUuid(), template.getName(), template.getDescription(), template.getKeyPattern()); PermissionTemplateDto reloaded = db.getDbClient().permissionTemplateDao().selectByUuid(db.getSession(), template.getUuid()); assertThat(reloaded.getName()).isEqualTo(template.getName()); assertThat(reloaded.getDescription()).isEqualTo(template.getDescription()); assertThat(reloaded.getKeyPattern()).isEqualTo(template.getKeyPattern()); }
@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); }
private CeQueueDto createTaskSubmit(@Nullable ComponentDto componentDto) { CeTaskSubmit.Builder submission = queue.prepareSubmit() .setType(CeTaskTypes.REPORT) .setSubmitterUuid(null) .setCharacteristics(emptyMap()); if (componentDto != null) { submission.setComponent(CeTaskSubmit.Component.fromDto(componentDto)); } CeTask task = queue.submit(submission.build()); return db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get(); } }
@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 cancel_pending_task_on_project() { logInAsSystemAdministrator(); ComponentDto project = db.components().insertPrivateProject(); CeQueueDto queue = createTaskSubmit(project); tester.newRequest() .setParam("id", queue.getUuid()) .execute(); assertThat(db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), queue.getUuid()).get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED); }
@Test public void recovery_does_not_fail_if_unsupported_docIdType() { EsQueueDto item = EsQueueDto.create(INDEX_TYPE_ISSUE.format(), "I1", "unknown", "P1"); db.getDbClient().esQueueDao().insert(db.getSession(), item); db.commit(); recover(); assertThat(logTester.logs(LoggerLevel.ERROR)) .filteredOn(l -> l.contains("Unsupported es_queue.doc_id_type for issues. Manual fix is required: ")) .hasSize(1); assertThatEsQueueTableHasSize(1); }
private void unsafeInsertProjectPermissionOnUser(ComponentDto component, UserDto user, String permission) { UserPermissionDto dto = new UserPermissionDto(component.getOrganizationUuid(), permission, user.getId(), component.getId()); dbTester.getDbClient().userPermissionDao().insert(dbTester.getSession(), dto); dbTester.commit(); }
private List<String> getLoginsInTemplateAndPermission(PermissionTemplateDto template, String permission) { PermissionQuery permissionQuery = PermissionQuery.builder().setOrganizationUuid(template.getOrganizationUuid()).setPermission(permission).build(); return db.getDbClient().permissionTemplateDao() .selectUserLoginsByQueryAndTemplate(db.getSession(), permissionQuery, template.getId()); }
@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 List<Integer> selectProjectPermissionUsers(ComponentDto project, String permission) { PermissionQuery query = PermissionQuery.builder().setOrganizationUuid(project.getOrganizationUuid()).setPermission(permission).setComponentUuid(project.uuid()).build(); return db.getDbClient().userPermissionDao().selectUserIdsByQuery(db.getSession(), query); } }
private List<Integer> selectProjectPermissionUsers(ComponentDto project, String permission) { PermissionQuery query = PermissionQuery.builder().setOrganizationUuid(project.getOrganizationUuid()).setPermission(permission).setComponentUuid(project.uuid()).build(); return db.getDbClient().userPermissionDao().selectUserIdsByQuery(db.getSession(), query); } }
@Test public void return_empty_value_when_no_scm() throws Exception { userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project, file); dbTester.getDbClient().fileSourceDao().insert(dbSession, new FileSourceDto() .setProjectUuid(PROJECT_UUID) .setFileUuid(FILE_UUID) .setSourceData(DbFileSources.Data.newBuilder().build())); dbSession.commit(); WsTester.TestRequest request = tester.newGetRequest("api/sources", "scm").setParam("key", FILE_KEY); request.execute().assertJson(getClass(), "return_empty_value_when_no_scm.json"); }
private void unsafeInsertProjectPermissionOnAnyone(String perm, ComponentDto project) { GroupPermissionDto dto = new GroupPermissionDto() .setOrganizationUuid(project.getOrganizationUuid()) .setGroupId(null) .setRole(perm) .setResourceId(project.getId()); db.getDbClient().groupPermissionDao().insert(db.getSession(), dto); db.commit(); } }
@Before public void setUp() { underTest = new MergeBranchComponentUuids(analysisMetadataHolder, db.getDbClient()); analysisMetadataHolder.setBranch(branch); ComponentDto project = db.components().insertMainBranch(); mergeBranch = db.components().insertProjectBranch(project, b -> b.setKey("mergeBranch")); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1")); mergeBranchFile = ComponentTesting.newFileDto(mergeBranch, null, "file").setUuid("mergeFile"); branchFile = ComponentTesting.newFileDto(branch, null, "file").setUuid("file1"); db.components().insertComponents(mergeBranchFile, branchFile); }