@Test public void selectByUuid() { when(uuidFactory.create()).thenReturn(A_UUID); when(system2.now()).thenReturn(DATE); String userUuid = Uuids.createFast(); underTest.insertOrUpdate(dbSession, GITHUB, A_OWNER, true, AN_INSTALL, userUuid); assertThat(underTest.selectByUuid(dbSession, A_UUID).get()) .extracting(AlmAppInstallDto::getUuid, AlmAppInstallDto::getAlm, AlmAppInstallDto::getInstallId, AlmAppInstallDto::getOwnerId, AlmAppInstallDto::getUserExternalId, AlmAppInstallDto::getCreatedAt, AlmAppInstallDto::getUpdatedAt) .contains(A_UUID, GITHUB, A_OWNER, AN_INSTALL, userUuid, DATE, DATE); assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent(); }
@Test public void selectByOwnerId() { when(uuidFactory.create()).thenReturn(A_UUID); when(system2.now()).thenReturn(DATE); underTest.insertOrUpdate(dbSession, GITHUB, A_OWNER, true, AN_INSTALL, null); assertThat(underTest.selectByOwnerId(dbSession, GITHUB, A_OWNER).get()) .extracting(AlmAppInstallDto::getUuid, AlmAppInstallDto::getAlm, AlmAppInstallDto::getInstallId, AlmAppInstallDto::getOwnerId, AlmAppInstallDto::getCreatedAt, AlmAppInstallDto::getUpdatedAt) .contains(A_UUID, GITHUB, A_OWNER, AN_INSTALL, DATE, DATE); assertThat(underTest.selectByOwnerId(dbSession, BITBUCKETCLOUD, A_OWNER)).isNotPresent(); assertThat(underTest.selectByOwnerId(dbSession, GITHUB, "Unknown owner")).isNotPresent(); }
@Test public void selectByInstallationId() { when(uuidFactory.create()).thenReturn(A_UUID); when(system2.now()).thenReturn(DATE); underTest.insertOrUpdate(dbSession, GITHUB, A_OWNER, true, AN_INSTALL, Uuids.createFast()); assertThat(underTest.selectByInstallationId(dbSession, GITHUB, AN_INSTALL).get()) .extracting(AlmAppInstallDto::getUuid, AlmAppInstallDto::getAlm, AlmAppInstallDto::getInstallId, AlmAppInstallDto::getOwnerId, AlmAppInstallDto::getCreatedAt, AlmAppInstallDto::getUpdatedAt) .contains(A_UUID, GITHUB, A_OWNER, AN_INSTALL, DATE, DATE); assertThat(underTest.selectByInstallationId(dbSession, GITHUB, "unknown installation")).isEmpty(); assertThat(underTest.selectByInstallationId(dbSession, BITBUCKETCLOUD, AN_INSTALL)).isEmpty(); }
@Test public void empty_response() { ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(UserRole.USER, project); SearchResponse result = call(project.getDbKey()); assertThat(result.hasPaging()).isTrue(); assertThat(result.getPaging()).extracting(Paging::getPageIndex, Paging::getPageSize, Paging::getTotal).containsExactly(1, 100, 0); assertThat(result.getAnalysesCount()).isEqualTo(0); }
@Test public void select() { underTest.insert(dbSession, create("O1", 512)); Optional<OrganizationMemberDto> result = underTest.select(dbSession, "O1", 512); assertThat(result).isPresent(); assertThat(result.get()).extracting(OrganizationMemberDto::getOrganizationUuid, OrganizationMemberDto::getUserId).containsExactly("O1", 512); assertThat(underTest.select(dbSession, "O1", 256)).isNotPresent(); assertThat(underTest.select(dbSession, "O2", 512)).isNotPresent(); }
@Test public void empty_search_with_unknown_branch() { SearchWsResponse response = ws.newRequest() .setParam("onComponentOnly", "true") .setParam("componentKeys", "foo") .setParam("branch", "bar") .executeProtobuf(SearchWsResponse.class); assertThat(response) .extracting(SearchWsResponse::getIssuesList, r -> r.getPaging().getTotal()) .containsExactlyInAnyOrder(Collections.emptyList(), 0); }
@Test public void return_homepage_when_set_to_MY_PROJECTS() { UserDto user = db.users().insertUser(u -> u.setHomepageType("MY_PROJECTS")); userSessionRule.logIn(user); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType) .containsExactly(CurrentWsResponse.HomepageType.MY_PROJECTS); }
@Test public void create_none_local_user() { logInAsSystemAdministrator(); call(CreateRequest.builder() .setLogin("john") .setName("John") .setLocal(false) .build()); assertThat(db.users().selectUserByLogin("john").get()) .extracting(UserDto::isLocal, UserDto::getExternalIdentityProvider, UserDto::getExternalLogin, UserDto::isRoot) .containsOnly(false, "sonarqube", "john", false); }
@Test public void selectByUuid() { ComponentDto project = db.components().insertPrivateProject(); ComponentDto branch1 = db.components().insertProjectBranch(project); ComponentDto branch2 = db.components().insertProjectBranch(project); assertThat(underTest.selectByUuid(db.getSession(), branch1.uuid()).get()) .extracting(BranchDto::getUuid) .containsExactlyInAnyOrder(branch1.uuid()); assertThat(underTest.selectByUuid(db.getSession(), project.uuid())).isNotPresent(); assertThat(underTest.selectByUuid(db.getSession(), "unknown")).isNotPresent(); }
@Test public void associate() { QualityGateDto qgate = db.qualityGates().insertQualityGate(db.getDefaultOrganization()); OrganizationDto org = db.organizations().insert(); underTest.associate(dbSession, Uuids.createFast(), org, qgate); assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())).isNotNull(); assertThat(underTest.selectByOrganizationAndUuid(dbSession, org, qgate.getUuid())) .extracting(QGateWithOrgDto::getId, QGateWithOrgDto::getUuid, QGateWithOrgDto::getOrganizationUuid, QGateWithOrgDto::getName) .containsExactly(qgate.getId(), qgate.getUuid(), org.getUuid(), qgate.getName()); }
@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 return_default_homepage_when_set_to_a_project_but_no_rights_on_this_project() { ComponentDto project = db.components().insertPrivateProject(); UserDto user = db.users().insertUser(u -> u.setHomepageType("PROJECT").setHomepageParameter(project.uuid())); userSessionRule.logIn(user); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType) .containsExactly(CurrentWsResponse.HomepageType.PROJECTS); }
@Test public void return_homepage_when_set_to_an_organization() { OrganizationDto organizationDto = db.organizations().insert(); UserDto user = db.users().insertUser(u -> u.setHomepageType("ORGANIZATION").setHomepageParameter(organizationDto.getUuid())); userSessionRule.logIn(user); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType, CurrentWsResponse.Homepage::getOrganization) .containsExactly(CurrentWsResponse.HomepageType.ORGANIZATION, organizationDto.getKey()); }
@Test public void return_default_homepage_when_set_to_an_application_but_no_rights_on_this_application() { withGovernancePlugin(); ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); UserDto user = db.users().insertUser(u -> u.setHomepageType("APPLICATION").setHomepageParameter(application.uuid())); userSessionRule.logIn(user); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType) .containsExactly(CurrentWsResponse.HomepageType.PROJECTS); }
@Test public void selectMeasure_map_fields() { MetricDto metric = db.measures().insertMetric(); ComponentDto project = db.components().insertPrivateProject(); ComponentDto file = db.components().insertComponent(newFileDto(project)); underTest.insert(db.getSession(), newLiveMeasure(file, metric).setValue(3.14).setVariation(0.1).setData("text_value")); LiveMeasureDto result = underTest.selectMeasure(db.getSession(), file.uuid(), metric.getKey()).orElseThrow(() -> new IllegalArgumentException("Measure not found")); assertThat(result).as("Fail to map fields of %s", result.toString()).extracting( LiveMeasureDto::getProjectUuid, LiveMeasureDto::getComponentUuid, LiveMeasureDto::getMetricId, LiveMeasureDto::getValue, LiveMeasureDto::getVariation, LiveMeasureDto::getDataAsString, LiveMeasureDto::getTextValue) .contains(project.uuid(), file.uuid(), metric.getId(), 3.14, 0.1, "text_value", "text_value"); }
@Test public void findById() { MetricDto firstMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); MetricDto secondMetric = db.getDbClient().metricDao().insert(db.getSession(), newMetricDto()); db.commit(); assertThat(underTest.findById(firstMetric.getId())).extracting(Metric::getKey).containsExactly(firstMetric.getKey()); }
@Test public void return_homepage_when_set_to_an_application() { withGovernancePlugin(); ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); UserDto user = db.users().insertUser(u -> u.setHomepageType("APPLICATION").setHomepageParameter(application.uuid())); userSessionRule.logIn(user).addProjectPermission(USER, application); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType, CurrentWsResponse.Homepage::getComponent) .containsExactly(CurrentWsResponse.HomepageType.APPLICATION, application.getKey()); }
@Test public void return_homepage_when_set_to_a_branch() { ComponentDto project = db.components().insertMainBranch(); ComponentDto branch = db.components().insertProjectBranch(project); UserDto user = db.users().insertUser(u -> u.setHomepageType("PROJECT").setHomepageParameter(branch.uuid())); userSessionRule.logIn(user).addProjectPermission(USER, project); CurrentWsResponse response = call(); assertThat(response.getHomepage()) .extracting(CurrentWsResponse.Homepage::getType, CurrentWsResponse.Homepage::getComponent, CurrentWsResponse.Homepage::getBranch) .containsExactly(CurrentWsResponse.HomepageType.PROJECT, branch.getKey(), branch.getBranch()); }
@Test public void show_on_paid_organization() { OrganizationDto organization = db.organizations().insert(); QProfileDto qualityProfile = db.qualityProfiles().insert(organization, p -> p.setLanguage(XOO1.getKey())); UserDto user = db.users().insertUser(); db.organizations().addMember(organization, user); userSession.logIn(user); ShowResponse result = call(ws.newRequest().setParam(PARAM_KEY, qualityProfile.getKee())); assertThat(result.getProfile()) .extracting(QualityProfile::getKey) .containsExactly(qualityProfile.getKee()); }
@Test public void compare_to_sonarqube_way_profile() { QProfileDto sonarWayProfile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setIsBuiltIn(true).setName("SonarQube way").setLanguage(XOO1.getKey())); QProfileDto profile = db.qualityProfiles().insert(db.getDefaultOrganization(), p -> p.setLanguage(XOO1.getKey())); CompareToSonarWay result = call(ws.newRequest() .setParam(PARAM_KEY, profile.getKee()) .setParam(PARAM_COMPARE_TO_SONAR_WAY, "true")) .getCompareToSonarWay(); assertThat(result) .extracting(CompareToSonarWay::getProfile, CompareToSonarWay::getProfileName) .containsExactly(sonarWayProfile.getKee(), sonarWayProfile.getName()); }