use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class CommandResolverTest method testFindWikiActionWithParams.
@Test
public void testFindWikiActionWithParams() {
final Page page = m_engine.getManager(PageManager.class).getPage("SinglePage");
// Passing an EDIT request with page param yields a wrapped action
MockHttpServletRequest request = m_engine.newHttpRequest("/Edit.jsp?page=SinglePage");
request.getParameterMap().put("page", new String[] { "SinglePage" });
Command a = resolver.findCommand(request, ContextEnum.PAGE_EDIT.getRequestContext());
Assertions.assertNotSame(PageCommand.EDIT, a);
Assertions.assertEquals("EditContent.jsp", a.getContentTemplate());
Assertions.assertEquals("Edit.jsp", a.getJSP());
Assertions.assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
Assertions.assertEquals(page, a.getTarget());
// Passing an EDIT request with page=Search yields FIND action, *not* edit
request.setContextPath("/Edit.jsp?page=Search");
request.getParameterMap().put("page", new String[] { "Search" });
a = resolver.findCommand(request, ContextEnum.PAGE_EDIT.getRequestContext());
Assertions.assertEquals(WikiCommand.FIND, a);
Assertions.assertEquals("FindContent.jsp", a.getContentTemplate());
Assertions.assertEquals("Search.jsp", a.getJSP());
Assertions.assertEquals("%uSearch.jsp", a.getURLPattern());
Assertions.assertNull(a.getTarget());
// Passing an EDIT request with group="Foo" yields wrapped VIEW_GROUP
request = m_engine.newHttpRequest("/Group.jsp?group=Foo");
request.getParameterMap().put("group", new String[] { "Foo" });
a = resolver.findCommand(request, ContextEnum.PAGE_EDIT.getRequestContext());
Assertions.assertNotSame(GroupCommand.VIEW_GROUP, a);
Assertions.assertEquals("GroupContent.jsp", a.getContentTemplate());
Assertions.assertEquals("Group.jsp", a.getJSP());
Assertions.assertEquals("%uGroup.jsp?group=%n", a.getURLPattern());
Assertions.assertEquals(new GroupPrincipal("Foo"), a.getTarget());
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class RPCHandlerTest method testPageInfo.
@Test
public void testPageInfo() throws Exception {
m_engine.saveText(NAME1, "Foobar.[{ALLOW view Anonymous}]");
final Page directInfo = m_engine.getManager(PageManager.class).getPage(NAME1);
final Hashtable ht = m_handler.getPageInfo(NAME1);
Assertions.assertEquals((String) ht.get("name"), NAME1, "name");
final Date d = (Date) ht.get("lastModified");
final Calendar cal = Calendar.getInstance();
cal.setTime(d);
// System.out.println("Real: "+directInfo.getLastModified() );
// System.out.println("RPC: "+d );
// Offset the ZONE offset and DST offset away. DST only
// if we're actually in DST.
cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(d) ? cal.get(Calendar.DST_OFFSET) : 0)));
// System.out.println("RPC2: "+cal.getTime() );
Assertions.assertEquals(cal.getTime().getTime(), directInfo.getLastModified().getTime(), "date");
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class CounterProvider method initialize.
@Override
public void initialize(final Engine engine, final Properties props) {
m_pages = new Page[] { Wiki.contents().page(engine, "Foo"), Wiki.contents().page(engine, "Bar"), Wiki.contents().page(engine, "Blat"), Wiki.contents().page(engine, "Blaa") };
m_initCalls++;
for (final Page m_page : m_pages) {
m_page.setAuthor("Unknown");
m_page.setLastModified(new Date(0L));
m_page.setVersion(1);
}
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class VersioningFileProviderTest method testMigrationChangesHistory.
/**
* Checks if migration from FileSystemProvider to VersioningFileProvider
* works when a simple text file and its associated properties exist, but
* when there is not yet any corresponding history content in OLD/.
* Update the wiki page and confirm the original simple history was
* assimilated into the newly-created properties.
*/
@Test
public void testMigrationChangesHistory() throws Exception {
// we cannot switch PageProviders within a single test, so the
// initial FileSystemProvider wiki page must be faked.
final String fakeWikiPage = "foobar";
injectFile(NAME1 + AbstractFileProvider.FILE_EXT, fakeWikiPage);
// also create an associated properties file with some history
injectFile(NAME1 + FileSystemProvider.PROP_EXT, FAKE_HISTORY);
final String result1 = engine.getManager(PageManager.class).getText(NAME1);
Assertions.assertEquals(fakeWikiPage, result1, "latest should be initial");
// now update the wiki page to create a new version
final String text = "diddo\r\n";
engine.saveText(NAME1, text);
// confirm the right number of versions have been recorded
final List<WikiPage> versionHistory = engine.getManager(PageManager.class).getVersionHistory(NAME1);
Assertions.assertEquals(2, versionHistory.size(), "number of versions");
// fetch the updated page
final String result2 = engine.getManager(PageManager.class).getText(NAME1);
Assertions.assertEquals(text, result2, "latest should be new version");
// Should be the 2nd version.
final String result3 = engine.getManager(PageManager.class).getText(NAME1, 2);
Assertions.assertEquals(text, result3, "fetch new by version did not work");
// now confirm the original page has been archived
final String result4 = engine.getManager(PageManager.class).getText(NAME1, 1);
Assertions.assertEquals(fakeWikiPage, result4, "fetch original by version Assertions.failed");
final Page pageNew = engine.getManager(PageManager.class).getPage(NAME1, 2);
Assertions.assertEquals(2, pageNew.getVersion(), "new version");
Assertions.assertEquals("Guest", pageNew.getAuthor(), "new author");
final Page pageOld = engine.getManager(PageManager.class).getPage(NAME1, 1);
Assertions.assertEquals(1, pageOld.getVersion(), "old version");
Assertions.assertEquals(OLD_AUTHOR, pageOld.getAuthor(), "old author");
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class VersioningFileProviderTest method testMigrationInfoAvailable.
/*
* Checks if a page created or last modified by FileSystemProvider
* will be seen by VersioningFileProvider as the "first" version.
*/
@Test
public void testMigrationInfoAvailable() throws IOException {
// we cannot switch PageProviders within a single test, so the
// initial FileSystemProvider wiki page must be faked.
final String fakeWikiPage = "foobar";
injectFile(NAME1 + AbstractFileProvider.FILE_EXT, fakeWikiPage);
// also create an associated properties file with some history
injectFile(NAME1 + FileSystemProvider.PROP_EXT, FAKE_HISTORY);
final String res = engine.getManager(PageManager.class).getText(NAME1);
Assertions.assertEquals(fakeWikiPage, res, "fetch latest should work");
final Page page = engine.getManager(PageManager.class).getPage(NAME1, 1);
Assertions.assertEquals(1, page.getVersion(), "original version expected");
Assertions.assertEquals(OLD_AUTHOR, page.getAuthor(), "original author");
}
Aggregations