@Test public void return_events() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("P1")); userSession.addProjectPermission(UserRole.USER, project); SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(ComponentTesting.newPrivateProjectDto(organizationDto)).setUuid("A42")); EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1")); EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2")); db.events().insertEvent(newEvent(a42)); List<Analysis> result = call("P1").getAnalysesList(); assertThat(result).hasSize(1); List<Event> events = result.get(0).getEventsList(); assertThat(events).hasSize(2); assertThat(events).extracting(Event::getKey, wsToDbCategory(), Event::getName, Event::getDescription).containsOnly( tuple(e1.getUuid(), e1.getCategory(), e1.getName(), e1.getDescription()), tuple(e2.getUuid(), e2.getCategory(), e2.getName(), e2.getDescription())); }
@Test public void branch() { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch")); SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(branch)); EventDto event = db.events().insertEvent(newEvent(analysis).setCategory(EventCategory.QUALITY_GATE.getLabel())); List<Analysis> result = call(SearchRequest.builder() .setProject(project.getKey()) .setBranch("my_branch") .build()) .getAnalysesList(); assertThat(result).extracting(Analysis::getKey).containsExactlyInAnyOrder(analysis.getUuid()); assertThat(result.get(0).getEventsList()).extracting(Event::getKey).containsExactlyInAnyOrder(event.getUuid()); }
@Test public void pull_request() { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST)); SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(branch)); EventDto event = db.events().insertEvent(newEvent(analysis).setCategory(EventCategory.QUALITY_GATE.getLabel())); List<Analysis> result = call(SearchRequest.builder() .setProject(project.getKey()) .setPullRequest("pr-123") .build()) .getAnalysesList(); assertThat(result).extracting(Analysis::getKey).containsExactlyInAnyOrder(analysis.getUuid()); assertThat(result.get(0).getEventsList()).extracting(Event::getKey).containsExactlyInAnyOrder(event.getUuid()); }