use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class TokenRenewActionTest method should_replace_existing_token_when__token_already_present_and_update_update_at.
@Test
public void should_replace_existing_token_when__token_already_present_and_update_update_at() {
ProjectDto project = db.components().insertPrivateProjectDto();
userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
when(tokenGenerator.generate()).thenReturn("generated_token");
// inserting first token with updated at 1000
ws.newRequest().setParam("project", project.getKey()).execute();
when(system2.now()).thenReturn(2000L);
// replacing first token with updated at 2000
ws.newRequest().setParam("project", project.getKey()).execute();
ProjectBadgeTokenDto projectBadgeTokenDto = db.getDbClient().projectBadgeTokenDao().selectTokenByProject(db.getSession(), project);
assertThat(projectBadgeTokenDto).isNotNull();
assertThat(projectBadgeTokenDto.getToken()).isEqualTo("generated_token");
assertThat(projectBadgeTokenDto.getUpdatedAt()).isEqualTo(2000L);
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ComponentServiceUpdateKeyTest method fail_to_update_project_key_without_admin_permission.
@Test
public void fail_to_update_project_key_without_admin_permission() {
ComponentDto project = insertSampleProject();
userSession.logIn("john").addProjectPermission(UserRole.USER, project);
ProjectDto projectDto = componentDb.getProjectDto(project);
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "sample2:root")).isInstanceOf(ForbiddenException.class);
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ComponentServiceUpdateKeyTest method fail_if_new_key_is_not_formatted_correctly.
@Test
public void fail_if_new_key_is_not_formatted_correctly() {
ComponentDto project = insertSampleProject();
logInAsProjectAdministrator(project);
ProjectDto projectDto = componentDb.getProjectDto(project);
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "sample?root")).isInstanceOf(IllegalArgumentException.class).hasMessage("Malformed key for 'sample?root'. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ComponentServiceUpdateKeyTest method fail_if_new_key_is_empty.
@Test
public void fail_if_new_key_is_empty() {
ComponentDto project = insertSampleProject();
logInAsProjectAdministrator(project);
ProjectDto projectDto = componentDb.getProjectDto(project);
assertThatThrownBy(() -> underTest.updateKey(dbSession, projectDto, "")).isInstanceOf(IllegalArgumentException.class).hasMessage("Malformed key for ''. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.");
}
use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.
the class ComponentCleanerServiceTest method insertApplication.
private ProjectDto insertApplication(ProjectDto project) {
ProjectDto app = db.components().insertPublicApplicationDto();
db.components().addApplicationProject(app, project);
return app;
}
Aggregations