Search in sources :

Example 1 with BRANCH_KEY_SEPARATOR

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RekeyedResource(org.sonar.db.component.ComponentKeyUpdaterDao.RekeyedResource) DbSession(org.sonar.db.DbSession) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) BRANCH_KEY_SEPARATOR(org.sonar.db.component.ComponentDto.BRANCH_KEY_SEPARATOR) Strings(com.google.common.base.Strings) ComponentKeyUpdaterDao.computeNewKey(org.sonar.db.component.ComponentKeyUpdaterDao.computeNewKey) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) ComponentDto.generateBranchKey(org.sonar.db.component.ComponentDto.generateBranchKey) DbTester(org.sonar.db.DbTester) Tuple(org.assertj.core.groups.Tuple) System2(org.sonar.api.utils.System2) Predicate(java.util.function.Predicate) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) ComponentKeyNewValue(org.sonar.db.audit.model.ComponentKeyNewValue) Mockito.verify(org.mockito.Mockito.verify) DbClient(org.sonar.db.DbClient) ComponentTesting.newPrivateProjectDto(org.sonar.db.component.ComponentTesting.newPrivateProjectDto) List(java.util.List) AuditPersister(org.sonar.db.audit.AuditPersister) Rule(org.junit.Rule) Qualifiers(org.sonar.api.resources.Qualifiers) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ComponentTesting.newModuleDto(org.sonar.db.component.ComponentTesting.newModuleDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Strings (com.google.common.base.Strings)1 List (java.util.List)1 Map (java.util.Map)1 Predicate (java.util.function.Predicate)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Tuple (org.assertj.core.groups.Tuple)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Qualifiers (org.sonar.api.resources.Qualifiers)1 System2 (org.sonar.api.utils.System2)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 DbTester (org.sonar.db.DbTester)1 AuditPersister (org.sonar.db.audit.AuditPersister)1