Search in sources :

Example 1 with ListWsResponse

use of org.sonarqube.ws.ProjectBranches.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method main_branch.

@Test
public void main_branch() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(USER, project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getDbKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(Branch::getName, Branch::getIsMain, Branch::getType).containsExactlyInAnyOrder(tuple("master", true, BranchType.BRANCH));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 2 with ListWsResponse

use of org.sonarqube.ws.ProjectBranches.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method status_on_branch.

@Test
public void status_on_branch() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(USER, project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
    db.measures().insertLiveMeasure(branch, qualityGateStatus, m -> m.setData("OK"));
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(b -> b.getStatus().hasQualityGateStatus(), b -> b.getStatus().getQualityGateStatus()).containsExactlyInAnyOrder(tuple(false, ""), tuple(true, "OK"));
}
Also used : SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) ComponentFinder(org.sonar.server.component.ComponentFinder) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) AsyncIssueIndexing(org.sonar.server.issue.index.AsyncIssueIndexing) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BranchType(org.sonarqube.ws.Common.BranchType) ProjectBranches(org.sonarqube.ws.ProjectBranches) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BUG(org.sonar.api.rules.RuleType.BUG) Branch(org.sonarqube.ws.ProjectBranches.Branch) PROJECT(org.sonar.api.resources.Qualifiers.PROJECT) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) ComponentTesting(org.sonar.db.component.ComponentTesting) ResourceTypesRule(org.sonar.db.component.ResourceTypesRule) ResourceTypes(org.sonar.api.resources.ResourceTypes) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) BRANCH(org.sonar.db.component.BranchType.BRANCH) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Mockito.mock(org.mockito.Mockito.mock) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 3 with ListWsResponse

use of org.sonarqube.ws.ProjectBranches.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method main_branch_with_specified_name.

@Test
public void main_branch_with_specified_name() {
    ComponentDto project = db.components().insertPrivateProject();
    db.getDbClient().branchDao().updateMainBranchName(db.getSession(), project.uuid(), "head");
    db.commit();
    userSession.logIn().addProjectPermission(USER, project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(Branch::getName, Branch::getIsMain, Branch::getType).containsExactlyInAnyOrder(tuple("head", true, BranchType.BRANCH));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with ListWsResponse

use of org.sonarqube.ws.ProjectBranches.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method application_branches.

@Test
public void application_branches() {
    ComponentDto application = db.components().insertPrivateApplication();
    db.components().insertProjectBranch(application, b -> b.setKey("feature/bar"));
    db.components().insertProjectBranch(application, b -> b.setKey("feature/foo"));
    userSession.logIn().addProjectPermission(USER, application);
    ListWsResponse response = ws.newRequest().setParam("project", application.getDbKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(Branch::getName, Branch::getType).containsExactlyInAnyOrder(tuple("master", BranchType.BRANCH), tuple("feature/foo", BranchType.BRANCH), tuple("feature/bar", BranchType.BRANCH));
}
Also used : ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 5 with ListWsResponse

use of org.sonarqube.ws.ProjectBranches.ListWsResponse in project sonarqube by SonarSource.

the class ListActionTest method response_contains_date_of_last_analysis.

@Test
public void response_contains_date_of_last_analysis() {
    Long lastAnalysisBranch = dateToLong(parseDateTime("2017-04-01T00:00:00+0100"));
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().addProjectPermission(USER, project);
    ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(org.sonar.db.component.BranchType.BRANCH));
    db.getDbClient().snapshotDao().insert(db.getSession(), newAnalysis(branch2).setCreatedAt(lastAnalysisBranch));
    db.commit();
    indexIssues();
    permissionIndexerTester.allowOnlyAnyone(project);
    ListWsResponse response = ws.newRequest().setParam("project", project.getKey()).executeProtobuf(ListWsResponse.class);
    assertThat(response.getBranchesList()).extracting(ProjectBranches.Branch::getType, ProjectBranches.Branch::hasAnalysisDate, b -> "".equals(b.getAnalysisDate()) ? null : dateToLong(parseDateTime(b.getAnalysisDate()))).containsExactlyInAnyOrder(tuple(BranchType.BRANCH, false, null), tuple(BranchType.BRANCH, true, lastAnalysisBranch));
}
Also used : SCAN_EXECUTION(org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION) ComponentFinder(org.sonar.server.component.ComponentFinder) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) AsyncIssueIndexing(org.sonar.server.issue.index.AsyncIssueIndexing) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) BranchType(org.sonarqube.ws.Common.BranchType) ProjectBranches(org.sonarqube.ws.ProjectBranches) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BUG(org.sonar.api.rules.RuleType.BUG) Branch(org.sonarqube.ws.ProjectBranches.Branch) PROJECT(org.sonar.api.resources.Qualifiers.PROJECT) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SnapshotTesting.newAnalysis(org.sonar.db.component.SnapshotTesting.newAnalysis) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) ComponentTesting(org.sonar.db.component.ComponentTesting) ResourceTypesRule(org.sonar.db.component.ResourceTypesRule) ResourceTypes(org.sonar.api.resources.ResourceTypes) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) USER(org.sonar.api.web.UserRole.USER) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) WsActionTester(org.sonar.server.ws.WsActionTester) BRANCH(org.sonar.db.component.BranchType.BRANCH) NotFoundException(org.sonar.server.exceptions.NotFoundException) String.format(java.lang.String.format) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) DateUtils.parseDateTime(org.sonar.api.utils.DateUtils.parseDateTime) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Mockito.mock(org.mockito.Mockito.mock) ListWsResponse(org.sonarqube.ws.ProjectBranches.ListWsResponse) ProjectBranches(org.sonarqube.ws.ProjectBranches) DateUtils.dateToLong(org.sonar.api.utils.DateUtils.dateToLong) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ComponentDto (org.sonar.db.component.ComponentDto)6 ListWsResponse (org.sonarqube.ws.ProjectBranches.ListWsResponse)6 String.format (java.lang.String.format)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 Assertions.tuple (org.assertj.core.api.Assertions.tuple)2 Before (org.junit.Before)2 Rule (org.junit.Rule)2 Mockito.mock (org.mockito.Mockito.mock)2 ALERT_STATUS_KEY (org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY)2 PROJECT (org.sonar.api.resources.Qualifiers.PROJECT)2 ResourceTypes (org.sonar.api.resources.ResourceTypes)2 BUG (org.sonar.api.rules.RuleType.BUG)2 WebService (org.sonar.api.server.ws.WebService)2 DateUtils.dateToLong (org.sonar.api.utils.DateUtils.dateToLong)2 DateUtils.parseDateTime (org.sonar.api.utils.DateUtils.parseDateTime)2 System2 (org.sonar.api.utils.System2)2 USER (org.sonar.api.web.UserRole.USER)2 SCAN_EXECUTION (org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION)2