public void insert(DbSession session, Collection<SnapshotDto> items) { for (SnapshotDto item : items) { insert(session, item); } }
public SnapshotDto insertSnapshot(SnapshotDto snapshotDto) { SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, snapshotDto); db.commit(); return snapshot; }
public SnapshotDto insertSnapshot(ComponentDto componentDto, Consumer<SnapshotDto> consumer) { SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(componentDto); consumer.accept(snapshotDto); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, snapshotDto); db.commit(); return snapshot; }
private SnapshotDto createProjectSnapshot(ComponentDto project) { SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project); dbClient.snapshotDao().insert(dbSession, projectSnapshot); dbSession.commit(); return projectSnapshot; }
private SnapshotDto insertSnapshot(SnapshotDto snapshot) { dbClient.snapshotDao().insert(dbTester.getSession(), snapshot); dbTester.getSession().commit(); return snapshot; }
@Test public void do_not_return_unprocessed_analyses() { dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setStatus(STATUS_UNPROCESSED)); db.commit(); SearchHistoryResponse result = call(); // one analysis in setUp method assertThat(result.getPaging().getTotal()).isEqualTo(1); }
private SnapshotDto insertComponentAndSnapshot(ComponentDto component) { dbClient.componentDao().insert(dbSession, component); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(component)); db.commit(); return snapshot; }
private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) { SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid)) .setLast(isLastFlag) .setStatus(status) .setUuid(uuid); underTest.insert(db.getSession(), snapshot); return snapshot; }
private void insertAnalysis(ComponentDto project, String uuid, String status, boolean isLastFlag) { SnapshotDto snapshot = SnapshotTesting.newAnalysis(project) .setLast(isLastFlag) .setStatus(status) .setUuid(uuid); db.getDbClient().snapshotDao().insert(db.getSession(), snapshot); } }
private void insertPeriod(ComponentDto componentDto, long date) { SnapshotDto dto = new SnapshotDto(); dto.setUuid("uuid"); dto.setLast(true); dto.setPeriodDate(date); dto.setComponentUuid(componentDto.uuid()); snapshotDao.insert(db.getSession(), dto); } }
@Test public void return_project_without_analysis() { ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert())); dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false)); dbSession.commit(); Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById(); assertThat(docsById).hasSize(1); ProjectMeasures doc = docsById.get(project.uuid()); assertThat(doc.getProject().getAnalysisDate()).isNull(); }
@Test public void insert_snapshots() { ComponentDto project = db.components().insertPrivateProject(); underTest.insert(db.getSession(), newAnalysis(project).setLast(false).setUuid("u5"), newAnalysis(project).setLast(false).setUuid("u6")); db.getSession().commit(); assertThat(db.countRowsOfTable("snapshots")).isEqualTo(2); }
@Test public void selectLastSnapshotsByRootComponentUuids_returns_snapshots_flagged_as_last() { ComponentDto firstProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1")); dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(false)); SnapshotDto lastSnapshotOfFirstProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(true)); ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2")); SnapshotDto lastSnapshotOfSecondProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(secondProject).setLast(true)); db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization())); List<SnapshotDto> result = underTest.selectLastAnalysesByRootComponentUuids(dbSession, newArrayList(firstProject.uuid(), secondProject.uuid())); assertThat(result).extracting(SnapshotDto::getId).containsOnly(lastSnapshotOfFirstProject.getId(), lastSnapshotOfSecondProject.getId()); }
private SnapshotDto insertAnalysis(String projectUuid, boolean isLast) { return db.getDbClient().snapshotDao().insert(db.getSession(), SnapshotTesting.newSnapshot() .setUuid(Uuids.createFast()) .setComponentUuid(projectUuid) .setLast(isLast)); }
@Test public void create_2_version_events_on_same_project() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert()); SnapshotDto firstAnalysis = db.components().insertProjectAndSnapshot(project); SnapshotDto secondAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); db.commit(); logInAsProjectAdministrator(project); call(VERSION.name(), "5.6.3", firstAnalysis.getUuid()); call(VERSION.name(), "6.3", secondAnalysis.getUuid()); List<EventDto> events = dbClient.eventDao().selectByComponentUuid(dbSession, project.uuid()); assertThat(events).hasSize(2); }
@Test public void fail_if_project_is_not_found() { userSession.logIn(); SnapshotDto analysis = dbClient.snapshotDao().insert(dbSession, newSnapshot().setUuid("A1")); db.commit(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Project of analysis 'A1' is not found"); call(VERSION.name(), "5.6.3", analysis.getUuid()); }
@Test public void project_user_is_allowed_to_get_project_status() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); dbSession.commit(); userSession.addProjectPermission(UserRole.USER, project); ws.newRequest() .setParam(PARAM_ANALYSIS_ID, snapshot.getUuid()) .executeProtobuf(ProjectStatusResponse.class); }
@Test public void project_administrator_is_allowed_to_get_project_status() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); dbSession.commit(); userSession.addProjectPermission(UserRole.ADMIN, project); ws.newRequest() .setParam(PARAM_ANALYSIS_ID, snapshot.getUuid()) .executeProtobuf(ProjectStatusResponse.class); }
@Test public void fail_if_insufficient_privileges() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPrivateProject(organization); SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); dbSession.commit(); userSession.logIn(); expectedException.expect(ForbiddenException.class); ws.newRequest() .setParam(PARAM_ANALYSIS_ID, snapshot.getUuid()) .executeProtobuf(ProjectStatusResponse.class); }
@Test public void not_fail_if_analysis_date_is_after_last_analysis() { ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY); dbClient.componentDao().insert(dbTester.getSession(), project); dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1420088400000L)); // 2015-01-01 dbTester.getSession().commit(); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build()); underTest.execute(new TestComputationStepContext()); }