private String BRANCH_UUID = "branch_uuid";
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester dbTester = DbTester.create(System2.INSTANCE, true);
private CeTask.Component component = new CeTask.Component(BRANCH_UUID, "component key", "component name");
private CeTask ceTask = new CeTask.Builder()
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
public class RenameActionIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Test
public void rename() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
userSession.addProjectPermission(UserRole.ADMIN, project);
tester.newRequest()
.execute();
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(2);
- Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid());
+ Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), project.getUuid());
assertThat(mainBranch.get().getKey()).isEqualTo("master");
- Optional<BranchDto> unchangedBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid());
+ Optional<BranchDto> unchangedBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.getUuid());
assertThat(unchangedBranch.get().getKey()).isEqualTo("branch");
}
@Test
public void rename_with_same_name() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch"));
userSession.addProjectPermission(UserRole.ADMIN, project);
tester.newRequest()
.execute();
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(2);
- Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid());
+ Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), project.getUuid());
assertThat(mainBranch.get().getKey()).isEqualTo("master");
- Optional<BranchDto> unchangedBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid());
+ Optional<BranchDto> unchangedBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.getUuid());
assertThat(unchangedBranch.get().getKey()).isEqualTo("branch");
}
@Test
public void fail_if_name_already_used() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
userSession.addProjectPermission(UserRole.ADMIN, project);
db.components().insertProjectBranch(project, b -> b.setKey("branch"));
import org.sonar.api.web.UserRole;
import org.sonar.db.DbTester;
import org.sonar.db.component.BranchDto;
-import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ResourceTypesRule;
+import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.exceptions.NotFoundException;
public class SetAutomaticDeletionProtectionActionIT {
@Rule
- public DbTester db = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create(System2.INSTANCE, true);
@Rule
public UserSessionRule userSession = UserSessionRule.standalone();
@Test
public void fail_if_no_administer_permission() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
assertThatThrownBy(() -> tester.newRequest()
.setParam("project", project.getKey())
@Test
public void fail_when_attempting_to_set_main_branch_as_included_in_purge() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1").setExcludeFromPurge(false));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1").setExcludeFromPurge(false));
userSession.addProjectPermission(UserRole.ADMIN, project);
assertThatThrownBy(() -> tester.newRequest()
@Test
public void set_purge_exclusion() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1").setExcludeFromPurge(false));
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
+ BranchDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1").setExcludeFromPurge(false));
userSession.addProjectPermission(UserRole.ADMIN, project);
tester.newRequest()
.execute();
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(2);
- Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid());
+ Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectMainBranchByProjectUuid(db.getSession(), project.getUuid());
assertThat(mainBranch.get().getKey()).isEqualTo(DEFAULT_MAIN_BRANCH_NAME);
assertThat(mainBranch.get().isExcludeFromPurge()).isTrue();
- Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid());
+ Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.getUuid());
assertThat(branchDto.get().getKey()).isEqualTo("branch1");
assertThat(branchDto.get().isExcludeFromPurge()).isTrue();
}
@Test
public void fail_on_non_boolean_value_parameter() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
assertThatThrownBy(() -> tester.newRequest()
.setParam("project", project.getKey())
@Test
public void fail_if_branch_does_not_exist() {
userSession.logIn();
- ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
+ ProjectDto project = db.components().insertPublicProject().getProjectDto();
userSession.addProjectPermission(UserRole.ADMIN, project);
assertThatThrownBy(() -> tester.newRequest()
private final System2 system2 = System2.INSTANCE;
@Rule
- public final DbTester db = DbTester.create(system2);
+ public final DbTester db = DbTester.create(system2, true);
@Rule
public final UserSessionRule userSession = UserSessionRule.standalone();
@Rule
import org.sonar.db.component.BranchDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
import static com.google.common.base.Preconditions.checkArgument;
checkArgument(!existingBranch.filter(b -> !b.isMain()).isPresent(),
"Impossible to update branch name: a branch with name \"%s\" already exists in the project.", newBranchName);
- dbClient.branchDao().updateBranchName(dbSession, project.getUuid(), newBranchName);
+ BranchDto mainBranchDto = dbClient.branchDao().selectMainBranchByProjectUuid(dbSession, project.getUuid())
+ .orElseThrow(() -> new NotFoundException("Cannot find main branch for project: " + project.getUuid()));
+
+ dbClient.branchDao().updateBranchName(dbSession, mainBranchDto.getUuid(), newBranchName);
dbSession.commit();
response.noContent();
}