Search in sources :

Example 1 with Action

use of teammates.ui.controller.Action in project teammates by TEAMMATES.

the class BaseActionTest method verifyCannotAccess.

/**
 * Verifies that the {@link Action} matching the {@code params} is not
 * accessible to the logged in user.
 * This could be one of the following ways:
 * -> Unauthorised Access Exception
 * ->
 */
protected void verifyCannotAccess(String... params) {
    try {
        Action c = gaeSimulation.getActionObject(getActionUri(), params);
        ActionResult result = c.executeAndPostProcess();
        String classNameOfResult = result.getClass().getName();
        assertEquals(classNameOfResult, result.getClass().getName());
        AssertHelper.assertContains("You are not registered in the course ", result.getStatusMessage());
    } catch (UnauthorizedAccessException e) {
        ignoreExpectedException();
    }
}
Also used : Action(teammates.ui.controller.Action) ActionResult(teammates.ui.controller.ActionResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException)

Example 2 with Action

use of teammates.ui.controller.Action in project teammates by TEAMMATES.

the class BaseActionTest method verifyRedirectTo.

/**
 * Verifies that the {@link Action} matching the {@code params} is
 * redirected to {@code expectedRedirectUrl}. Note that only the base
 * URI is matched and parameters are ignored. E.g. "/page/studentHome"
 * matches "/page/studentHome?user=abc".
 */
protected void verifyRedirectTo(String expectedRedirectUrl, String... params) {
    Action c = gaeSimulation.getActionObject(getActionUri(), params);
    RedirectResult r = getRedirectResult(c);
    AssertHelper.assertContains(expectedRedirectUrl, r.destination);
}
Also used : Action(teammates.ui.controller.Action) RedirectResult(teammates.ui.controller.RedirectResult)

Example 3 with Action

use of teammates.ui.controller.Action in project teammates by TEAMMATES.

the class GaeSimulation method getActionObject.

/**
 * Returns an {@link Action} object that matches the parameters given.
 *
 * @param parameters Parameters that appear in a HttpServletRequest received by the app.
 */
public Action getActionObject(String uri, String... parameters) {
    HttpServletRequest req = createWebRequest(uri, parameters);
    Action action = new ActionFactory().getAction(req);
    action.setTaskQueuer(new MockTaskQueuer());
    action.setEmailSender(new MockEmailSender());
    return action;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AutomatedAction(teammates.ui.automated.AutomatedAction) Action(teammates.ui.controller.Action) AutomatedActionFactory(teammates.ui.automated.AutomatedActionFactory) ActionFactory(teammates.ui.controller.ActionFactory)

Example 4 with Action

use of teammates.ui.controller.Action in project teammates by TEAMMATES.

the class BaseActionTest method verifyCanAccess.

/*
     * 'low-level' tests here it tests an action once with the given parameters.
     * These methods are not aware of the user type.
     */
/**
 * Verifies that the {@link Action} matching the {@code params} is
 * accessible to the logged in user.
 */
protected void verifyCanAccess(String... params) {
    Action c = gaeSimulation.getActionObject(getActionUri(), params);
    assertTrue(c.isValidUser());
    c.executeAndPostProcess();
}
Also used : Action(teammates.ui.controller.Action)

Example 5 with Action

use of teammates.ui.controller.Action in project teammates by TEAMMATES.

the class BaseActionTest method verifyRedirectToLoginOrUnauthorisedException.

private void verifyRedirectToLoginOrUnauthorisedException(String... params) {
    try {
        Action c = gaeSimulation.getActionObject(getActionUri(), params);
        assertFalse(c.isValidUser());
    } catch (UnauthorizedAccessException ue) {
        ignoreExpectedException();
    }
}
Also used : Action(teammates.ui.controller.Action) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException)

Aggregations

Action (teammates.ui.controller.Action)8 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 InvalidPostParametersException (teammates.common.exception.InvalidPostParametersException)1 AutomatedAction (teammates.ui.automated.AutomatedAction)1 AutomatedActionFactory (teammates.ui.automated.AutomatedActionFactory)1 ActionFactory (teammates.ui.controller.ActionFactory)1 ActionResult (teammates.ui.controller.ActionResult)1 RedirectResult (teammates.ui.controller.RedirectResult)1