Wikipedia implements WikiConstants { public Title getTitle(int pageId) throws WikiApiException { Session session = this.__getHibernateSession(); session.beginTransaction(); Object returnValue = session.createNativeQuery( "select p.name from PageMapLine as p where p.pageId= :pId").setParameter("pId", pageId, IntegerType.INSTANCE).uniqueResult(); session.getTransaction().commit(); String title = (String)returnValue; if(title==null){ throw new WikiPageNotFoundException(); } return new Title(title); } Wikipedia(DatabaseConfiguration dbConfig); Page getPage(String title); Page getPageByExactTitle(String exactTitle); Set<Page> getPages(String title); Page getPage(int pageId); Title getTitle(int pageId); List<Integer> getPageIds(String title); List<Integer> getPageIdsCaseInsensitive(String title); Page getArticleForDiscussionPage(Page discussionPage); Page getDiscussionPage(int articlePageId); Page getDiscussionPage(String title); Page getDiscussionPage(Page articlePage); Iterable<Page> getDiscussionArchives(int articlePageId); Iterable<Page> getDiscussionArchives(String title); Iterable<Page> getDiscussionArchives(Page articlePage); Category getCategory(String title); Category getCategory(int pageId); Iterable<Category> getCategories(); Set<Category> getCategories(String pageTitle); Iterable<Page> getPages(); Iterable<Integer> getPageIds(); Iterable<Page> getPages(PageQuery query); Iterable<Page> getArticles(); Iterable<Title> getTitles(); Language getLanguage(); boolean existsPage(String title); boolean existsPage(int pageID); MetaData getMetaData(); DatabaseConfiguration getDatabaseConfiguration(); String getWikipediaId();  }
@Test public void testGetTitleByID() { try { Title title = wiki.getTitle(A_FAMOUS_PAGE_ID); assertNotNull(title); assertEquals(A_FAMOUS_PAGE, title.getRawTitleText()); assertEquals(A_FAMOUS_PAGE_CLEAN, title.getPlainTitle()); } catch (WikiPageNotFoundException nfe) { fail("Encountered WikiPageNotFoundException: " + nfe.getLocalizedMessage()); } catch (WikiApiException ae) { fail("Encountered WikiApiException: " + ae.getLocalizedMessage()); } }
@Test public void testGetTitleByIDInvalid() { try { wiki.getTitle(-42); } catch (WikiPageNotFoundException wpnfe) { } catch (WikiApiException e) { fail("Expected a WikiApiException, yet encountered WikiApiException: " + e.getLocalizedMessage()); } }