@Override public DefaultOrganization get() { if (defaultOrganization == null) { defaultOrganization = toDefaultOrganization(dbTester.getDefaultOrganization()); } return defaultOrganization; }
@Before public void setUp() throws Exception { defaultOrganizationKey = db.getDefaultOrganization().getKey(); defaultOrganizationUuid = db.getDefaultOrganization().getUuid(); }
@Before public void setUp() throws Exception { when(system2.now()).thenReturn(NOW); group1 = db.users().insertGroup(db.getDefaultOrganization(), GROUP1); group2 = db.users().insertGroup(db.getDefaultOrganization(), GROUP2); sonarUsers = db.users().insertDefaultGroup(db.getDefaultOrganization(), "sonar-users"); }
@Test public void return_default_quality_gate_for_project() { ComponentDto project = db.components().insertPrivateProject(); QualityGateDto dbQualityGate = db.qualityGates().createDefaultQualityGate(db.getDefaultOrganization(), qg -> qg.setName("Sonar way")); Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, db.getDefaultOrganization(), project); assertThat(result).isPresent(); assertThat(result.get().getQualityGate().getId()).isEqualTo(dbQualityGate.getId()); assertThat(result.get().isDefault()).isTrue(); }
/** * @deprecated since 6.6 * @see #insertPublicPortfolio(OrganizationDto, Consumer[]) */ public ComponentDto insertView(String uuid) { return insertComponentImpl(newView(db.getDefaultOrganization(), uuid), false, noExtraConfiguration()); }
@Test public void paginate_results() { IntStream.rangeClosed(1, 9) .forEach(i -> addComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("K" + i).setName("N" + i))); ComponentDto unauthorizedProject = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization())); db.favorites().add(unauthorizedProject, USER_ID); SearchResponse result = call(2, 3); assertThat(result.getFavoritesCount()).isEqualTo(3); assertThat(result.getFavoritesList()) .extracting(Favorite::getKey) .containsExactly("K4", "K5", "K6"); }
@Test public void execute_set_organization_from_ce_task_when_organizationKey_is_not_set_in_report() { reportReader.setMetadata( newBatchReportBuilder() .build()); underTest.execute(new TestComputationStepContext()); Organization organization = analysisMetadataHolder.getOrganization(); OrganizationDto defaultOrganization = db.getDefaultOrganization(); assertThat(organization.getUuid()).isEqualTo(defaultOrganization.getUuid()); assertThat(organization.getKey()).isEqualTo(defaultOrganization.getKey()); assertThat(organization.getName()).isEqualTo(defaultOrganization.getName()); }
/** * Create group in default organization */ public GroupDto insertGroup() { GroupDto group = newGroupDto().setOrganizationUuid(db.getDefaultOrganization().getUuid()); return insertGroup(group); }
@Test public void search_by_key_query() { insertProjectsAuthorizedForUser( ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("project-_%-key"), ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("project-key-without-escaped-characters")); SearchWsResponse response = call(new SearchRequest().setQuery("project-_%-key").setQualifiers(singletonList(PROJECT))); assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("project-_%-key"); }
@Test public void index_application() { ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); underTest.index(application.uuid()); List<ViewDoc> result = es.getDocuments(ViewIndexDefinition.INDEX_TYPE_VIEW, ViewDoc.class); assertThat(result).hasSize(1); ViewDoc resultApp = result.get(0); assertThat(resultApp.uuid()).isEqualTo(application.uuid()); assertThat(resultApp.projects()).containsExactlyInAnyOrder(project.uuid()); }
@Test public void deleteByRulesProfileUuids() { QProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization()); QProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization()); insertChange(profile1, "ACTIVATED", null, null); insertChange(profile1, "ACTIVATED", null, null); insertChange(profile2, "ACTIVATED", null, null); underTest.deleteByRulesProfileUuids(dbSession, asList(profile1.getRulesProfileUuid())); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile1.getKee()))).isEqualTo(0); assertThat(underTest.countByQuery(dbSession, new QProfileChangeQuery(profile2.getKee()))).isEqualTo(1); }
@Test public void deactivate_user_deletes_his_qprofiles_permissions() { logInAsSystemAdministrator(); UserDto user = db.users().insertUser(); QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization()); db.qualityProfiles().addUserPermission(profile, user); deactivate(user.getLogin()); assertThat(db.getDbClient().qProfileEditUsersDao().exists(dbSession, profile, user)).isFalse(); }
@Test public void associate() { QualityGateDto qgate = db.qualityGates().insertQualityGate(db.getDefaultOrganization()); OrganizationDto org = db.organizations().insert(); underTest.associate(dbSession, Uuids.createFast(), org, qgate); assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())).isNotNull(); assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())) .extracting(QGateWithOrgDto::getId, QGateWithOrgDto::getUuid, QGateWithOrgDto::getOrganizationUuid, QGateWithOrgDto::getName) .containsExactly(qgate.getId(), qgate.getUuid(), org.getUuid(), qgate.getName()); }
@Test public void selectByQuery_returns_changes_ordered_by_descending_date() { QProfileDto profile1 = db.qualityProfiles().insert(db.getDefaultOrganization()); QProfileDto profile2 = db.qualityProfiles().insert(db.getDefaultOrganization()); QProfileChangeDto change1OnP1 = insertChange(profile1, "ACTIVATED", null, null); QProfileChangeDto change2OnP1 = insertChange(profile1, "ACTIVATED", null, null); QProfileChangeDto changeOnP2 = insertChange(profile2, "ACTIVATED", null, null); List<QProfileChangeDto> changes = underTest.selectByQuery(dbSession, new QProfileChangeQuery(profile1.getKee())); assertThat(changes) .extracting(QProfileChangeDto::getUuid) .containsExactly(change2OnP1.getUuid(), change1OnP1.getUuid()); }
@Test public void simulate_bulk_update_key_does_not_return_disable_components() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("project")); db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module")); db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false)); db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "D").setDbKey("other-project")); Map<String, String> result = underTest.simulateBulkUpdateKey(dbSession, "A", "project", "new-project"); assertThat(result).containsOnly( entry("project", "new-project"), entry("project:enabled-module", "new-project:enabled-module")); }
@Test public void selectByQuery_filter_on_visibility() { db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("private-key")); db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("public-key")); ComponentQuery privateProjectsQuery = ComponentQuery.builder().setPrivate(true).setQualifiers(PROJECT).build(); ComponentQuery publicProjectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build(); ComponentQuery allProjectsQuery = ComponentQuery.builder().setPrivate(null).setQualifiers(PROJECT).build(); assertThat(underTest.selectByQuery(dbSession, privateProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsExactly("private-key"); assertThat(underTest.selectByQuery(dbSession, publicProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsExactly("public-key"); assertThat(underTest.selectByQuery(dbSession, allProjectsQuery, 0, 10)).extracting(ComponentDto::getDbKey).containsOnly("public-key", "private-key"); }
@Test public void search_activity_returns_application() { ComponentDto apacheApp = db.components().insertApplication(db.getDefaultOrganization(), a -> a.setName("Apache App")); db.components().insertSnapshot(apacheApp); logInAsSystemAdministrator(); insertActivity("T2", apacheApp, SUCCESS); ActivityResponse activityResponse = call(ws.newRequest().setParam(PARAM_COMPONENT_QUERY, "apac")); assertThat(activityResponse.getTasksList()).extracting(Task::getId).containsOnly("T2"); }
@Test public void should_add_group_permission_to_template() { PermissionTemplateDto permissionTemplate = templateDb.insertTemplate(db.getDefaultOrganization()); GroupDto group = db.users().insertGroup(); underTest.insertGroupPermission(dbSession, permissionTemplate.getId(), group.getId(), "user"); dbSession.commit(); assertThat(db.getDbClient().permissionTemplateDao().selectGroupPermissionsByTemplateId(db.getSession(), permissionTemplate.getId())) .extracting(PermissionTemplateGroupDto::getTemplateId, PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission, PermissionTemplateGroupDto::getCreatedAt, PermissionTemplateGroupDto::getUpdatedAt) .containsOnly(tuple(permissionTemplate.getId(), group.getId(), "user", NOW, NOW)); }
@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 fail_if_component_is_removed() { userSession.logIn().setRoot(); ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization())); db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); expectedException.expect(NotFoundException.class); expectedException.expectMessage("Component key 'file-key' not found"); newRequest(null, "file-key"); }