return Optional.ofNullable(mapper(session).selectProjectOrAppByKey(key));
}
- public List<ProjectDto> selectAllApplications(DbSession session){
+ public List<ProjectDto> selectAllApplications(DbSession session) {
return mapper(session).selectAllApplications();
}
return Optional.ofNullable(mapper(session).selectByUuid(uuid));
}
- public List<ProjectDto> selectByOrganizationUuid(DbSession session, String organizationUuid) {
- return mapper(session).selectByOrganizationUuid(organizationUuid);
- }
-
- public List<ProjectDto> selectProjectsByOrganizationUuid(DbSession session, String organizationUuid) {
- return mapper(session).selectProjectsByOrganizationUuid(organizationUuid);
+ public List<ProjectDto> selectAll(DbSession session) {
+ return mapper(session).selectAll();
}
public List<ProjectDto> selectByUuids(DbSession session, Set<String> uuids) {
List<ProjectDto> selectByUuids(@Param("uuids") Collection<String> uuids);
- List<ProjectDto> selectByOrganizationUuid(@Param("organizationUuid") String organizationUuid);
+ List<ProjectDto> selectAll();
void updateKey(@Param("uuid") String uuid, @Param("newKey") String newKey, @Param("updatedAt") long updatedAt);
List<ProjectDto> selectProjects();
- List<ProjectDto> selectProjectsByOrganizationUuid(String organizationUuid);
-
void updateVisibility(@Param("uuid") String uuid, @Param("isPrivate") boolean isPrivate, @Param("updatedAt") long updatedAt);
List<ProjectDto> selectAllApplications();
p.qualifier='TRK'
</select>
- <select id="selectByOrganizationUuid" parameterType="String" resultType="Project">
+ <select id="selectAll" resultType="Project">
select
<include refid="projectColumns"/>
from projects p
- where
- p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectProjectsByOrganizationUuid" parameterType="String" resultType="Project">
- select
- <include refid="projectColumns"/>
- from projects p
- where
- p.qualifier='TRK' and
- p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
</select>
<select id="selectAllApplications" resultType="Project">
import javax.annotation.Nullable;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
public class ProjectDaoTest {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = new AlwaysIncreasingSystem2(1000L);
+ private final System2 system2 = new AlwaysIncreasingSystem2(1000L);
@Rule
public DbTester db = DbTester.create(system2);
- private ProjectDao projectDao = new ProjectDao(system2);
+ private final ProjectDao projectDao = new ProjectDao(system2);
@Test
public void should_insert_and_select_by_uuid() {
}
@Test
- public void select_by_organization_uuid() {
+ public void select_all() {
ProjectDto dto1 = createProject("o1", "p1");
ProjectDto dto2 = createProject("o1", "p2");
ProjectDto dto3 = createProject("o2", "p1");
projectDao.insert(db.getSession(), dto2);
projectDao.insert(db.getSession(), dto3);
- List<ProjectDto> projectsByOrg = projectDao.selectByOrganizationUuid(db.getSession(), "org_o1");
- assertThat(projectsByOrg).hasSize(2);
- assertProject(projectsByOrg.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
- assertProject(projectsByOrg.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
+ List<ProjectDto> projectsByOrg = projectDao.selectAll(db.getSession());
+ assertThat(projectsByOrg)
+ .extracting(ProjectDto::getName, ProjectDto::getKey, ProjectDto::getOrganizationUuid, ProjectDto::getUuid, ProjectDto::getDescription,
+ ProjectDto::getTagsString, ProjectDto::isPrivate)
+ .containsExactlyInAnyOrder(
+ tuple("projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false),
+ tuple("projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2", false),
+ tuple("projectName_p1", "projectKee_o2_p1", "org_o2", "uuid_o2_p1", "desc_p1", "tag1,tag2", false));
}
@Test
import org.sonar.db.issue.IssueDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2();
- private PurgeProfiler profiler = new PurgeProfiler();
- private Random random = new Random();
- private PurgeCommands underTest = new PurgeCommands(dbTester.getSession(), profiler, system2);
+ private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2();
+ private final PurgeProfiler profiler = new PurgeProfiler();
+ private final Random random = new Random();
+ private final PurgeCommands underTest = new PurgeCommands(dbTester.getSession(), profiler, system2);
/**
* Required because there is no autogenerated keys for analysis_properties
@Test
@UseDataProvider("projects")
- public void deleteComponents_delete_tree_of_components_of_a_project(OrganizationDto organizationDto, ComponentDto project) {
- dbTester.organizations().insert(organizationDto);
+ public void deleteComponents_delete_tree_of_components_of_a_project(ComponentDto project) {
dbTester.components().insertComponent(project);
- ComponentDto otherProject = dbTester.components().insertPrivateProject(organizationDto);
+ ComponentDto otherProject = dbTester.components().insertPrivateProject();
Stream.of(project, otherProject).forEach(prj -> {
ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(prj));
ComponentDto directory1 = dbTester.components().insertComponent(ComponentTesting.newDirectory(module, "a"));
@Test
@UseDataProvider("projects")
- public void deleteComponentsByMainBranchProjectUuid_deletes_all_branches_of_a_project(OrganizationDto organizationDto, ComponentDto project) {
- dbTester.organizations().insert(organizationDto);
+ public void deleteComponentsByMainBranchProjectUuid_deletes_all_branches_of_a_project(ComponentDto project) {
dbTester.components().insertComponent(project);
ComponentDto branch = dbTester.components().insertProjectBranch(project);
Stream.of(project, branch).forEach(prj -> {
@Test
@UseDataProvider("views")
- public void deleteComponents_delete_tree_of_components_of_a_view(OrganizationDto organizationDto, ComponentDto view) {
- dbTester.organizations().insert(organizationDto);
+ public void deleteComponents_delete_tree_of_components_of_a_view(ComponentDto view) {
dbTester.components().insertComponent(view);
- ComponentDto otherView = dbTester.components().insertPrivatePortfolio(organizationDto);
+ ComponentDto otherView = dbTester.components().insertPrivatePortfolio();
Stream.of(view, otherView).forEach(vw -> {
dbTester.components().insertSubView(vw);
dbTester.components().insertComponent(newProjectCopy(dbTester.components().insertPrivateProject(), vw));
@Test
public void deletePermissions_deletes_permissions_of_public_project() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPublicProject(organization);
+ ComponentDto project = dbTester.components().insertPublicProject();
addPermissions(project);
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
@Test
public void deleteNewCodePeriodsByRootUuid_deletes_branch_new_code_periods() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
BranchDto branch = newBranchDto(project);
dbTester.components().insertProjectBranch(project, branch);
@Test
public void deleteNewCodePeriodsByRootUuid_deletes_project_new_code_periods() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
BranchDto branch = newBranchDto(project);
dbTester.components().insertProjectBranch(project, branch);
@Test
public void deleteNewCodePeriodsByRootUuid_should_not_delete_any_if_root_uuid_is_null() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
BranchDto branch = newBranchDto(project);
dbTester.components().insertProjectBranch(project, branch);
}
@DataProvider
- public static Object[][] projects() {
- OrganizationDto organization = OrganizationTesting.newOrganizationDto();
- return new Object[][] {
- {organization, ComponentTesting.newPrivateProjectDto(organization)},
- {organization, ComponentTesting.newPublicProjectDto(organization)},
+ public static Object[] projects() {
+ return new Object[] {
+ ComponentTesting.newPrivateProjectDto(), ComponentTesting.newPublicProjectDto(),
};
}
@DataProvider
- public static Object[][] views() {
- OrganizationDto organization = OrganizationTesting.newOrganizationDto();
- return new Object[][] {
- {organization, ComponentTesting.newView(organization)},
- {organization, ComponentTesting.newApplication(organization)}
+ public static Object[] views() {
+ return new Object[] {
+ ComponentTesting.newView(), ComponentTesting.newApplication()
};
}
@DataProvider
- public static Object[][] projectsAndViews() {
- return Stream.concat(Arrays.stream(views()), Arrays.stream(projects()))
- .map(t -> new Object[] {t[1]})
- .toArray(Object[][]::new);
+ public static Object[] projectsAndViews() {
+ return Stream.concat(Arrays.stream(views()), Arrays.stream(projects())).toArray(Object[]::new);
}
private Consumer<SnapshotDto> randomLastAndStatus() {
* @see #insertPublicPortfolio(java.util.function.Consumer)
* @deprecated since 6.6
*/
+ @Deprecated
public ComponentDto insertView(Consumer<ComponentDto> dtoPopulator) {
return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false, dtoPopulator);
}
return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(false), false, dtoPopulator);
}
+ // TODO remove after getting rid of organization code
+ @Deprecated
+ public final ComponentDto insertPublicPortfolio(OrganizationDto organization, String uuid, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentImpl(ComponentTesting.newView(organization, uuid).setPrivate(false), false, dtoPopulator);
+ }
+
+ public final ComponentDto insertPublicPortfolio(String uuid, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentImpl(ComponentTesting.newView(uuid).setPrivate(false), false, dtoPopulator);
+ }
+
public final ComponentDto insertPublicPortfolio(Consumer<ComponentDto> dtoPopulator) {
return insertComponentImpl(ComponentTesting.newView().setPrivate(false), false, dtoPopulator);
}
public final ComponentDto insertPrivatePortfolio() {
- return insertPrivatePortfolio(db.getDefaultOrganization());
+ return insertComponentImpl(ComponentTesting.newView().setPrivate(true), true, defaults());
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivatePortfolio(OrganizationDto organization) {
- return insertPrivatePortfolio(organization, defaults());
+ public final ComponentDto insertPrivatePortfolio(String uuid, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentImpl(ComponentTesting.newView(uuid).setPrivate(true), true, dtoPopulator);
}
public final ComponentDto insertPrivatePortfolio(Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()).setPrivate(true), true, dtoPopulator);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivatePortfolio(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(true), true, dtoPopulator);
+ return insertComponentImpl(ComponentTesting.newView().setPrivate(true), true, dtoPopulator);
}
public final ComponentDto insertPublicApplication() {
return newProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ProjectDto createPrivateProjectDto(OrganizationDto organizationDto) {
- return createProjectDto(organizationDto.getUuid(), Uuids.createFast(), true);
- }
-
public static ComponentDto newPrivateProjectDto(String uuid) {
return newProjectDto(uuid, true);
}
return newProjectDto(organizationDto.getUuid(), uuid, false);
}
- // TODO remove organizationUuid parameter after getting rid of organization code
- @Deprecated
- private static ProjectDto createProjectDto(String organizationUuid, String uuid, boolean isPrivate) {
- return new ProjectDto()
- .setOrganizationUuid(organizationUuid)
- .setUuid(uuid)
- .setKey("KEY_" + uuid)
- .setQualifier(Qualifiers.PROJECT)
- .setName("NAME_" + uuid)
- .setDescription("DESCRIPTION_" + uuid)
- .setPrivate(isPrivate);
- }
-
private static ComponentDto newProjectDto(String uuid, boolean isPrivate) {
return new ComponentDto()
.setUuid(uuid)