@Test public void create_project() { userSession.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization()); CreateWsResponse response = call(CreateRequest.builder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) .build()); assertThat(response.getProject()) .extracting(Project::getKey, Project::getName, Project::getQualifier, Project::getVisibility) .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "public"); assertThat(db.getDbClient().componentDao().selectByKey(db.getSession(), DEFAULT_PROJECT_KEY).get()) .extracting(ComponentDto::getDbKey, ComponentDto::name, ComponentDto::qualifier, ComponentDto::scope, ComponentDto::isPrivate, ComponentDto::getMainBranchProjectUuid) .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "PRJ", false, null); }
/** * * This is part of the internal API. * This is a POST request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/create">Further information about this action online (including a response example)</a> * @since 4.0 */ public CreateWsResponse create(CreateRequest request) { return call( new PostRequest(path("create")) .setParam("branch", request.getBranch()) .setParam("name", request.getName()) .setParam("organization", request.getOrganization()) .setParam("project", request.getProject()) .setParam("visibility", request.getVisibility()), CreateWsResponse.parser()); }
private static CreateWsResponse toCreateResponse(ComponentDto componentDto) { return CreateWsResponse.newBuilder() .setProject(CreateWsResponse.Project.newBuilder() .setKey(componentDto.getDbKey()) .setName(componentDto.name()) .setQualifier(componentDto.qualifier()) .setVisibility(Visibility.getLabel(componentDto.isPrivate()))) .build(); }
/** * * This is part of the internal API. * This is a POST request. * @see <a href="https://next.sonarqube.com/sonarqube/web_api/api/projects/create">Further information about this action online (including a response example)</a> * @since 4.0 */ public CreateWsResponse create(CreateRequest request) { return call( new PostRequest(path("create")) .setParam("branch", request.getBranch()) .setParam("name", request.getName()) .setParam("organization", request.getOrganization()) .setParam("project", request.getProject()) .setParam("visibility", request.getVisibility()), CreateWsResponse.parser()); }
@Test public void create_project_with_deprecated_parameter() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(PROVISION_PROJECTS, organization); CreateWsResponse response = ws.newRequest() .setMethod(POST.name()) .setParam("organization", organization.getKey()) .setParam("key", DEFAULT_PROJECT_KEY) .setParam(PARAM_NAME, DEFAULT_PROJECT_NAME) .executeProtobuf(CreateWsResponse.class); assertThat(response.getProject()) .extracting(Project::getKey, Project::getName, Project::getQualifier, Project::getVisibility) .containsOnly(DEFAULT_PROJECT_KEY, DEFAULT_PROJECT_NAME, "TRK", "public"); }
@Test public void apply_project_visibility_private() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(PROVISION_PROJECTS, organization); CreateWsResponse result = ws.newRequest() .setParam("key", DEFAULT_PROJECT_KEY) .setParam("name", DEFAULT_PROJECT_NAME) .setParam("organization", organization.getKey()) .setParam("visibility", PRIVATE.getLabel()) .executeProtobuf(CreateWsResponse.class); assertThat(result.getProject().getVisibility()).isEqualTo("private"); }
@Test public void create_project_with_branch() { userSession.addPermission(PROVISION_PROJECTS, db.getDefaultOrganization()); CreateWsResponse response = call(CreateRequest.builder() .setKey(DEFAULT_PROJECT_KEY) .setName(DEFAULT_PROJECT_NAME) .setBranch("origin/master") .build()); assertThat(response.getProject()) .extracting(Project::getKey, Project::getName, Project::getQualifier, Project::getVisibility) .containsOnly(DEFAULT_PROJECT_KEY + ":origin/master", DEFAULT_PROJECT_NAME, "TRK", "public"); }
@Test public void apply_default_project_visibility_private() { OrganizationDto organization = db.organizations().insert(); db.organizations().setNewProjectPrivate(organization, true); userSession.addPermission(PROVISION_PROJECTS, organization); CreateWsResponse result = ws.newRequest() .setParam("key", DEFAULT_PROJECT_KEY) .setParam("name", DEFAULT_PROJECT_NAME) .setParam("organization", organization.getKey()) .executeProtobuf(CreateWsResponse.class); assertThat(result.getProject().getVisibility()).isEqualTo("private"); }
@Test public void apply_default_project_visibility_public() { OrganizationDto organization = db.organizations().insert(); db.organizations().setNewProjectPrivate(organization, false); userSession.addPermission(PROVISION_PROJECTS, organization); CreateWsResponse result = ws.newRequest() .setParam("key", DEFAULT_PROJECT_KEY) .setParam("name", DEFAULT_PROJECT_NAME) .setParam("organization", organization.getKey()) .executeProtobuf(CreateWsResponse.class); assertThat(result.getProject().getVisibility()).isEqualTo("public"); }
private static CreateWsResponse toCreateResponse(ComponentDto componentDto) { return CreateWsResponse.newBuilder() .setProject(CreateWsResponse.Project.newBuilder() .setKey(componentDto.getDbKey()) .setName(componentDto.name()) .setQualifier(componentDto.qualifier()) .setVisibility(Visibility.getLabel(componentDto.isPrivate()))) .build(); }
@Test public void does_not_fail_to_create_public_projects_when_organization_is_not_allowed_to_use_private_projects() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(PROVISION_PROJECTS, organization); doThrow(new BillingValidationsException("This organization cannot use project private")).when(billingValidations) .checkCanUpdateProjectVisibility(any(BillingValidations.Organization.class), eq(true)); CreateWsResponse result = ws.newRequest() .setParam("key", DEFAULT_PROJECT_KEY) .setParam("name", DEFAULT_PROJECT_NAME) .setParam("organization", organization.getKey()) .setParam("visibility", "public") .executeProtobuf(CreateWsResponse.class); assertThat(result.getProject().getVisibility()).isEqualTo("public"); }
@Test public void apply_project_visibility_public() { OrganizationDto organization = db.organizations().insert(); userSession.addPermission(PROVISION_PROJECTS, organization); CreateWsResponse result = ws.newRequest() .setParam("key", DEFAULT_PROJECT_KEY) .setParam("name", DEFAULT_PROJECT_NAME) .setParam("organization", organization.getKey()) .setParam("visibility", "public") .executeProtobuf(CreateWsResponse.class); assertThat(result.getProject().getVisibility()).isEqualTo("public"); }