Search in sources :

Example 11 with ShowWsResponse

use of org.sonarqube.ws.Components.ShowWsResponse in project sonarqube by SonarSource.

the class ShowActionTest method show_with_last_analysis_date.

@Test
public void show_with_last_analysis_date() {
    ComponentDto project = db.components().insertPrivateProject();
    db.components().insertSnapshots(newAnalysis(project).setCreatedAt(1_000_000_000L).setLast(false), newAnalysis(project).setCreatedAt(2_000_000_000L).setLast(false), newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
    userSession.addProjectPermission(USER, project);
    ShowWsResponse response = newRequest(project.getDbKey());
    assertThat(response.getComponent().getAnalysisDate()).isNotEmpty().isEqualTo(formatDateTime(new Date(3_000_000_000L)));
}
Also used : ShowWsResponse(org.sonarqube.ws.Components.ShowWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date) Test(org.junit.Test)

Example 12 with ShowWsResponse

use of org.sonarqube.ws.Components.ShowWsResponse in project sonarqube by SonarSource.

the class ShowActionTest method show_with_ancestors_and_analysis_date.

@Test
public void show_with_ancestors_and_analysis_date() {
    ComponentDto project = db.components().insertPrivateProject();
    db.components().insertSnapshot(newAnalysis(project).setCreatedAt(3_000_000_000L).setLast(true));
    ComponentDto module = db.components().insertComponent(newModuleDto(project));
    ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
    ComponentDto file = db.components().insertComponent(newFileDto(directory));
    userSession.addProjectPermission(USER, project);
    ShowWsResponse response = newRequest(file.getDbKey());
    String expectedDate = formatDateTime(new Date(3_000_000_000L));
    assertThat(response.getAncestorsList()).extracting(Component::getAnalysisDate).containsOnly(expectedDate, expectedDate, expectedDate);
}
Also used : ShowWsResponse(org.sonarqube.ws.Components.ShowWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Date(java.util.Date) Test(org.junit.Test)

Example 13 with ShowWsResponse

use of org.sonarqube.ws.Components.ShowWsResponse in project sonarqube by SonarSource.

the class ShowActionTest method pull_request.

@Test
public void pull_request() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, project);
    String pullRequest = "pr-1234";
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(pullRequest).setBranchType(PULL_REQUEST));
    ComponentDto module = db.components().insertComponent(newModuleDto(branch));
    ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
    ComponentDto file = db.components().insertComponent(newFileDto(directory));
    db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
    ShowWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, file.getKey()).setParam(PARAM_PULL_REQUEST, pullRequest).executeProtobuf(ShowWsResponse.class);
    assertThat(response.getComponent()).extracting(Component::getKey, Component::getPullRequest, Component::getVersion).containsExactlyInAnyOrder(file.getKey(), pullRequest, "1.1");
    assertThat(response.getAncestorsList()).extracting(Component::getKey, Component::getPullRequest, Component::getVersion).containsExactlyInAnyOrder(tuple(directory.getKey(), pullRequest, "1.1"), tuple(module.getKey(), pullRequest, "1.1"), tuple(branch.getKey(), pullRequest, "1.1"));
}
Also used : ShowWsResponse(org.sonarqube.ws.Components.ShowWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 14 with ShowWsResponse

use of org.sonarqube.ws.Components.ShowWsResponse in project sonarqube by SonarSource.

the class ShowActionTest method assertNeedIssueSyncEqual.

private void assertNeedIssueSyncEqual(@Nullable String pullRequest, @Nullable String branch, ComponentDto component, boolean needIssueSync) {
    TestRequest testRequest = ws.newRequest().setParam(PARAM_COMPONENT, component.getKey());
    Optional.ofNullable(pullRequest).ifPresent(pr -> testRequest.setParam(PARAM_PULL_REQUEST, pr));
    Optional.ofNullable(branch).ifPresent(br -> testRequest.setParam(PARAM_BRANCH, br));
    ShowWsResponse response = testRequest.executeProtobuf(ShowWsResponse.class);
    assertThat(response.getComponent()).extracting(Component::getNeedIssueSync).isEqualTo(needIssueSync);
}
Also used : ShowWsResponse(org.sonarqube.ws.Components.ShowWsResponse) TestRequest(org.sonar.server.ws.TestRequest)

Example 15 with ShowWsResponse

use of org.sonarqube.ws.Components.ShowWsResponse in project sonarqube by SonarSource.

the class ShowActionTest method show_without_ancestors_when_project.

@Test
public void show_without_ancestors_when_project() {
    ComponentDto project = db.components().insertPrivateProject();
    db.components().insertComponent(newModuleDto(project));
    userSession.addProjectPermission(USER, project);
    ShowWsResponse response = newRequest(project.getDbKey());
    assertThat(response.getComponent().getKey()).isEqualTo(project.getDbKey());
    assertThat(response.getAncestorsList()).isEmpty();
}
Also used : ShowWsResponse(org.sonarqube.ws.Components.ShowWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

ShowWsResponse (org.sonarqube.ws.Components.ShowWsResponse)15 Test (org.junit.Test)13 ComponentDto (org.sonar.db.component.ComponentDto)13 Date (java.util.Date)3 TestRequest (org.sonar.server.ws.TestRequest)1