use of org.sonar.db.component.ComponentDto.BRANCH_KEY_SEPARATOR 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