private ComponentDto insertSubviews(ComponentDto view) { ComponentDto lowestView = view; int subviewsCount1 = 1 + random.nextInt(5); for (int i = 0; i < subviewsCount1; i++) { lowestView = db.components().insertSubView(lowestView); } return lowestView; }
@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()); }
@Test public void select_projects_from_view() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto view = db.components().insertView(); db.components().insertComponent(newProjectCopy(project1, view)); ComponentDto viewWithSubView = db.components().insertView(); db.components().insertComponent(newProjectCopy(project2, viewWithSubView)); ComponentDto subView = db.components().insertSubView(viewWithSubView); db.components().insertComponent(newProjectCopy(project1, subView)); ComponentDto viewWithoutProject = db.components().insertView(); assertThat(underTest.selectProjectsFromView(dbSession, view.uuid(), view.uuid())).containsExactlyInAnyOrder(project1.uuid()); assertThat(underTest.selectProjectsFromView(dbSession, viewWithSubView.uuid(), viewWithSubView.uuid())).containsExactlyInAnyOrder(project1.uuid(), project2.uuid()); assertThat(underTest.selectProjectsFromView(dbSession, subView.uuid(), viewWithSubView.uuid())).containsExactlyInAnyOrder(project1.uuid()); assertThat(underTest.selectProjectsFromView(dbSession, viewWithoutProject.uuid(), viewWithoutProject.uuid())).isEmpty(); assertThat(underTest.selectProjectsFromView(dbSession, "Unknown", "Unknown")).isEmpty(); }
@Test public void scrollAllFilesForFileMove_ignores_non_file_and_non_ut_component_with_source() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = random.nextBoolean() ? db.components().insertPrivateProject(organization) : db.components().insertPublicProject(organization); db.fileSources().insertFileSource(project); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(project)); db.fileSources().insertFileSource(module); ComponentDto dir = db.components().insertComponent(ComponentTesting.newDirectory(module, "foo")); db.fileSources().insertFileSource(dir); ComponentAndSource file = insertFileAndSource(module, FILE); ComponentAndSource ut = insertFileAndSource(dir, UNIT_TEST_FILE); ComponentDto portfolio = random.nextBoolean() ? db.components().insertPublicPortfolio(organization) : db.components().insertPrivatePortfolio(organization); db.fileSources().insertFileSource(portfolio); ComponentDto subView = db.components().insertSubView(portfolio); db.fileSources().insertFileSource(subView); ComponentDto application = random.nextBoolean() ? db.components().insertPrivateApplication(organization) : db.components().insertPublicApplication(organization); db.fileSources().insertFileSource(application); RecordingResultHandler resultHandler = new RecordingResultHandler(); underTest.scrollAllFilesForFileMove(dbSession, project.uuid(), resultHandler); underTest.scrollAllFilesForFileMove(dbSession, portfolio.uuid(), resultHandler); underTest.scrollAllFilesForFileMove(dbSession, application.uuid(), resultHandler); assertThat(resultHandler.dtos).hasSize(2); verifyFileMoveRowDto(resultHandler, file); verifyFileMoveRowDto(resultHandler, ut); }
@Test public void create_custom_measure_on_a_sub_view() { MetricDto metric = db.measures().insertMetric(m -> m.setUserManaged(true).setValueType(BOOL.name())); OrganizationDto organization = db.organizations().insert(); ComponentDto view = db.components().insertPrivatePortfolio(organization); ComponentDto subView = db.components().insertSubView(view); UserDto user = db.users().insertUser(); userSession.logIn(user).addProjectPermission(ADMIN, view); ws.newRequest() .setParam(CreateAction.PARAM_PROJECT_ID, subView.uuid()) .setParam(CreateAction.PARAM_METRIC_ID, metric.getId().toString()) .setParam(CreateAction.PARAM_DESCRIPTION, "custom-measure-description") .setParam(CreateAction.PARAM_VALUE, "true") .execute(); assertThat(db.getDbClient().customMeasureDao().selectByMetricId(db.getSession(), metric.getId())) .extracting(CustomMeasureDto::getDescription, CustomMeasureDto::getTextValue, CustomMeasureDto::getValue, CustomMeasureDto::getComponentUuid) .containsExactlyInAnyOrder(tuple("custom-measure-description", null, 1d, subView.uuid())); }