@Test public void update_index_on_project_creation() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); IndexingResult result = indexProject(project, PROJECT_CREATION); assertThatIndexContainsOnly(project, file); // two requests (one per component) assertThat(result.getTotal()).isEqualTo(2L); assertThat(result.getSuccess()).isEqualTo(2L); }
@Test public void facet_on_projectUuids() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(organizationDto, "ABCD"); ComponentDto project2 = newPrivateProjectDto(organizationDto, "EFGH"); indexIssues( newDoc("I1", newFileDto(project, null)), newDoc("I2", newFileDto(project, null)), newDoc("I3", newFileDto(project2, null))); assertThatFacetHasExactly(IssueQuery.builder(), "projects", entry("ABCD", 2L), entry("EFGH", 1L)); }
@Test public void insert_data() { byte[] data = "text_value".getBytes(StandardCharsets.UTF_8); MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); LiveMeasureDto measure = newLiveMeasure(file, metric).setData(data); underTest.insert(db.getSession(), measure); LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found")); assertThat(new String(result.getData(), StandardCharsets.UTF_8)).isEqualTo("text_value"); assertThat(result.getDataAsString()).isEqualTo("text_value"); }
@Test public void getUuidPathLikeIncludingSelf() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto).setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); assertThat(project.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + ".%"); ComponentDto module = ComponentTesting.newModuleDto(project); assertThat(module.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + "." + module.uuid() + ".%"); ComponentDto file = ComponentTesting.newFileDto(module); assertThat(file.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + "." + module.uuid() + "." + file.uuid() + ".%"); }
@Test public void do_transition() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto rule = db.rules().insert(); IssueDto issue = db.issues().insert(rule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null)); DefaultIssue defaultIssue = issue.toDefaultIssue(); boolean result = underTest.doTransition(defaultIssue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm"); assertThat(result).isTrue(); assertThat(defaultIssue.status()).isEqualTo(STATUS_CONFIRMED); }
@Test public void facet_on_directories_return_100_entries_plus_selected_values() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(organizationDto); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, newDirectory(project, "dir" + i))).setDirectoryPath("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, newDirectory(project, "path1"))).setDirectoryPath("directory1"); IssueDoc issue2 = newDoc(newFileDto(project, newDirectory(project, "path2"))).setDirectoryPath("directory2"); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "directories", 100); assertThatFacetHasSize(IssueQuery.builder().directories(asList(issue1.directoryPath(), issue2.directoryPath())).build(), "directories", 102); }
@Test public void rule_id_is_not_set_on_updated_issue_when_rule_is_removed() { RuleDefinitionDto rule = db.rules().insert(r -> r.setStatus(REMOVED)); ComponentDto project = db.components().insertMainBranch(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto file = db.components().insertComponent(newFileDto(module)); DefaultIssue issue = newIssue(rule, project, file).toDefaultIssue(); Collection<IssueDto> results = underTest.save(db.getSession(), singletonList(issue)); assertThat(results).hasSize(1); assertThat(results.iterator().next().getRuleId()).isNull(); }
private ComponentDto randomComponent(OrganizationDto organization) { ComponentDto project = dbTester.components().insertPublicProject(organization); ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project)); ComponentDto dir = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "foo")); ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project)); ComponentDto[] components = new ComponentDto[] {project, module, dir, file}; return components[random.nextInt(components.length)]; }
@Test public void select_descendants_with_leaves_strategy() { ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID); db.components().insertProjectAndSnapshot(project); db.components().insertComponent(newModuleDto("module-1-uuid", project)); db.components().insertComponent(newFileDto(project, null, "file-1-uuid")); db.components().insertComponent(newFileDto(project, null, "file-2-uuid")); db.commit(); ComponentTreeQuery query = newTreeQuery(PROJECT_UUID).setStrategy(LEAVES).build(); List<ComponentDto> result = underTest.selectDescendants(dbSession, query); assertThat(result).extracting("uuid").containsOnly("file-1-uuid", "file-2-uuid", "module-1-uuid"); }
@Test public void indexOnAnalysis_indexes_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); underTest.indexOnAnalysis(project.uuid()); assertThatIndexContainsOnly(project, file); }
private IssueDto newIssue() { RuleDto rule = db.rules().insertRule(newRuleDto()); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); return newDto(rule, file, project); }
@Test public void filter_by_authors() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file = newFileDto(project, null); indexIssues( newDoc("I1", file).setAuthorLogin("steph"), newDoc("I2", file).setAuthorLogin("marcel"), newDoc("I3", file).setAssigneeUuid(null)); assertThatSearchReturnsOnly(IssueQuery.builder().authors(singletonList("steph")), "I1"); assertThatSearchReturnsOnly(IssueQuery.builder().authors(asList("steph", "marcel")), "I1", "I2"); assertThatSearchReturnsEmpty(IssueQuery.builder().authors(singletonList("unknown"))); }
@Test public void fail_if_user_does_not_have_permission_on_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); expectedException.expect(ForbiddenException.class); tester.newRequest().setParam("key", file.getKey()).execute(); }
@Test public void deleteProject_fails_with_IAE_if_specified_component_is_file() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(privateProject)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Couldn't find root component with uuid " + file.uuid()); underTest.deleteProject(dbSession, file.uuid()); }
@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 public void do_transition_fail_on_external_issue() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); RuleDefinitionDto externalRule = db.rules().insert(r -> r.setIsExternal(true)); IssueDto externalIssue = db.issues().insert(externalRule, project, file, i -> i.setStatus(STATUS_OPEN).setResolution(null)); DefaultIssue defaultIssue = externalIssue.toDefaultIssue(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Transition is not allowed on issues imported from external rule engines"); underTest.doTransition(defaultIssue, IssueChangeContext.createUser(new Date(), "user_uuid"), "confirm"); } }
@Test public void fail_if_component_is_removed() { userSession.logIn().setRoot(); ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization())); db.components().insertComponent(newFileDto(project).setDbKey("file-key").setEnabled(false)); expectedException.expect(NotFoundException.class); expectedException.expectMessage("Component key 'file-key' not found"); newRequest(null, "file-key"); }
@Test public void fail_if_both_componentId_and_pull_request_parameters_provided() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST)); ComponentDto file = db.components().insertComponent(newFileDto(branch)); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Parameter 'componentId' cannot be used at the same time as 'branch' or 'pullRequest'"); ws.newRequest() .setParam("uuid", file.uuid()) .setParam("pullRequest", file.getPullRequest()) .execute(); }
@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" + "}"); }
private ComponentDto insertProjectWithBranchAndRelatedData() { RuleDefinitionDto rule = db.rules().insert(); ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); ComponentDto subModule = db.components().insertComponent(newModuleDto(module)); ComponentDto file = db.components().insertComponent(newFileDto(subModule)); db.issues().insert(rule, branch, file); db.issues().insert(rule, branch, subModule); db.issues().insert(rule, branch, module); return project; }