Search in sources :

Example 11 with Model

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

the class UserManagementControllerTest method testSubmitAddUserForm.

/**
     * Test of submitAddUserForm method, of class UserManagementController.
     */
public void testSubmitAddUserForm() throws Exception {
    System.out.println("submitAddUserForm");
    instance = new UserManagementController();
    setUpMockRoleDataService();
    setUpMockUserDataService(false, true, false, false, false);
    setUpMockAuthenticationContext();
    instance.setUserDataService(mockUserDataService);
    CreateUserFormValidator createUserFormValidator = new CreateUserFormValidator();
    createUserFormValidator.setUserDataService(mockUserDataService);
    instance.setCreateUserFormValidator(createUserFormValidator);
    // Finally the form is conform and the admin page is returned
    CreateUserCommand createUserCommand = CreateUserCommandFactory.getInstance().getNewCreateUserCommand();
    createUserCommand.setSiteUrl("http://www.newSite.com/");
    createUserCommand.setEmail("newUser@test.com");
    createUserCommand.setPassword("P4sSw0rD");
    createUserCommand.setConfirmPassword("P4sSw0rD");
    BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
    Model model = new ExtendedModelMap();
    String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
    assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
    assertFalse(bindingResult.hasErrors());
    assertTrue(bindingResult.getFieldErrors().isEmpty());
    assertEquals(2, model.asMap().size());
    assertEquals("newUser@test.com", model.asMap().get(TgolKeyStore.ADDED_USER_NAME_KEY));
    assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Also used : BindingResult(org.springframework.validation.BindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) User(org.asqatasun.webapp.entity.user.User) Model(org.springframework.ui.Model) CreateUserFormValidator(org.asqatasun.webapp.validator.CreateUserFormValidator) CreateUserCommand(org.asqatasun.webapp.command.CreateUserCommand)

Example 12 with Model

use of org.springframework.ui.Model 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 13 with Model

use of org.springframework.ui.Model 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 14 with Model

use of org.springframework.ui.Model 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 15 with Model

use of org.springframework.ui.Model 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

Model (org.springframework.ui.Model)38 ExtendedModelMap (org.springframework.ui.ExtendedModelMap)24 HttpServletResponse (javax.servlet.http.HttpServletResponse)15 BindingResult (org.springframework.validation.BindingResult)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 CreateUserCommand (org.asqatasun.webapp.command.CreateUserCommand)10 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 MediaType (org.springframework.http.MediaType)8 IOException (java.io.IOException)6 Map (java.util.Map)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 WebDataBinder (org.springframework.web.bind.WebDataBinder)6 GetRequest (com.mashape.unirest.request.GetRequest)5 FileNotFoundException (java.io.FileNotFoundException)5 DateFormat (java.text.DateFormat)5 SimpleDateFormat (java.text.SimpleDateFormat)5 java.util (java.util)5 Valid (javax.validation.Valid)5