Search in sources :

Example 91 with ProjectDto

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);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ProjectBadgeTokenDto(org.sonar.db.project.ProjectBadgeTokenDto) Test(org.junit.Test)

Example 92 with ProjectDto

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);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 93 with ProjectDto

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.");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 94 with ProjectDto

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.");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 95 with ProjectDto

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;
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10