/** * Insert an {@link OrganizationDto} and commit the session */ public OrganizationDto insert() { return insert(OrganizationTesting.newOrganizationDto()); }
@Test public void formatUuidPathFromParent() { ComponentDto parent = ComponentTesting.newPrivateProjectDto(newOrganizationDto(), "123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT); assertThat(ComponentDto.formatUuidPathFromParent(parent)).isEqualTo(".123."); }
@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 context_contains_project_uuid_from_analysis_metada_holder() { Project project = Project.from(newPrivateProjectDto(newOrganizationDto())); analysisMetadataHolder.setProject(project); PostMeasuresComputationCheck check = mock(PostMeasuresComputationCheck.class); newStep(check).execute(new TestComputationStepContext()); ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class); verify(check).onCheck(contextArgumentCaptor.capture()); assertThat(contextArgumentCaptor.getValue().getProjectUuid()).isEqualTo(project.getUuid()); }
@Test public void list_authors_escapes_regexp_special_characters() { OrganizationDto org = newOrganizationDto(); ComponentDto project = newPrivateProjectDto(org); indexIssues( newDoc("issue1", project).setAuthorLogin("name++")); IssueQuery query = IssueQuery.builder().build(); assertThat(underTest.searchAuthors(query, "invalidRegexp[", 5)).isEmpty(); assertThat(underTest.searchAuthors(query, "nam+", 5)).isEmpty(); assertThat(underTest.searchAuthors(query, "name+", 5)).containsExactly("name++"); assertThat(underTest.searchAuthors(query, ".*", 5)).isEmpty(); }
@Test public void test_getUuidPath() { assertThat(MeasureTreeQuery.builder().setStrategy(CHILDREN) .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID."); assertThat(MeasureTreeQuery.builder().setStrategy(LEAVES) .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%"); }
@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 should_not_selectByLanguage_in_wrong_organization() { QProfileDto profile = QualityProfileTesting.newQualityProfileDto() .setOrganizationUuid(organization.getUuid()); underTest.insert(dbSession, profile); List<QProfileDto> results = underTest.selectByLanguage(dbSession, OrganizationTesting.newOrganizationDto(), profile.getLanguage()); assertThat(results).isEmpty(); }
@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 filter_by_statuses() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file = newFileDto(project, null); indexIssues( newDoc("I1", file).setStatus(Issue.STATUS_CLOSED), newDoc("I2", file).setStatus(Issue.STATUS_OPEN)); assertThatSearchReturnsOnly(IssueQuery.builder().statuses(asList(Issue.STATUS_CLOSED, Issue.STATUS_OPEN)), "I1", "I2"); assertThatSearchReturnsOnly(IssueQuery.builder().statuses(singletonList(Issue.STATUS_CLOSED)), "I1"); assertThatSearchReturnsEmpty(IssueQuery.builder().statuses(singletonList(Issue.STATUS_CONFIRMED))); }
@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 filter_by_severities() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file = newFileDto(project, null); indexIssues( newDoc("I1", file).setSeverity(Severity.INFO), newDoc("I2", file).setSeverity(Severity.MAJOR)); assertThatSearchReturnsOnly(IssueQuery.builder().severities(asList(Severity.INFO, Severity.MAJOR)), "I1", "I2"); assertThatSearchReturnsOnly(IssueQuery.builder().severities(singletonList(Severity.INFO)), "I1"); assertThatSearchReturnsEmpty(IssueQuery.builder().severities(singletonList(Severity.BLOCKER))); }
@Test public void filter_by_resolutions() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto file = newFileDto(project, null); indexIssues( newDoc("I1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE), newDoc("I2", file).setResolution(Issue.RESOLUTION_FIXED)); assertThatSearchReturnsOnly(IssueQuery.builder().resolutions(asList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)), "I1", "I2"); assertThatSearchReturnsOnly(IssueQuery.builder().resolutions(singletonList(Issue.RESOLUTION_FALSE_POSITIVE)), "I1"); assertThatSearchReturnsEmpty(IssueQuery.builder().resolutions(singletonList(Issue.RESOLUTION_REMOVED))); }