@Test public void select_by_id() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertProvidedLink(project, c -> c .setUuid("ABCD") .setName("Home") .setType("homepage") .setHref("http://www.struts.org")); ProjectLinkDto reloaded = underTest.selectByUuid(db.getSession(), link.getUuid()); assertThat(reloaded.getUuid()).isEqualTo("ABCD"); assertThat(reloaded.getProjectUuid()).isEqualTo(project.uuid()); assertThat(reloaded.getType()).isEqualTo("homepage"); assertThat(reloaded.getName()).isEqualTo("Home"); assertThat(reloaded.getHref()).isEqualTo("http://www.struts.org"); assertThat(reloaded.getCreatedAt()).isEqualTo(NOW); assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW); }
@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(); }
@SafeVarargs public final ProjectLinkDto insertProvidedLink(ComponentDto project, Consumer<ProjectLinkDto>... dtoPopulators) { return insertLink(project, newProvidedLinkDto(), dtoPopulators); }
@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")); }
private DbTester(System2 system2, @Nullable String schemaPath, MyBatisConfExtension... confExtensions) { super(TestDb.create(schemaPath, confExtensions)); this.system2 = system2; initDbClient(); this.userTester = new UserDbTester(this); this.componentTester = new ComponentDbTester(this); this.componentLinkTester = new ProjectLinkDbTester(this); this.favoriteTester = new FavoriteDbTester(this); this.eventTester = new EventDbTester(this); this.organizationTester = new OrganizationDbTester(this); this.permissionTemplateTester = new PermissionTemplateDbTester(this); this.propertyTester = new PropertyDbTester(this); this.qualityGateDbTester = new QualityGateDbTester(this); this.issueDbTester = new IssueDbTester(this); this.ruleDbTester = new RuleDbTester(this); this.notificationDbTester = new NotificationDbTester(this); this.rootFlagAssertions = new RootFlagAssertions(this); this.qualityProfileDbTester = new QualityProfileDbTester(this); this.measureDbTester = new MeasureDbTester(this); this.fileSourceTester = new FileSourceTester(this); this.pluginDbTester = new PluginDbTester(this); this.webhookDbTester = new WebhookDbTester(this); this.webhookDeliveryDbTester = new WebhookDeliveryDbTester(this); this.almDbTester = new AlmDbTester(this); }
@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())); }
@Test public void select_by_project_uuids() { ComponentDto project1 = db.components().insertPrivateProject(); ProjectLinkDto link1 = db.componentLinks().insertProvidedLink(project1); ProjectLinkDto link2 = db.componentLinks().insertProvidedLink(project1); ComponentDto project2 = db.components().insertPrivateProject(); ProjectLinkDto link3 = db.componentLinks().insertProvidedLink(project2); assertThat(underTest.selectByProjectUuids(db.getSession(), asList(project1.uuid(), project2.uuid()))) .extracting(ProjectLinkDto::getUuid) .containsOnly(link1.getUuid(), link2.getUuid(), link3.getUuid()); assertThat(underTest.selectByProjectUuids(db.getSession(), singletonList(project1.uuid()))) .extracting(ProjectLinkDto::getUuid) .containsOnly(link1.getUuid(), link2.getUuid()); assertThat(underTest.selectByProjectUuids(db.getSession(), Collections.emptyList())).isEmpty(); }
@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); }
@SafeVarargs public final ProjectLinkDto insertCustomLink(ComponentDto project, Consumer<ProjectLinkDto>... dtoPopulators) { return insertLink(project, newCustomLinkDto(), dtoPopulators); }
@Test public void delete() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertProvidedLink(project); underTest.delete(db.getSession(), link.getUuid()); db.getSession().commit(); assertThat(db.countRowsOfTable("project_links")).isEqualTo(0); }
@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 select_by_project_uuid() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link1 = db.componentLinks().insertProvidedLink(project); ProjectLinkDto link2 = db.componentLinks().insertProvidedLink(project); ProjectLinkDto link3 = db.componentLinks().insertProvidedLink(project); ComponentDto otherProject = db.components().insertPrivateProject(); ProjectLinkDto otherLink = db.componentLinks().insertProvidedLink(otherProject); assertThat(underTest.selectByProjectUuid(db.getSession(), project.uuid())) .extracting(ProjectLinkDto::getUuid) .containsExactlyInAnyOrder(link1.getUuid(), link2.getUuid(), link3.getUuid()); assertThat(underTest.selectByProjectUuid(db.getSession(), otherProject.uuid())) .extracting(ProjectLinkDto::getUuid) .containsExactlyInAnyOrder(otherLink.getUuid()); assertThat(underTest.selectByProjectUuid(db.getSession(), "UNKNOWN")).isEmpty(); }
@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 update() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertProvidedLink(project, c -> c .setUuid("ABCD") .setType("ci") .setName("Gihub") .setHref("http://www.github.org")); // Force dates to be in the past db.executeUpdateSql("UPDATE project_links SET created_at=" + PAST + " ,updated_at=" + PAST); ComponentDto project2 = db.components().insertPrivateProject(); underTest.update(db.getSession(), link .setProjectUuid(project2.uuid()) .setType("homepage") .setName("Home") .setHref("http://www.sonarqube.org")); db.getSession().commit(); ProjectLinkDto reloaded = underTest.selectByUuid(db.getSession(), link.getUuid()); assertThat(reloaded.getUuid()).isEqualTo("ABCD"); assertThat(reloaded.getProjectUuid()).isEqualTo(project2.uuid()); assertThat(reloaded.getType()).isEqualTo("homepage"); assertThat(reloaded.getName()).isEqualTo("Home"); assertThat(reloaded.getHref()).isEqualTo("http://www.sonarqube.org"); assertThat(reloaded.getCreatedAt()).isEqualTo(PAST); assertThat(reloaded.getUpdatedAt()).isEqualTo(NOW); }
@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 fail_when_delete_provided_link() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertProvidedLink(project); logInAsProjectAdministrator(project); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Provided link cannot be deleted"); 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_does_not_fail_when_link_has_no_name() { ComponentDto project = db.components().insertPrivateProject(); ProjectLinkDto link = db.componentLinks().insertProvidedLink(project); logInAsProjectAdministrator(project); SearchWsResponse response = callByKey(project.getKey()); assertThat(response.getLinksList()) .extracting(Link::getId, Link::hasName) .containsExactlyInAnyOrder(tuple(link.getUuid(), false)); }
@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 search_json_example() { OrganizationDto organizationDto = db.organizations().insert(); ComponentDto jdk7 = insertJdk7(organizationDto); ComponentDto cLang = insertClang(organizationDto); db.componentLinks().insertProvidedLink(jdk7, l -> l.setHref("http://www.oracle.com").setType(ProjectLinkDto.TYPE_HOME_PAGE).setName("Home")); db.componentLinks().insertProvidedLink(jdk7, l -> l.setHref("http://download.java.net/openjdk/jdk8/").setType(ProjectLinkDto.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.liveMeasureDao().insert(dbSession, newLiveMeasure(jdk7, alertStatusMetric).setData(Level.ERROR.name())); dbClient.liveMeasureDao().insert(dbSession, newLiveMeasure(cLang, alertStatusMetric).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")); }