use of org.sonar.db.component.ComponentDto.generateBranchKey in project sonarqube by SonarSource.
the class ComponentKeyUpdaterDaoTest method updateKey_updates_branches_too.
@Test
public void updateKey_updates_branches_too() {
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
db.components().insertComponent(newFileDto(branch));
db.components().insertComponent(newFileDto(branch));
int branchComponentCount = 3;
String oldProjectKey = project.getKey();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).hasSize(1);
String oldBranchKey = branch.getDbKey();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount);
String newProjectKey = "newKey";
String newBranchKey = ComponentDto.generateBranchKey(newProjectKey, branch.getBranch());
underTest.updateKey(dbSession, project.uuid(), newProjectKey);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldProjectKey)).isEmpty();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).isEmpty();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount);
db.select(dbSession, "select kee from components").forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
}
use of org.sonar.db.component.ComponentDto.generateBranchKey in project sonarqube by SonarSource.
the class ComponentKeyUpdaterDaoTest method update_application_branch_key.
@Test
public void update_application_branch_key() {
ComponentDto app = db.components().insertPublicProject();
ComponentDto appBranch = db.components().insertProjectBranch(app);
ComponentDto appBranchProj1 = appBranch.copy().setDbKey(appBranch.getDbKey().replace(BRANCH_KEY_SEPARATOR, "") + "appBranchProj1:BRANCH:1").setUuid("appBranchProj1").setScope(Qualifiers.FILE);
ComponentDto appBranchProj2 = appBranch.copy().setDbKey(appBranch.getDbKey().replace(BRANCH_KEY_SEPARATOR, "") + "appBranchProj2:BRANCH:2").setUuid("appBranchProj2").setScope(Qualifiers.FILE);
db.components().insertComponent(appBranchProj1);
db.components().insertComponent(appBranchProj2);
int branchComponentCount = 3;
String oldBranchKey = appBranch.getDbKey();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).hasSize(branchComponentCount);
String newBranchName = "newKey";
String newAppBranchKey = ComponentDto.generateBranchKey(app.getDbKey(), newBranchName);
String newAppBranchFragment = app.getDbKey() + newBranchName;
underTest.updateApplicationBranchKey(dbSession, appBranch.uuid(), app.getDbKey(), newBranchName);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, oldBranchKey)).isEmpty();
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newAppBranchKey)).hasSize(branchComponentCount);
List<Map<String, Object>> result = db.select(dbSession, String.format("select kee from components where root_uuid = '%s' and scope != 'PRJ'", appBranch.uuid()));
assertThat(result).hasSize(2);
result.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newAppBranchFragment)));
}
Aggregations