ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class);
// must SELECT first everything
Set<ResourceDto> modules = collectAllModules(projectUuid, stringToReplace, mapper);
+ checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
- // add branches
+ // add branches (no check should be done as branch keys cannot be changed by the user)
Map<String, String> branchBaseKeys = new HashMap<>();
session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid)
.stream()
branchModules.forEach(module -> branchBaseKeys.put(module.getKey(), branchBaseKey(module.getKey())));
});
- checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
for (ResourceDto module : modules) {
allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getUuid()));
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
}
+ @Test
+ public void bulk_updateKey_on_branch_containing_slash() {
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch/with/slash"));
+ String newKey = "newKey";
+
+ underTest.bulkUpdateKey(dbSession, project.uuid(), project.getKey(), newKey);
+
+ assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newKey)).hasSize(1);
+ assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, ComponentDto.generateBranchKey(newKey, branch.getBranch()))).hasSize(1);
+ }
+
@Test
public void bulk_updateKey_updates_pull_requests_too() {
ComponentDto project = db.components().insertMainBranch();