Difference between revisions of "Examples"

From BITPlan mediawiki-japi Wiki
Jump to navigation Jump to search
Line 5: Line 5:
 
Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
 
Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
 
String content=wiki.getPageContent("Main Page");
 
String content=wiki.getPageContent("Main Page");
 +
</source>
 +
=== JUnit Test ====
 +
<source lang='java'>
 +
/**
 +
* http://www.mediawiki.org/wiki/API:Query#Sample_query
 +
* http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&titles=Main%20Page&format=xml
 +
* @throws Exception
 +
*/
 +
@Test
 +
public void testSampleQuery() throws Exception {
 +
  Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
 +
  String content=wiki.getPageContent("Main Page");
 +
  assertTrue(content.contains("Wikipedia"));
 +
}
 
</source>
 
</source>

Revision as of 08:58, 4 January 2015

Sample query:get a single page

http://www.mediawiki.org/wiki/API:Query#Sample_query

Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
String content=wiki.getPageContent("Main Page");

JUnit Test =

/**
 * http://www.mediawiki.org/wiki/API:Query#Sample_query
 * http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&titles=Main%20Page&format=xml
 * @throws Exception 
 */
@Test
public void testSampleQuery() throws Exception {
  Mediawiki wiki=new Mediawiki("http://en.wikipedia.org");
  String content=wiki.getPageContent("Main Page");
  assertTrue(content.contains("Wikipedia"));
}