@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()); }
@Test public void count_enabled_modules_by_project_uuid() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); db.components().insertComponent(newModuleDto(module)); ComponentDto subModule2 = newModuleDto(module); subModule2.setEnabled(false); db.components().insertComponent(subModule2); int result = underTest.countEnabledModulesByProjectUuid(dbSession, project.uuid()); assertThat(result).isEqualTo(2); }
@Test public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_module_with_specified_uuid() { ComponentDto privateProject = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject)); assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(module.uuid())) .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 show_without_ancestors_when_project() { ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newModuleDto(project)); userSession.addProjectPermission(USER, project); ShowWsResponse response = newRequest(null, project.getDbKey()); assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey()); assertThat(response.getAncestorsList()).isEmpty(); }
@Test public void should_search_in_tree_with_module_uuid() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); SearchRequest request = new SearchRequest() .setComponentUuids(asList(module.uuid())); IssueQuery query = underTest.create(request); assertThat(query.moduleRootUuids()).containsExactly(module.uuid()); assertThat(query.onComponentOnly()).isFalse(); }
@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(); }
@Test public void fail_when_component_is_a_module() { ComponentDto module = db.components().insertComponent(newModuleDto(ComponentTesting.newPrivateProjectDto(db.organizations().insert()))); failIfComponentIsNotAProjectOrView(module); }
@Test public void fail_when_component_is_a_module() { ComponentDto module = db.components().insertComponent(newModuleDto(ComponentTesting.newPrivateProjectDto(db.organizations().insert()))); failIfComponentIsNotAProjectOrView(module); }
@Test public void fail_when_component_is_a_module() { ComponentDto module = db.components().insertComponent(newModuleDto(ComponentTesting.newPrivateProjectDto(db.organizations().insert()))); failIfComponentIsNotAProjectOrView(module); }
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 get_by_key_and_pull_request() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("pr-123").setBranchType(PULL_REQUEST).setMergeBranchUuid(project.uuid())); ComponentDto module = db.components().insertComponent(newModuleDto(branch)); ComponentDto directory = db.components().insertComponent(newDirectory(module, "scr")); ComponentDto file = db.components().insertComponent(newFileDto(module)); assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, project.getKey(), null, "pr-123").uuid()).isEqualTo(branch.uuid()); assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, module.getKey(), null, "pr-123").uuid()).isEqualTo(module.uuid()); assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, file.getKey(), null, "pr-123").uuid()).isEqualTo(file.uuid()); assertThat(underTest.getByKeyAndOptionalBranchOrPullRequest(dbSession, directory.getKey(), null, "pr-123").uuid()).isEqualTo(directory.uuid()); }
@Test public void fail_if_component_is_a_module() { ComponentDto module = db.components().insertComponent(newModuleDto(project).setDbKey("MODULE_KEY")); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Component 'MODULE_KEY' is not a project"); call(module.getDbKey(), "modz"); }
@Test public void simulate_bulk_update_key_fails_if_invalid_componentKey() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "A").setDbKey("project")); db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module")); db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false)); thrown.expect(IllegalArgumentException.class); underTest.simulateBulkUpdateKey(dbSession, "A", "project", "project?"); }
@Test public void simulate_bulk_update_key_does_not_return_disable_components() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("project")); db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module")); db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false)); db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "D").setDbKey("other-project")); Map<String, String> result = underTest.simulateBulkUpdateKey(dbSession, "A", "project", "new-project"); assertThat(result).containsOnly( entry("project", "new-project"), entry("project:enabled-module", "new-project:enabled-module")); }
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; }
@Test public void show_with_ancestors_when_not_project() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto module = db.components().insertComponent(newModuleDto(project)); ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir")); ComponentDto file = db.components().insertComponent(newFileDto(directory)); userSession.addProjectPermission(USER, project); ShowWsResponse response = newRequest(null, file.getDbKey()); assertThat(response.getComponent().getKey()).isEqualTo(file.getDbKey()); assertThat(response.getAncestorsList()).extracting(Component::getKey).containsOnly(directory.getDbKey(), module.getDbKey(), project.getDbKey()); }
@Test(expected = BadRequestException.class) public void fail_on_directory_key_as_param() { ComponentDto project = insertOrganizationAndProject(); ComponentDto module = componentDbTester.insertComponent(newModuleDto("bcde", project).setDbKey("palap").setName("Palap")); ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo")); userSession.addProjectPermission(UserRole.USER, project); init(); execute(directory.getDbKey()); }
@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 return_module_values() { logInAsProjectUser(); ComponentDto module = componentDb.insertComponent(newModuleDto(project)); definitions.addComponent(PropertyDefinition.builder("property").defaultValue("default").build()); propertyDb.insertProperties( newGlobalPropertyDto().setKey("property").setValue("one"), // The property is overriding global value newComponentPropertyDto(module).setKey("property").setValue("two")); executeAndVerify(module.getDbKey(), "property", "return_module_values.json"); }