public static ComponentDto newProjectCopy(ComponentDto project, ComponentDto view) { return newProjectCopy(Uuids.createFast(), project, view); }
@SafeVarargs private final ComponentDto insertProjectCopy(ComponentDto view, ComponentDto project, Consumer<ComponentDto>... decorators) { ComponentDto component = ComponentTesting.newProjectCopy(project, view); Arrays.stream(decorators).forEach(decorator -> decorator.accept(component)); return db.components().insertComponent(component); }
private ComponentDto insertProjectInView(ComponentDto project, ComponentDto view) { return db.components().insertComponent(newProjectCopy("project-in-view-uuid", project, view)); }
@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_does_not_return_technicalCopy_with_specified_uuid() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto view = db.components().insertView(); ComponentDto technicalCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(technicalCopy.uuid())) .isEmpty(); } }
@Test public void return_projects_composing_a_view() { ComponentDto project = newPrivateProjectDto(db.organizations().insert(), "project-uuid"); db.components().insertProjectAndSnapshot(project); ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid"); db.components().insertViewAndSnapshot(view); db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); userSession.logIn() .registerComponents(project, view); TreeWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT_ID, view.uuid()).executeProtobuf(TreeWsResponse.class); assertThat(response.getBaseComponent().getId()).isEqualTo(view.uuid()); assertThat(response.getComponentsCount()).isEqualTo(1); assertThat(response.getComponents(0).getId()).isEqualTo("project-copy-uuid"); assertThat(response.getComponents(0).getRefId()).isEqualTo("project-uuid"); }
@Test public void search_by_application_key() { ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); db.components().insertComponents(newProjectCopy(project1, application)); db.components().insertComponents(newProjectCopy(project2, application)); userSession.addProjectPermission(USER, application); assertThat(underTest.create(new SearchRequest() .setComponentKeys(singletonList(application.getKey()))) .viewUuids()).containsExactly(application.uuid()); }
@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 fail_for_property_without_definition_when_set_on_projectCopy_component() { ComponentDto view = db.components().insertView(); ComponentDto projectCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", db.components().insertPrivateProject(), view)); failForPropertyWithoutDefinitionOnUnsupportedComponent(view, projectCopy); }
@Test public void fail_for_property_without_definition_when_set_on_projectCopy_component() { ComponentDto view = db.components().insertView(); ComponentDto projectCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", db.components().insertPrivateProject(), view)); failForPropertyWithoutDefinitionOnUnsupportedComponent(view, projectCopy); }
@Test public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_project_copy_with_specified_project_uuid() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto view = db.components().insertView(); db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid())) .extracting(IdUuidPair::getUuid) .containsOnly(view.uuid()); }
@Test public void reference_uuid_in_the_response() { userSession.logIn().setRoot(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto view = db.components().insertView(); db.components().insertSnapshot(view); ComponentDto projectCopy = db.components().insertComponent(newProjectCopy("project-uuid-copy", project, view)); MetricDto metric = db.measures().insertMetric(m -> m.setValueType("INT")); ComponentWsResponse response = newRequest(projectCopy.getKey(), metric.getKey()); assertThat(response.getComponent().getRefId()).isEqualTo(project.uuid()); assertThat(response.getComponent().getRefKey()).isEqualTo(project.getKey()); }
@Test public void deleteNonRootComponents_deletes_measures_of_any_non_root_component_of_a_view() { ComponentDto view = db.components().insertView(); ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view)); insertMeasureFor(view, subview, pc); assertThat(getComponentUuidsOfMeasures()).containsOnly(view.uuid(), subview.uuid(), pc.uuid()); underTest.deleteNonRootComponentsInView(dbSession, singletonList(pc)); assertThat(getComponentUuidsOfMeasures()) .containsOnly(view.uuid(), subview.uuid()); underTest.deleteNonRootComponentsInView(dbSession, singletonList(subview)); assertThat(getComponentUuidsOfMeasures()) .containsOnly(view.uuid()); }
@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 deleteNonRootComponentsInView_deletes_manual_measures_of_subviews_of_a_view() { ComponentDto view = db.components().insertView(); ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1)); ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view)); insertManualMeasureFor(view, subview1, subview2, subview3, pc); assertThat(getComponentUuidsOfManualMeasures()).containsOnly(view.uuid(), subview1.uuid(), subview2.uuid(), subview3.uuid(), pc.uuid()); underTest.deleteNonRootComponentsInView(dbSession, singletonList(subview1)); assertThat(getComponentUuidsOfManualMeasures()) .containsOnly(view.uuid(), subview2.uuid(), subview3.uuid(), pc.uuid()); underTest.deleteNonRootComponentsInView(dbSession, asList(subview2, subview3, pc)); assertThat(getComponentUuidsOfManualMeasures()) .containsOnly(view.uuid(), pc.uuid()); }
@Test public void deleteNonRootComponents_deletes_properties_of_subviews_of_a_view() { ComponentDto view = db.components().insertView(); ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1)); ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view)); ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view)); insertPropertyFor(view, subview1, subview2, subview3, pc); assertThat(getResourceIdOfProperties()).containsOnly(view.getId(), subview1.getId(), subview2.getId(), subview3.getId(), pc.getId()); underTest.deleteNonRootComponentsInView(dbSession, singletonList(subview1)); assertThat(getResourceIdOfProperties()) .containsOnly(view.getId(), subview2.getId(), subview3.getId(), pc.getId()); underTest.deleteNonRootComponentsInView(dbSession, asList(subview2, subview3, pc)); assertThat(getResourceIdOfProperties()) .containsOnly(view.getId(), pc.getId()); }
@Test public void select_descendants_of_a_view_and_filter_by_name() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto view = newView(organizationDto, A_VIEW_UUID); db.components().insertViewAndSnapshot(view); // one subview ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name"); db.components().insertComponent(subView); // one project and its copy linked to the view ComponentDto project = newPrivateProjectDto(organizationDto, PROJECT_UUID).setName("project name"); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view)); ComponentTreeQuery dbQuery = newTreeQuery(A_VIEW_UUID).setNameOrKeyQuery("name").setStrategy(CHILDREN).build(); List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery); assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid"); assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid()); }
@Test public void project_reference_from_portfolio() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto view = db.components().insertPrivatePortfolio(db.getDefaultOrganization()); SnapshotDto viewAnalysis = db.components().insertSnapshot(view); ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, view)); MetricDto ncloc = insertNclocMetric(); db.measures().insertLiveMeasure(projectCopy, ncloc, m -> m.setValue(5d)); ComponentTreeWsResponse result = ws.newRequest() .setParam(PARAM_COMPONENT, view.getKey()) .setParam(PARAM_METRIC_KEYS, ncloc.getKey()) .executeProtobuf(ComponentTreeWsResponse.class); assertThat(result.getComponentsList()) .extracting(Component::getKey, Component::getRefId, Component::getRefKey) .containsExactlyInAnyOrder(tuple(projectCopy.getKey(), project.uuid(), project.getKey())); }
@Test public void search_by_view_uuid() { ComponentDto project = db.components().insertPublicProject(p -> p.setDbKey("PK1")); ComponentDto file = db.components().insertComponent(newFileDto(project, null, "F1").setDbKey("FK1")); ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "V1").setDbKey("MyView")); db.components().insertComponent(newProjectCopy(project, view)); RuleDefinitionDto rule = db.rules().insert(r -> r.setRuleKey(RuleKey.of("xoo", "x1"))); db.issues().insert(rule, project, file, i -> i.setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); allowAnyoneOnProjects(project, view); indexIssuesAndViews(); ws.newRequest() .setParam(PARAM_COMPONENT_KEYS, view.getKey()) .execute() .assertJson(this.getClass(), "search_by_view_uuid.json"); }