public IssueDto setComponent(ComponentDto component) { this.componentKey = component.getDbKey(); this.componentUuid = component.uuid(); this.moduleUuid = component.moduleUuid(); this.moduleUuidPath = component.moduleUuidPath(); this.filePath = component.path(); return this; }
@Test public void get_by_key_on_a_root_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto result = underTest.selectOrFailByKey(dbSession, project.getDbKey()); assertThat(result.getDbKey()).isEqualTo(project.getDbKey()); assertThat(result.uuid()).isEqualTo(project.uuid()); assertThat(result.getUuidPath()).isEqualTo(project.getUuidPath()); assertThat(result.getRootUuid()).isEqualTo(project.uuid()); assertThat(result.projectUuid()).isEqualTo(project.uuid()); }
@Test public void should_support_db_key() { when(branch.getMergeBranchUuid()).thenReturn(Optional.of(mergeBranch.uuid())); assertThat(underTest.getUuid(branchFile.getDbKey())).isEqualTo(mergeBranchFile.uuid()); }
@Test public void get_by_keys() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); List<ComponentDto> results = underTest.selectByKeys(dbSession, asList(project1.getDbKey(), project2.getDbKey())); assertThat(results) .extracting(ComponentDto::uuid, ComponentDto::getDbKey) .containsExactlyInAnyOrder( tuple(project1.uuid(), project1.getDbKey()), tuple(project2.uuid(), project2.getDbKey())); assertThat(underTest.selectByKeys(dbSession, singletonList("unknown"))).isEmpty(); }
@Test public void fail_to_getByUuidOrKey_when_using_branch_key() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey())); underTest.getByUuidOrKey(dbSession, null, branch.getDbKey(), ID_AND_KEY); }
@Test public void fail_when_using_branch_db_key() throws Exception { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(format("Component key '%s' not found", branch.getDbKey())); call(NOTIF_MY_NEW_ISSUES, null, branch.getDbKey(), null); }
@Test public void fail_if_old_key_and_new_key_are_the_same() { ComponentDto project = insertSampleRootProject(); ComponentDto anotherProject = componentDb.insertPrivateProject(); logInAsProjectAdministrator(project); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Impossible to update key: a component with key \"" + anotherProject.getDbKey() + "\" already exists."); underTest.updateKey(dbSession, project, anotherProject.getDbKey()); }
@Test public void get_by_ids() { ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); List<ComponentDto> results = underTest.selectByIds(dbSession, asList(project1.getId(), project2.getId())); assertThat(results) .extracting(ComponentDto::uuid, ComponentDto::getDbKey) .containsExactlyInAnyOrder( tuple(project1.uuid(), project1.getDbKey()), tuple(project2.uuid(), project2.getDbKey())); assertThat(underTest.selectByIds(dbSession, singletonList(0L))).isEmpty(); }
@Test public void fail_when_using_branch_db_key() { ComponentDto project = db.components().insertMainBranch(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey())); ws.newRequest() .setParam(PARAM_COMPONENT, branch.getDbKey()) .executeProtobuf(ShowWsResponse.class); }
@Test public void fail_when_using_branch_db_key() { ComponentDto project = db.components().insertMainBranch(); userSession.addProjectPermission(UserRole.USER, project); ComponentDto branch = db.components().insertProjectBranch(project); expectedException.expect(NotFoundException.class); expectedException.expectMessage(String.format("Component key '%s' not found", branch.getDbKey())); ws.newRequest() .setParam(PARAM_COMPONENT, branch.getDbKey()) .executeProtobuf(Components.ShowWsResponse.class); }
@Test public void fail_if_file() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); userSession.addProjectPermission(UserRole.USER, project); MetricDto metric = db.measures().insertMetric(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Only component of qualifiers [TRK, APP, VW, SVW] are allowed"); call(singletonList(file.getDbKey()), singletonList(metric.getKey())); }
@Test public void fail_when_new_key_is_invalid() { ComponentDto project = db.components().insertPrivateProject(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Malformed key for 'my?project?key'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit."); underTest.bulkUpdateKey(dbSession, project.uuid(), project.getDbKey(), "my?project?key", doNotReturnAnyRekeyedResource()); }
private static ProjectMeasuresDoc newDoc(ComponentDto project) { return new ProjectMeasuresDoc() .setOrganizationUuid(project.getOrganizationUuid()) .setId(project.uuid()) .setKey(project.getDbKey()) .setName(project.name()); }
@Test public void suggestions_without_query_should_not_contain_recently_browsed_without_permission() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); componentIndexer.indexOnStartup(null); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") .setParam(PARAM_RECENTLY_BROWSED, project.getDbKey()) .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .isEmpty(); }
@Test public void fail_if_component_uuid_and_key_are_provided() { ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert()); db.components().insertComponent(project); expectedException.expect(IllegalArgumentException.class); callByComponentUuidOrComponentKey(project.uuid(), project.getDbKey()); }
@Test public void filter_projects_by_coverage() { userSession.logIn(); OrganizationDto organizationDto = db.organizations().insert(); MetricDto coverage = db.measures().insertMetric(c -> c.setKey(COVERAGE).setValueType("PERCENT")); ComponentDto project1 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(80d))); ComponentDto project2 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(85d))); ComponentDto project3 = insertProject(organizationDto, new Measure(coverage, c -> c.setValue(10d))); SearchProjectsWsResponse result = call(request.setFilter("coverage <= 80")); assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project3.getDbKey()); }
@Test public void fail_if_user_is_not_allowed_to_access_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); expectedException.expect(ForbiddenException.class); newBaseRequest().setParam("key", file.getDbKey()).execute(); }
@Test @UseDataProvider("rating_metric_keys") public void filter_projects_by_rating(String metricKey) { userSession.logIn(); OrganizationDto organizationDto = db.organizations().insert(); MetricDto ratingMetric = db.measures().insertMetric(c -> c.setKey(metricKey).setValueType(INT.name())); ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(1d))); ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(2d))); ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setValue(3d))); SearchProjectsWsResponse result = call(request.setFilter(metricKey + " = 2")); assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getDbKey()); }
@Test @UseDataProvider("new_rating_metric_keys") public void filter_projects_by_new_rating(String newMetricKey) { userSession.logIn(); OrganizationDto organizationDto = db.organizations().insert(); MetricDto ratingMetric = db.measures().insertMetric(c -> c.setKey(newMetricKey).setValueType(INT.name())); ComponentDto project1 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(1d))); ComponentDto project2 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(2d))); ComponentDto project3 = insertProject(organizationDto, new Measure(ratingMetric, c -> c.setVariation(3d))); SearchProjectsWsResponse result = call(request.setFilter(newMetricKey + " = 2")); assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(project2.getDbKey()); }
@Test public void return_file_with_missing_duplication_data() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project).setDbKey("foo.js")); db.components().insertSnapshot(newAnalysis(project)); userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project); TestResponse result = newBaseRequest().setParam("key", file.getDbKey()).execute(); assertJson(result.getInput()).isSimilarTo("{\n" + " \"duplications\": [],\n" + " \"files\": {}\n" + "}"); }