@Test
public void update_project_key() throws Exception {
ComponentDto file = ComponentTesting.newFileDto(project).setKey("sample:root:src/File.xoo");
tester.get(ComponentDao.class).insert(session, file);
IssueDto issue = IssueTesting.newDto(rule, file, project);
db.issueDao().insert(session, issue);
session.commit();
MockUserSession.set().setLogin("john").addComponentPermission(UserRole.ADMIN, project.key(), project.key());
service.updateKey(project.key(), "sample2:root");
session.commit();
// Check project key has been updated
assertThat(service.getNullableByKey(project.key())).isNull();
assertThat(service.getNullableByKey("sample2:root")).isNotNull();
// Check file key has been updated
assertThat(service.getNullableByKey(file.key())).isNull();
assertThat(service.getNullableByKey("sample2:root:src/File.xoo")).isNotNull();
// Check issues are still here
assertThat(tester.get(IssueIndex.class).getNullableByKey(issue.getKey()).componentUuid()).isEqualTo(file.uuid());
assertThat(tester.get(IssueIndex.class).getNullableByKey(issue.getKey()).projectUuid()).isEqualTo(project.uuid());
// Check that no new issue has been added
assertThat(tester.get(SearchClient.class).prepareCount(IndexDefinition.ISSUES.getIndexName()).setTypes(IndexDefinition.ISSUES.getIndexType()).get().getCount()).isEqualTo(1);
// Check Issue Authorization index