Search in sources :

Example 6 with ProjectLinkDto

use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.

the class DeleteActionTest method fail_when_delete_provided_link.

@Test
public void fail_when_delete_provided_link() {
    ComponentDto project = db.components().insertPrivateProject();
    ProjectLinkDto link = db.componentLinks().insertProvidedLink(project);
    logInAsProjectAdministrator(project);
    assertThatThrownBy(() -> deleteLink(link)).isInstanceOf(BadRequestException.class).hasMessageContaining("Provided link cannot be deleted");
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) Test(org.junit.Test)

Example 7 with ProjectLinkDto

use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.

the class SearchActionTest method several_projects.

@Test
public void several_projects() {
    ComponentDto project1 = db.components().insertPrivateProject();
    ComponentDto project2 = db.components().insertPrivateProject();
    ProjectLinkDto link1 = db.componentLinks().insertCustomLink(project1);
    ProjectLinkDto link2 = db.componentLinks().insertCustomLink(project2);
    userSession.logIn().setRoot();
    SearchWsResponse response = callByKey(project1.getKey());
    assertThat(response.getLinksList()).extracting(Link::getId, Link::getName).containsExactlyInAnyOrder(tuple(link1.getUuid(), link1.getName()));
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.ProjectLinks.SearchWsResponse) Test(org.junit.Test)

Example 8 with ProjectLinkDto

use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.

the class SearchActionTest method response_fields.

@Test
public void response_fields() {
    ComponentDto project = db.components().insertPrivateProject();
    ProjectLinkDto homepageLink = db.componentLinks().insertProvidedLink(project);
    ProjectLinkDto customLink = db.componentLinks().insertCustomLink(project);
    logInAsProjectAdministrator(project);
    SearchWsResponse response = callByKey(project.getKey());
    assertThat(response.getLinksList()).extracting(Link::getId, Link::getName, Link::getType, Link::getUrl).containsExactlyInAnyOrder(tuple(homepageLink.getUuid(), "", homepageLink.getType(), homepageLink.getHref()), tuple(customLink.getUuid(), customLink.getName(), customLink.getType(), customLink.getHref()));
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.ProjectLinks.SearchWsResponse) Test(org.junit.Test)

Example 9 with ProjectLinkDto

use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.

the class SearchActionTest method project_user_can_search_for_links.

@Test
public void project_user_can_search_for_links() {
    ComponentDto project = db.components().insertPrivateProject();
    ProjectLinkDto link = db.componentLinks().insertCustomLink(project);
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    SearchWsResponse response = callByKey(project.getKey());
    assertThat(response.getLinksList()).extracting(Link::getId, Link::getName).containsExactlyInAnyOrder(tuple(link.getUuid(), link.getName()));
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) SearchWsResponse(org.sonarqube.ws.ProjectLinks.SearchWsResponse) Test(org.junit.Test)

Example 10 with ProjectLinkDto

use of org.sonar.db.component.ProjectLinkDto in project sonarqube by SonarSource.

the class ExportLinksStep method execute.

@Override
public void execute(Context context) {
    long count = 0L;
    try {
        try (DbSession dbSession = dbClient.openSession(false);
            StreamWriter<ProjectDump.Link> linksWriter = dumpWriter.newStreamWriter(DumpElement.LINKS)) {
            ProjectDump.Link.Builder builder = ProjectDump.Link.newBuilder();
            List<ProjectLinkDto> links = dbSession.getMapper(ProjectExportMapper.class).selectLinksForExport(projectHolder.projectDto().getUuid());
            for (ProjectLinkDto link : links) {
                builder.clear().setUuid(link.getUuid()).setName(defaultString(link.getName())).setHref(defaultString(link.getHref())).setType(defaultString(link.getType())).setComponentRef(componentRepository.getRef(link.getProjectUuid()));
                linksWriter.write(builder.build());
                ++count;
            }
            Loggers.get(getClass()).debug("{} links exported", count);
        }
    } catch (Exception e) {
        throw new IllegalStateException(format("Link export failed after processing %d link(s) successfully", count), e);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ProjectExportMapper(org.sonar.db.project.ProjectExportMapper)

Aggregations

ProjectLinkDto (org.sonar.db.component.ProjectLinkDto)22 Test (org.junit.Test)15 ComponentDto (org.sonar.db.component.ComponentDto)13 SearchWsResponse (org.sonarqube.ws.ProjectLinks.SearchWsResponse)7 DbSession (org.sonar.db.DbSession)6 Component (org.sonar.ce.task.projectanalysis.component.Component)2 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)2 ProjectDto (org.sonar.db.project.ProjectDto)2 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Link (com.sonarsource.governance.projectdump.protobuf.ProjectDump.Link)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AnalysisMetadataHolder (org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder)1 BatchReportReader (org.sonar.ce.task.projectanalysis.batch.BatchReportReader)1 TreeRootHolder (org.sonar.ce.task.projectanalysis.component.TreeRootHolder)1 ComputationStep (org.sonar.ce.task.step.ComputationStep)1