Search in sources :

Example 1 with ProjectLinkDto

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

the class ExportLinksStepTest method export_links.

@Test
public void export_links() {
    ProjectLinkDto link1 = db.componentLinks().insertCustomLink(PROJECT);
    ProjectLinkDto link2 = db.componentLinks().insertProvidedLink(PROJECT);
    db.componentLinks().insertCustomLink(db.components().insertPrivateProject());
    underTest.execute(new TestComputationStepContext());
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("2 links exported");
    assertThat(dumpWriter.getWrittenMessagesOf(DumpElement.LINKS)).extracting(Link::getUuid, Link::getName, Link::getType, Link::getHref).containsExactlyInAnyOrder(tuple(link1.getUuid(), link1.getName(), link1.getType(), link1.getHref()), tuple(link2.getUuid(), "", link2.getType(), link2.getHref()));
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Test(org.junit.Test)

Example 2 with ProjectLinkDto

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

the class ExportLinksStepTest method test_all_fields.

@Test
public void test_all_fields() {
    ProjectLinkDto link = db.componentLinks().insertCustomLink(PROJECT, l -> l.setName("name").setHref("href").setType("type"));
    underTest.execute(new TestComputationStepContext());
    Link reloaded = dumpWriter.getWrittenMessagesOf(DumpElement.LINKS).get(0);
    assertThat(reloaded.getUuid()).isEqualTo(link.getUuid());
    assertThat(reloaded.getName()).isEqualTo(link.getName());
    assertThat(reloaded.getHref()).isEqualTo(link.getHref());
    assertThat(reloaded.getType()).isEqualTo(link.getType());
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) TestComputationStepContext(org.sonar.ce.task.step.TestComputationStepContext) Link(com.sonarsource.governance.projectdump.protobuf.ProjectDump.Link) Test(org.junit.Test)

Example 3 with ProjectLinkDto

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

the class DeleteAction method doHandle.

private void doHandle(String id) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        ProjectLinkDto link = dbClient.projectLinkDao().selectByUuid(dbSession, id);
        link = NotFoundException.checkFound(link, "Link with id '%s' not found", id);
        checkProjectAdminPermission(link);
        checkNotProvided(link);
        dbClient.projectLinkDao().delete(dbSession, link.getUuid());
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectLinkDto(org.sonar.db.component.ProjectLinkDto)

Example 4 with ProjectLinkDto

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

the class DeleteActionTest method remove_custom_link.

@Test
public void remove_custom_link() {
    ComponentDto project = db.components().insertPrivateProject();
    ProjectLinkDto link = db.componentLinks().insertCustomLink(project);
    logInAsProjectAdministrator(project);
    deleteLink(link);
    assertLinkIsDeleted(link.getUuid());
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 5 with ProjectLinkDto

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

the class DeleteActionTest method keep_links_of_another_project.

@Test
public void keep_links_of_another_project() {
    ComponentDto project1 = db.components().insertPrivateProject();
    ComponentDto project2 = db.components().insertPrivateProject();
    ProjectLinkDto customLink1 = db.componentLinks().insertCustomLink(project1);
    ProjectLinkDto customLink2 = db.componentLinks().insertCustomLink(project2);
    userSession.logIn().addProjectPermission(ADMIN, project1, project2);
    deleteLink(customLink1);
    assertLinkIsDeleted(customLink1.getUuid());
    assertLinkIsNotDeleted(customLink2.getUuid());
}
Also used : ProjectLinkDto(org.sonar.db.component.ProjectLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

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