use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method import_project_with_tilda.
@Test
public void import_project_with_tilda() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
project.setKey("~" + project.getKey());
Repository repo = getGsonBBSRepo(project);
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "~projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
String key = project.getKey() + "_" + repo.getSlug();
assertThat(result.getKey()).isNotEqualTo(key);
assertThat(result.getKey()).isEqualTo(key.substring(1));
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault.
@Test
public void handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault() {
BranchesList branchesList = new BranchesList();
Branch branch = new Branch("default", true);
branchesList.addBranch(branch);
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
Repository repo = getGsonBBSRepo(project);
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(branchesList);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
String mainBranchName = collect.iterator().next().getKey();
assertThat(mainBranchName).isEqualTo("default");
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method fail_project_already_exist.
@Test
public void fail_project_already_exist() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
Repository repo = getGsonBBSRepo(project);
String projectKey = project.getKey() + "_" + repo.getSlug();
db.components().insertPublicProject(p -> p.setDbKey(projectKey));
assertThatThrownBy(() -> {
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").execute();
}).isInstanceOf(BadRequestException.class).hasMessage("Could not create null, key already exists: " + projectKey);
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_new_azuredevops_pat.
@Test
public void set_new_azuredevops_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", "12345678987654321").execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo("12345678987654321");
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_new_gitlab_pat.
@Test
public void set_new_gitlab_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertGitlabAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", "12345678987654321").execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo("12345678987654321");
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
Aggregations