Search in sources :

Example 6 with ComponentLinkDto

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

the class DeleteActionTest method fail_when_delete_provided_link.

@Test
public void fail_when_delete_provided_link() {
    ComponentDto project = insertProject();
    ComponentLinkDto link = insertHomepageLink(project.uuid());
    logInAsProjectAdministrator(project);
    expectedException.expect(BadRequestException.class);
    deleteLink(link.getId());
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 7 with ComponentLinkDto

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

the class DeleteActionTest method keep_links_of_another_project.

@Test
public void keep_links_of_another_project() {
    ComponentDto project1 = insertProject();
    ComponentDto project2 = insertProject("another", "abcd");
    ComponentLinkDto customLink1 = insertCustomLink(project1.uuid());
    ComponentLinkDto customLink2 = insertCustomLink(project2.uuid());
    Long id1 = customLink1.getId();
    Long id2 = customLink2.getId();
    userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project1.uuid(), project2.uuid());
    deleteLink(id1);
    assertLinkIsDeleted(id1);
    assertLinkIsNotDeleted(id2);
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 8 with ComponentLinkDto

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

the class DeleteActionTest method insertHomepageLink.

private ComponentLinkDto insertHomepageLink(String projectUuid) {
    ComponentLinkDto link = new ComponentLinkDto().setComponentUuid(projectUuid).setName("Homepage").setType("homepage").setHref("http://example.org");
    insertLink(link);
    return link;
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto)

Example 9 with ComponentLinkDto

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

the class DeleteAction method doHandle.

private void doHandle(DeleteWsRequest request) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        long id = request.getId();
        ComponentLinkDto link = dbClient.componentLinkDao().selectById(dbSession, id);
        link = WsUtils.checkFound(link, "Link with id '%s' not found", id);
        checkProjectAdminPermission(link);
        checkNotProvided(link);
        dbClient.componentLinkDao().delete(dbSession, link.getId());
        dbSession.commit();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentLinkDto(org.sonar.db.component.ComponentLinkDto)

Example 10 with ComponentLinkDto

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

the class SearchMyProjectsActionTest method search_json_example.

@Test
public void search_json_example() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto jdk7 = insertJdk7(organizationDto);
    ComponentDto cLang = insertClang(organizationDto);
    dbClient.componentLinkDao().insert(dbSession, new ComponentLinkDto().setComponentUuid(jdk7.uuid()).setHref("http://www.oracle.com").setType(ComponentLinkDto.TYPE_HOME_PAGE).setName("Home"));
    dbClient.componentLinkDao().insert(dbSession, new ComponentLinkDto().setComponentUuid(jdk7.uuid()).setHref("http://download.java.net/openjdk/jdk8/").setType(ComponentLinkDto.TYPE_SOURCES).setName("Sources"));
    long oneTime = DateUtils.parseDateTime("2016-06-10T13:17:53+0000").getTime();
    long anotherTime = DateUtils.parseDateTime("2016-06-11T14:25:53+0000").getTime();
    SnapshotDto jdk7Snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(jdk7).setCreatedAt(oneTime));
    SnapshotDto cLangSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(cLang).setCreatedAt(anotherTime));
    dbClient.measureDao().insert(dbSession, newMeasureDto(alertStatusMetric, jdk7, jdk7Snapshot).setData(Level.ERROR.name()));
    dbClient.measureDao().insert(dbSession, newMeasureDto(alertStatusMetric, cLang, cLangSnapshot).setData(Level.OK.name()));
    db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7);
    db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, cLang);
    db.commit();
    System.setProperty("user.timezone", "UTC");
    String result = ws.newRequest().execute().getInput();
    assertJson(result).isSimilarTo(getClass().getResource("search_my_projects-example.json"));
}
Also used : ComponentLinkDto(org.sonar.db.component.ComponentLinkDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

ComponentLinkDto (org.sonar.db.component.ComponentLinkDto)20 ComponentDto (org.sonar.db.component.ComponentDto)14 Test (org.junit.Test)11 DbSession (org.sonar.db.DbSession)3 SnapshotDto (org.sonar.db.component.SnapshotDto)2 SearchWsResponse (org.sonarqube.ws.WsProjectLinks.SearchWsResponse)2 InputStream (java.io.InputStream)1 MeasureDto (org.sonar.db.measure.MeasureDto)1 MeasureQuery (org.sonar.db.measure.MeasureQuery)1 MetricDto (org.sonar.db.metric.MetricDto)1 OrganizationDto (org.sonar.db.organization.OrganizationDto)1 TestResponse (org.sonar.server.ws.TestResponse)1 WsProjectLinks (org.sonarqube.ws.WsProjectLinks)1