Search in sources :

Example 21 with MockHttpServletRequest

use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.

the class TestEngine method saveText.

/**
 * Convenience method that saves a wiki page by constructing a fake
 * WikiContext and HttpServletRequest. We always want to do this using a
 * WikiContext whose subject contains Role.ADMIN.
 * Note: the WikiPage author will have the default value of "Guest".
 * @param pageName
 * @param content
 * @throws WikiException
 */
public void saveText(String pageName, String content) throws WikiException {
    // Build new request and associate our admin session
    MockHttpServletRequest request = newHttpRequest();
    WikiSession wikiSession = SessionMonitor.getInstance(this).find(request.getSession());
    this.getAuthenticationManager().login(wikiSession, request, Users.ADMIN, Users.ADMIN_PASS);
    // Create page and wiki context
    WikiPage page = new WikiPage(this, pageName);
    WikiContext context = new WikiContext(this, request, page);
    saveText(context, content);
}
Also used : MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest)

Example 22 with MockHttpServletRequest

use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.

the class TestEngine method saveTextAsJanne.

public void saveTextAsJanne(String pageName, String content) throws WikiException {
    // Build new request and associate our Janne session
    MockHttpServletRequest request = newHttpRequest();
    WikiSession wikiSession = SessionMonitor.getInstance(this).find(request.getSession());
    this.getAuthenticationManager().login(wikiSession, request, Users.JANNE, Users.JANNE_PASS);
    // Create page and wiki context
    WikiPage page = new WikiPage(this, pageName);
    page.setAuthor(Users.JANNE);
    WikiContext context = new WikiContext(this, request, page);
    saveText(context, content);
}
Also used : MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest)

Example 23 with MockHttpServletRequest

use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.

the class TestEngine method newHttpRequest.

/**
 * Creates a correctly-instantiated mock HttpServletRequest with an associated
 * HttpSession and path.
 * @param path the path relative to the wiki context, for example "/Wiki.jsp"
 * @return the new request
 */
public MockHttpServletRequest newHttpRequest(String path) {
    MockHttpServletRequest request = new MockHttpServletRequest("/JSPWiki", path);
    request.setSession(new MockHttpSession(this.getServletContext()));
    request.addLocale(new Locale(""));
    return request;
}
Also used : Locale(java.util.Locale) MockHttpServletRequest(net.sourceforge.stripes.mock.MockHttpServletRequest) MockHttpSession(net.sourceforge.stripes.mock.MockHttpSession)

Aggregations

MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)23 Test (org.junit.Test)10 Cookie (javax.servlet.http.Cookie)6 WikiPrincipal (org.apache.wiki.auth.WikiPrincipal)6 Principal (java.security.Principal)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 LoginException (javax.security.auth.login.LoginException)4 LoginModule (javax.security.auth.spi.LoginModule)4 WikiContext (org.apache.wiki.WikiContext)4 Collection (java.util.Collection)3 HashSet (java.util.HashSet)2 MockHttpServletResponse (net.sourceforge.stripes.mock.MockHttpServletResponse)2 Locale (java.util.Locale)1 Properties (java.util.Properties)1 Subject (javax.security.auth.Subject)1 MockHttpSession (net.sourceforge.stripes.mock.MockHttpSession)1 WikiPage (org.apache.wiki.WikiPage)1 WikiSession (org.apache.wiki.WikiSession)1 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)1