@Test public void index_application_on_startup() { ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); underTest.indexOnStartup(emptySet()); 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 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 selectRootAndModulesOrSubviewsByProjectUuid_returns_application_with_specified_uuid() { ComponentDto view = db.components().insertApplication(db.getDefaultOrganization()); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid())) .extracting(IdUuidPair::getUuid) .containsOnly(view.uuid()); }
@Test public void search_application_without_projects() { ComponentDto project = db.components().insertPublicProject(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, project); allowAnyoneOnProjects(project, application); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).isEmpty(); }
@Test public void application_search_project_issues_on_leak() { Date now = new Date(); ComponentDto project1 = db.components().insertPublicProject(); SnapshotDto analysis1 = db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime())); ComponentDto project2 = db.components().insertPublicProject(); SnapshotDto analysis2 = db.components().insertSnapshot(project2, s -> s.setPeriodDate(null)); ComponentDto project3 = db.components().insertPublicProject(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); db.components().insertComponents(newProjectCopy("PC1", project1, application)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); db.components().insertComponents(newProjectCopy("PC3", project3, application)); userSession.registerComponents(application, project1, project2, project3); IssueQuery result = underTest.create(new SearchRequest() .setComponentUuids(singletonList(application.uuid())) .setSinceLeakPeriod(true)); assertThat(result.createdAfterByProjectUuids()).hasSize(1); assertThat(result.createdAfterByProjectUuids().get(project1.uuid()).date().getTime()).isEqualTo(analysis1.getPeriodDate()); assertThat(result.createdAfterByProjectUuids().get(project1.uuid()).inclusive()).isFalse(); assertThat(result.viewUuids()).containsExactlyInAnyOrder(application.uuid()); }
@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 ignore_application_without_browse_permission() { ComponentDto project = db.components().insertPublicProject(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); db.components().insertComponents(newProjectCopy("PC1", project, application)); RuleDefinitionDto rule = db.rules().insert(); db.issues().insert(rule, project, project); allowAnyoneOnProjects(project); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).isEmpty(); }
@Test public void application_search_project_issues() { ComponentDto project1 = db.components().insertPublicProject(); ComponentDto project2 = db.components().insertPublicProject(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); db.components().insertComponents(newProjectCopy("PC1", project1, application)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); userSession.registerComponents(application, project1, project2); IssueQuery result = underTest.create(new SearchRequest().setComponentUuids(singletonList(application.uuid()))); assertThat(result.viewUuids()).containsExactlyInAnyOrder(application.uuid()); }
@Test public void execute_fails_with_BadRequestException_if_specified_component_is_neither_a_project_a_portfolio_nor_an_application() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = randomPublicOrPrivateProject(); ComponentDto module = ComponentTesting.newModuleDto(project); ComponentDto dir = ComponentTesting.newDirectory(project, "path"); ComponentDto file = ComponentTesting.newFileDto(project); dbTester.components().insertComponents(module, dir, file); ComponentDto application = dbTester.components().insertApplication(organization); ComponentDto portfolio = dbTester.components().insertView(organization); ComponentDto subView = ComponentTesting.newSubView(portfolio); ComponentDto projectCopy = newProjectCopy("foo", project, subView); dbTester.components().insertComponents(subView, projectCopy); userSessionRule.addProjectPermission(UserRole.ADMIN, project, portfolio, application); Stream.of(project, portfolio, application).forEach(c -> request .setParam(PARAM_PROJECT, c.getDbKey()) .setParam(PARAM_VISIBILITY, randomVisibility) .execute()); Stream.of(module, dir, file, subView, projectCopy) .forEach(nonRootComponent -> { request.setParam(PARAM_PROJECT, nonRootComponent.getDbKey()) .setParam(PARAM_VISIBILITY, randomVisibility); try { request.execute(); fail("a BadRequestException should have been raised"); } catch (BadRequestException e) { assertThat(e.getMessage()).isEqualTo("Component must be a project, a portfolio or an application"); } }); }
@Test public void select_views_and_sub_views_and_applications() { OrganizationDto organization = db.organizations().insert(); db.components().insertView(organization, "ABCD"); db.components().insertView(organization, "IJKL"); ComponentDto view = db.components().insertView(organization, "EFGH"); db.components().insertSubView(view, dto -> dto.setUuid("FGHI")); ComponentDto application = db.components().insertApplication(organization); assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid) .containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL", application.uuid()); assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getProjectUuid) .containsExactlyInAnyOrder("ABCD", "EFGH", "EFGH", "IJKL", application.projectUuid()); }
@Before public void setUp() { organization = dbTester.organizations().insert(); publicProject = componentDbTester.insertPublicProject(organization); privateProject1 = componentDbTester.insertPrivateProject(organization); privateProject2 = componentDbTester.insertPrivateProject(organization); view1 = componentDbTester.insertView(organization); view2 = componentDbTester.insertView(organization); application = componentDbTester.insertApplication(organization); user1 = userDbTester.insertUser(); user2 = userDbTester.insertUser(); group = userDbTester.insertGroup(organization); }
@Test public void apply_project_default_template_on_application_when_no_application_default_template() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto application = dbTester.components().insertApplication(organization); PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization); GroupDto group = dbTester.users().insertGroup(organization); dbTester.permissionTemplates().addGroupToTemplate(projectPermissionTemplate, group, PROVISION_PROJECTS.getKey()); dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), null, null); underTest.applyDefault(session, organization.getUuid(), application, null); assertThat(selectProjectPermissionsOfGroup(organization, group, application)).containsOnly(PROVISION_PROJECTS.getKey()); }
@Test public void apply_template_on_applications() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto application = dbTester.components().insertApplication(organization); PermissionTemplateDto permissionTemplate = dbTester.permissionTemplates().insertTemplate(organization); GroupDto group = dbTester.users().insertGroup(organization); dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, ADMINISTER.getKey()); dbTester.permissionTemplates().addGroupToTemplate(permissionTemplate, group, PROVISION_PROJECTS.getKey()); dbTester.organizations().setDefaultTemplates(organization, permissionTemplate.getUuid(), null, null); underTest.applyDefault(session, organization.getUuid(), application, null); assertThat(selectProjectPermissionsOfGroup(organization, group, application)) .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey()); }
@Test public void apply_default_view_template_on_application() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto application = dbTester.components().insertApplication(organization); PermissionTemplateDto projectPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization); PermissionTemplateDto appPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization); PermissionTemplateDto portPermissionTemplate = dbTester.permissionTemplates().insertTemplate(organization); GroupDto group = dbTester.users().insertGroup(organization); dbTester.permissionTemplates().addGroupToTemplate(appPermissionTemplate, group, ADMINISTER.getKey()); dbTester.permissionTemplates().addGroupToTemplate(appPermissionTemplate, group, PROVISION_PROJECTS.getKey()); dbTester.organizations().setDefaultTemplates(organization, projectPermissionTemplate.getUuid(), appPermissionTemplate.getUuid(), portPermissionTemplate.getUuid()); underTest.applyDefault(session, organization.getUuid(), application, null); assertThat(selectProjectPermissionsOfGroup(organization, group, application)) .containsOnly(ADMINISTER.getKey(), PROVISION_PROJECTS.getKey()); }
@Test public void should_only_provide_project_for_certain_qualifiers() { String query = randomAlphabetic(10); ComponentDto app = db.components().insertApplication(organization, v -> v.setName(query)); ComponentDto view = db.components().insertView(organization, v -> v.setName(query)); ComponentDto subView = db.components().insertComponent(ComponentTesting.newSubView(view).setName(query)); ComponentDto project = db.components().insertPrivateProject(organization, p -> p.setName(query)); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project).setName(query)); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query)); ComponentDto test = db.components().insertComponent(ComponentTesting.newFileDto(module).setName(query).setQualifier(Qualifiers.UNIT_TEST_FILE)); componentIndexer.indexOnStartup(null); authorizationIndexerTester.allowOnlyAnyone(project); authorizationIndexerTester.allowOnlyAnyone(view); authorizationIndexerTester.allowOnlyAnyone(app); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") .setParam(PARAM_QUERY, project.name()) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) .extracting(Category::getQ, c -> c.getItemsList().stream().map(Suggestion::hasProject).findFirst().orElse(null)) .containsExactlyInAnyOrder( tuple(SuggestionCategory.APP.getName(), false), tuple(SuggestionCategory.VIEW.getName(), false), tuple(SuggestionCategory.SUBVIEW.getName(), false), tuple(SuggestionCategory.PROJECT.getName(), false), tuple(SuggestionCategory.FILE.getName(), true), tuple(SuggestionCategory.UNIT_TEST_FILE.getName(), true)); }
@Test public void select_projects_by_organization() { OrganizationDto organization = db.organizations().insert(); ComponentDto project1 = db.components().insertPrivateProject(organization); ComponentDto module = db.components().insertComponent(newModuleDto(project1)); ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); ComponentDto file = db.components().insertComponent(newFileDto(module, directory)); ComponentDto project2 = db.components().insertPrivateProject(organization); ComponentDto view = db.components().insertView(organization); ComponentDto application = db.components().insertApplication(organization); OrganizationDto otherOrganization = db.organizations().insert(); ComponentDto projectOnOtherOrganization = db.components().insertPrivateProject(otherOrganization); assertThat(underTest.selectProjectsByOrganization(dbSession, organization.getUuid())) .extracting(ComponentDto::uuid) .containsExactlyInAnyOrder(project1.uuid(), project2.uuid()) .doesNotContain(view.uuid(), application.uuid()); }
@Test public void search_by_application_and_by_leak() { Date now = new Date(); RuleDefinitionDto rule = db.rules().insert(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); // Project 1 ComponentDto project1 = db.components().insertPublicProject(); db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime())); db.components().insertComponents(newProjectCopy("PC1", project1, application)); IssueDto project1Issue1 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10))); IssueDto project1Issue2 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20))); // Project 2 ComponentDto project2 = db.components().insertPublicProject(); db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime())); db.components().insertComponents(newProjectCopy("PC2", project2, application)); IssueDto project2Issue1 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15))); IssueDto project2Issue2 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30))); // Permissions and index allowAnyoneOnProjects(project1, project2, application); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issue::getKey) .containsExactlyInAnyOrder(project1Issue1.getKey(), project2Issue1.getKey()) .doesNotContain(project1Issue2.getKey(), project2Issue2.getKey()); }
@Test public void search_by_application_and_project_and_leak() { Date now = new Date(); RuleDefinitionDto rule = db.rules().insert(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); // Project 1 ComponentDto project1 = db.components().insertPublicProject(); db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime())); db.components().insertComponents(newProjectCopy("PC1", project1, application)); IssueDto project1Issue1 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10))); IssueDto project1Issue2 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20))); // Project 2 ComponentDto project2 = db.components().insertPublicProject(); db.components().insertSnapshot(project2, s -> s.setPeriodDate(addDays(now, -25).getTime())); db.components().insertComponents(newProjectCopy("PC2", project2, application)); IssueDto project2Issue1 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15))); IssueDto project2Issue2 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30))); // Permissions and index allowAnyoneOnProjects(project1, project2, application); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) .setParam(PARAM_PROJECT_KEYS, project1.getDbKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issue::getKey) .containsExactlyInAnyOrder(project1Issue1.getKey()) .doesNotContain(project1Issue2.getKey(), project2Issue1.getKey(), project2Issue2.getKey()); }
@Test public void search_by_application_and_project() { ComponentDto project1 = db.components().insertPublicProject(); ComponentDto project2 = db.components().insertPublicProject(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); db.components().insertComponents(newProjectCopy("PC1", project1, application)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); RuleDefinitionDto rule = db.rules().insert(); IssueDto issue1 = db.issues().insert(rule, project1, project1); IssueDto issue2 = db.issues().insert(rule, project2, project2); allowAnyoneOnProjects(project1, project2, application); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) .setParam(PARAM_PROJECT_KEYS, project1.getDbKey()) .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issue::getKey) .containsExactlyInAnyOrder(issue1.getKey()) .doesNotContain(issue2.getKey()); }
@Test public void search_by_application_and_by_leak_when_one_project_has_no_leak() { Date now = new Date(); RuleDefinitionDto rule = db.rules().insert(); ComponentDto application = db.components().insertApplication(db.getDefaultOrganization()); // Project 1 ComponentDto project1 = db.components().insertPublicProject(); db.components().insertSnapshot(project1, s -> s.setPeriodDate(addDays(now, -14).getTime())); db.components().insertComponents(newProjectCopy("PC1", project1, application)); IssueDto project1Issue1 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -10))); IssueDto project1Issue2 = db.issues().insert(rule, project1, project1, i -> i.setIssueCreationDate(addDays(now, -20))); // Project 2, without leak => no issue form it should be returned ComponentDto project2 = db.components().insertPublicProject(); db.components().insertSnapshot(project2, s -> s.setPeriodDate(null)); db.components().insertComponents(newProjectCopy("PC2", project2, application)); IssueDto project2Issue1 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -15))); IssueDto project2Issue2 = db.issues().insert(rule, project2, project2, i -> i.setIssueCreationDate(addDays(now, -30))); // Permissions and index allowAnyoneOnProjects(project1, project2, application); indexIssuesAndViews(); SearchWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, application.getDbKey()) .setParam(PARAM_SINCE_LEAK_PERIOD, "true") .executeProtobuf(SearchWsResponse.class); assertThat(result.getIssuesList()).extracting(Issue::getKey) .containsExactlyInAnyOrder(project1Issue1.getKey()) .doesNotContain(project1Issue2.getKey(), project2Issue1.getKey(), project2Issue2.getKey()); }