/** * Insert an {@link OrganizationDto} and commit the session */ public OrganizationDto insert() { return insert(OrganizationTesting.newOrganizationDto()); }
@Test public void commitAndIndex_of_module_indexes_the_project() { OrganizationDto organization = OrganizationTesting.newOrganizationDto(); ComponentDto project = ComponentTesting.newPublicProjectDto(organization); ComponentDto module = ComponentTesting.newModuleDto(project); FakeIndexers underTest = new FakeIndexers(); underTest.commitAndIndex(mock(DbSession.class), singletonList(module), Cause.PROJECT_CREATION); assertThat(underTest.calls).containsExactly(project.uuid()); }
private static RekeyedProject newUniqueRekeyedProject() { int base = counter++; Project project = Project.from(newPrivateProjectDto(newOrganizationDto())); return new RekeyedProject(project, base + "_old_key"); } }
@Test public void test_getUuidPath() { assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(CHILDREN) .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(LEAVES) .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); }
@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 filter_by_portfolios_not_having_projects() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project1 = newPrivateProjectDto(organizationDto); ComponentDto file1 = newFileDto(project1, null); indexIssues(newDoc("I2", file1)); String view1 = "ABCD"; indexView(view1, emptyList()); assertThatSearchReturnsOnly(IssueQuery.builder().viewUuids(singletonList(view1))); }
@Test public void setProject_throws_ISE_when_called_twice() { AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(); underTest.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()))); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Project has already been set"); underTest.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()))); }
@Test public void selectByKey_return_rule_even_if_organization_does_not_exist() { RuleDefinitionDto ruleDefinition = db.rules().insert(); assertThat(underTest.selectByKey(db.getSession(), OrganizationTesting.newOrganizationDto(), ruleDefinition.getKey())) .isNotEmpty(); }
@Test public void set_and_get_project() { AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(); Project project = Project.from(newPrivateProjectDto(newOrganizationDto())); underTest.setProject(project); assertThat(underTest.getProject()).isSameAs(project); }
@Test public void facet_on_projectUuids_return_100_entries_plus_selected_values() { OrganizationDto organizationDto = newOrganizationDto(); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newPrivateProjectDto(organizationDto, "a" + i))).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newPrivateProjectDto(organizationDto, "project1")); IssueDoc issue2 = newDoc(newPrivateProjectDto(organizationDto, "project2")); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "projects", 100); assertThatFacetHasSize(IssueQuery.builder().projectUuids(asList(issue1.projectUuid(), issue2.projectUuid())).build(), "projects", 102); }
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; }
@Test public void facets_on_languages() { ComponentDto project = ComponentTesting.newPrivateProjectDto(newOrganizationDto()); ComponentDto file = ComponentTesting.newFileDto(project, null); RuleKey ruleKey = RuleKey.of("repo", "X1"); indexIssues(IssueDocTesting.newDoc("I1", file).setLanguage("xoo").setEffort(10L)); Facets facets = search("languages"); assertThat(facets.getNames()).containsOnly("languages", FACET_MODE_EFFORT); assertThat(facets.get("languages")).containsOnly(entry("xoo", 10L)); assertThat(facets.get(FACET_MODE_EFFORT)).containsOnly(entry("total", 10L)); }
@Test public void facets_on_languages_return_100_entries_plus_selected_values() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(organizationDto); indexIssues(rangeClosed(1, 100).mapToObj(i -> newDoc(newFileDto(project, null)).setLanguage("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setLanguage("language1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setLanguage("language2"); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "languages", 100); assertThatFacetHasSize(IssueQuery.builder().languages(asList(issue1.language(), issue2.language())).build(), "languages", 102); }
@Test public void facets_on_authors_return_100_entries_plus_selected_values() { OrganizationDto organizationDto = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(organizationDto); indexIssues(rangeClosed(1, 110).mapToObj(i -> newDoc(newFileDto(project, null)).setAuthorLogin("a" + i)).toArray(IssueDoc[]::new)); IssueDoc issue1 = newDoc(newFileDto(project, null)).setAuthorLogin("user1"); IssueDoc issue2 = newDoc(newFileDto(project, null)).setAuthorLogin("user2"); indexIssues(issue1, issue2); assertThatFacetHasSize(IssueQuery.builder().build(), "authors", 100); assertThatFacetHasSize(IssueQuery.builder().authors(asList(issue1.authorLogin(), issue2.authorLogin())).build(), "authors", 102); }
@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 filter_by_directories() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file1 = newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo"); indexIssues( newDoc("I1", file1).setDirectoryPath("/src/main/xoo"), newDoc("I2", file2).setDirectoryPath("/")); assertThatSearchReturnsOnly(IssueQuery.builder().directories(singletonList("/src/main/xoo")), "I1"); assertThatSearchReturnsOnly(IssueQuery.builder().directories(singletonList("/")), "I2"); assertThatSearchReturnsEmpty(IssueQuery.builder().directories(singletonList("unknown"))); }
@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 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 facets_on_severities() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file = newFileDto(project, null); indexIssues( newDoc("I1", file).setSeverity(Severity.INFO), newDoc("I2", file).setSeverity(Severity.INFO), newDoc("I3", file).setSeverity(Severity.MAJOR)); assertThatFacetHasOnly(IssueQuery.builder(), "severities", entry("INFO", 2L), entry("MAJOR", 1L)); }
@Test public void facets_on_assignees() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file = newFileDto(project, null); indexIssues( newDoc("I1", file).setAssigneeUuid("steph-uuid"), newDoc("I2", file).setAssigneeUuid("marcel-uuid"), newDoc("I3", file).setAssigneeUuid("marcel-uuid"), newDoc("I4", file).setAssigneeUuid(null)); assertThatFacetHasOnly(IssueQuery.builder(), "assignees", entry("steph-uuid", 1L), entry("marcel-uuid", 2L), entry("", 1L)); }