Exemplo n.º 1
0
 @Override
 public void postWikiPage(
     TaskRepository repository, TracWikiPage newPage, IProgressMonitor monitor)
     throws CoreException {
   monitor.beginTask(Messages.TracWikiHandler_Upload_Wiki_Page, IProgressMonitor.UNKNOWN);
   try {
     String pageName = newPage.getPageInfo().getPageName();
     String content = newPage.getContent();
     Map<String, Object> attributes = new HashMap<String, Object>();
     attributes.put("comment", newPage.getPageInfo().getComment()); // $NON-NLS-1$
     attributes.put("author", newPage.getPageInfo().getAuthor()); // $NON-NLS-1$
     boolean success =
         getTracWikiClient(repository).putWikipage(pageName, content, attributes, monitor);
     if (success) {
       return;
     } else {
       throw new CoreException(
           TracCorePlugin.toStatus(
               new TracException("Failed to upload wiki page. No further information available."),
               repository)); //$NON-NLS-1$
     }
   } catch (TracException e) {
     throw new CoreException(TracCorePlugin.toStatus(e, repository));
   } finally {
     monitor.done();
   }
 }
  public void testGetWikiPage() throws Exception {
    String pageName = "TestGetPage" + RandomStringUtils.randomAlphanumeric(6);
    harness.createWikiPage(pageName, "Version 1");
    harness.createWikiPage(pageName, "Version 2");

    TracWikiPage page = client.getWikiPage(pageName, null);
    assertEquals(pageName, page.getPageInfo().getPageName());
    assertEquals("*****@*****.**", page.getPageInfo().getAuthor());
    assertEquals(2, page.getPageInfo().getVersion());
    // XXX The Date returned from Wiki API seems to have a problem with the Time Zone
    // String date = "Sat Nov 11 18:10:56 EST 2006";
    // assertEquals(date, page.getPageVersion().getLastModified().toString());
    assertEquals("Version 2", page.getContent());
    assertTrue(page.getPageHTML().startsWith("<html>"));

    page = client.getWikiPage(pageName, 1, null);
    assertEquals(pageName, page.getPageInfo().getPageName());
    assertEquals("*****@*****.**", page.getPageInfo().getAuthor());
    assertEquals(1, page.getPageInfo().getVersion());
    assertEquals("Version 1", page.getContent());
    assertTrue(page.getPageHTML().startsWith("<html>"));
  }