Search in sources :

Example 6 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class SignUpControllerTest method testSubmitForm.

/**
     * Test of submitForm method, of class SignUpController.
     * @throws java.lang.Exception
     */
public void testSubmitForm() throws Exception {
    System.out.println("submitForm");
    setUpMockRoleDataService();
    setUpUserDataService();
    setUpMockExposablePropertyPlaceholderConfigurer();
    setUpValidatorAndBindingResult();
    setUpMockEmailSender();
    // Set up instance dependences
    Model model = new ExtendedModelMap();
    // the returned UserSignUpCommand is seen as valid regarding the validator
    // the CONFIRMATION sign-up page is displayed
    String expResult = TgolKeyStore.SIGN_UP_CONFIRMATION_VIEW_REDIRECT_NAME;
    String result = instance.submitSignUpForm(mockValidCreateUserCommand, mockValidBindingResult, model);
    assertEquals(expResult, result);
    // the returned UserSignUpCommand is seen as invalid regarding the validator
    // the sign-up form is displayed again
    expResult = TgolKeyStore.SIGN_UP_VIEW_NAME;
    result = instance.submitSignUpForm(mockInvalidCreateUserCommand, mockInvalidBindingResult, model);
    assertEquals(expResult, result);
    assertSame(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY), mockInvalidCreateUserCommand);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model)

Example 7 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class SignUpControllerTest method testSetUpSignUpConfirmationPage.

/**
     * Test of setUpSignUpConfirmationPage method, of class SignUpController.
     */
public void testSetUpSignUpConfirmationPage() {
    System.out.println("setUpSignUpConfirmationPage");
    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.SIGN_UP_CONFIRMATION_VIEW_NAME;
    String result = instance.setUpSignUpConfirmationPage(model);
    // the returned view is the sign-up confirmation view name
    assertEquals(expResult, result);
    // the model contains a UserSignUpCommand instance to maps the data of
    // the form of the view
    assertTrue(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY) instanceof CreateUserCommand);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 8 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class SignUpControllerTest method testSetUpSignUpPage.

/**
     * Test of setUpSignUpPage method, of class SignUpController.
     */
public void testSetUpSignUpPage() {
    System.out.println("setUpSignUpPage");
    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.SIGN_UP_VIEW_NAME;
    String result = instance.setUpSignUpPage(model);
    // the returned view is the sign-up view name
    assertEquals(expResult, result);
    // the model contains a UserSignUpCommand instance to maps the data of
    // the form of the view
    assertTrue(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY) instanceof CreateUserCommand);
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 9 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class AuditSetUpControllerTest method testDisplayPageAuditUploadSetUpWithUnauthorisedFunctionality.

public void testDisplayPageAuditUploadSetUpWithUnauthorisedFunctionality() {
    System.out.println("testDisplayPageAuditUploadSetUpWithUnauthorisedFunctionality");
    setUpMockUserDataServiceAndUser();
    setUpMockAuthenticationContext();
    setUpMockContractDataService(2, "Contract1");
    setUpEmptyViewFunctionalityBindingMap();
    // regarding the viewFunctionalityBindingMap. An exception is caught
    try {
        instance.displayUploadAuditSetUp("2", null, null, new ExtendedModelMap());
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
}
Also used : ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Example 10 with ExtendedModelMap

use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.

the class ContractControllerTest method testDisplayContractPage_4args.

/**
     * Test of displayContractPage method, of class HomeController.
     */
public void testDisplayContractPage_4args() {
    System.out.println("displayContractPage");
    setUpUserDataService(false);
    setUpContractDataService(1);
    setUpActDataService(1, 1, 2, 1, 1);
    setUpLocaleResolver();
    setUpActionHandler(1);
    setUpMockAuthenticationContext();
    // contractId cannot be converted as a long, the ForbiddenUserException 
    // is caught
    String contractId = "wrongId";
    HttpServletRequest request = null;
    HttpServletResponse response = null;
    Model model = new ExtendedModelMap();
    try {
        instance.displayContractPage(contractId, request, response, model);
        // if the exception is not caught, the test is on error
        assertTrue(false);
    } catch (ForbiddenPageException fue) {
        assertTrue(true);
    }
    contractId = "1";
    String result = instance.displayContractPage(contractId, request, response, model);
    String expResult = TgolKeyStore.CONTRACT_VIEW_NAME;
    assertEquals(expResult, result);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Model(org.springframework.ui.Model) HttpServletResponse(javax.servlet.http.HttpServletResponse) ForbiddenPageException(org.asqatasun.webapp.exception.ForbiddenPageException)

Aggregations

ExtendedModelMap (org.springframework.ui.ExtendedModelMap)38 Model (org.springframework.ui.Model)24 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)11 ForbiddenPageException (org.asqatasun.webapp.exception.ForbiddenPageException)11 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)10 CreateUserFormValidator (org.asqatasun.webapp.validator.CreateUserFormValidator)6 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)6 BindingResult (org.springframework.validation.BindingResult)6 User (org.asqatasun.webapp.entity.user.User)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ForbiddenUserException (org.asqatasun.webapp.exception.ForbiddenUserException)3 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 Principal (java.security.Principal)1 Enumeration (java.util.Enumeration)1