@Test public void no_response() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertCustomLink(project); logInAsProjectAdministrator(project); TestResponse response = deleteLink(link); assertThat(response.getStatus()).isEqualTo(204); assertThat(response.getInput()).isEmpty(); }
@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())); }
@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()); }
@Test public void fail_if_not_project_admin() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertCustomLink(project); userSession.logIn(); expectedException.expect(ForbiddenException.class); deleteLink(link); }
@Test public void fail_if_anonymous() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertCustomLink(project); userSession.anonymous(); expectedException.expect(ForbiddenException.class); deleteLink(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()); }
@Test public void request_by_project_id() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertCustomLink(project); logInAsProjectAdministrator(project); SearchWsResponse response = callByUuid(project.uuid()); assertThat(response.getLinksList()) .extracting(Link::getId, Link::getName) .containsExactlyInAnyOrder(tuple(link.getUuid(), link.getName())); }
@Test public void request_by_project_key() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertCustomLink(project); logInAsProjectAdministrator(project); SearchWsResponse response = callByKey(project.getKey()); assertThat(response.getLinksList()) .extracting(Link::getId, Link::getName) .containsExactlyInAnyOrder(tuple(link.getUuid(), link.getName())); }
@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())); }
@Test public void project_administrator_can_search_for_links() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertCustomLink(project); userSession.logIn().addProjectPermission(UserRole.ADMIN, project); SearchWsResponse response = callByKey(project.getKey()); assertThat(response.getLinksList()) .extracting(Link::getId, Link::getName) .containsExactlyInAnyOrder(tuple(link.getUuid(), link.getName())); }
@Test public void not_delete_custom_link() { mockBranch(true); ComponentDto project = db.components().insertPrivateProject(p -> p.setUuid("ABCD")); db.componentLinks().insertCustomLink(project); treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build()); reportReader.putComponent(ScannerReport.Component.newBuilder() .setRef(1) .setType(ComponentType.PROJECT) .build()); underTest.execute(new TestComputationStepContext()); assertThat(db.countRowsOfTable("project_links")).isEqualTo(1); }
@Test public void example() { ComponentDto project = db.components().insertPrivateProject(); db.componentLinks().insertProvidedLink(project, l -> l.setUuid("1").setType("homepage").setName("Homepage").setHref("http://example.org")); db.componentLinks().insertCustomLink(project, l -> l.setUuid("2").setType("custom").setName("Custom").setHref("http://example.org/custom")); logInAsProjectAdministrator(project); String result = ws.newRequest() .setParam(PARAM_PROJECT_KEY, project.getKey()) .execute().getInput(); assertJson(result).isSimilarTo(getClass().getResource("search-example.json")); }
@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())); }