use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testDisplayAdminPage.
/**
* Test of displayAdminPage method, of class UserManagementController.
*/
public void testDisplayAdminPage() {
System.out.println("displayAdminPage");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, false, false);
setUpMockAuthenticationContext();
instance.setUserDataService(mockUserDataService);
HttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
Model model = new ExtendedModelMap();
String result = instance.displayAdminPage(request, response, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
}
use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitEditUserForm.
/**
* Test of submitEditUserForm method, of class UserManagementController.
*/
public void testSubmitEditUserForm() throws Exception {
System.out.println("submitEditUserForm");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, true, 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.setEmail("user@test.com");
createUserCommand.setLastName("newName");
createUserCommand.setFirstName("newFirstName");
createUserCommand.setPhoneNumber("0102030405");
createUserCommand.setActivated(false);
createUserCommand.setAdmin(true);
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, Long.valueOf(5));
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("user@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testDeleteUserConfirmation.
/**
* Test of deleteUserConfirmation method, of class UserManagementController.
*/
public void testDeleteUserConfirmation() {
System.out.println("deleteUserConfirmation");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(true, false, false, false, false);
setUpMockAuthenticationContext();
instance.setUserDataService(mockUserDataService);
HttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
Model model = new ExtendedModelMap();
String idToRemove = "idToRemove";
request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, idToRemove);
try {
instance.displayDeleteUserConfirmation(request, response, model);
assertTrue(false);
} catch (ForbiddenUserException fue) {
assertTrue(true);
}
idToRemove = "4";
request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, idToRemove);
String result = instance.displayDeleteUserConfirmation(request, response, model);
assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, Long.valueOf(6));
result = instance.displayDeleteUserConfirmation(request, response, model);
assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, Long.valueOf(5));
result = instance.displayDeleteUserConfirmation(request, response, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME, result);
assertTrue(model.asMap().isEmpty());
assertEquals("user@test.com", request.getSession().getAttribute(TgolKeyStore.DELETED_USER_NAME_KEY));
}
use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testDeleteUserPage.
/**
* Test of deleteUserPage method, of class UserManagementController.
*/
public void testDeleteUserPage() {
System.out.println("deleteUserPage");
instance = new UserManagementController();
setUpMockRoleDataService();
setUpMockUserDataService(false, false, false, false, false);
setUpMockAuthenticationContext();
instance.setUserDataService(mockUserDataService);
HttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
Model model = new ExtendedModelMap();
String idToRemove = "idToRemove";
try {
instance.displayDeleteUserPage(idToRemove, request, response, model);
assertTrue(false);
} catch (ForbiddenUserException fue) {
assertTrue(true);
}
idToRemove = "4";
String result = instance.displayDeleteUserPage(idToRemove, request, response, model);
assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
idToRemove = "6";
result = instance.displayDeleteUserPage(idToRemove, request, response, model);
assertEquals(TgolKeyStore.ACCESS_DENIED_VIEW_NAME, result);
idToRemove = "5";
result = instance.displayDeleteUserPage(idToRemove, request, response, model);
assertEquals(TgolKeyStore.DELETE_USER_VIEW_NAME, result);
assertEquals("user@test.com", model.asMap().get(TgolKeyStore.USER_NAME_TO_DELETE_KEY));
assertEquals(Long.valueOf(5), request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY));
assertEquals(1, model.asMap().size());
}
use of org.springframework.ui.ExtendedModelMap in project Asqatasun by Asqatasun.
the class AuditSetUpControllerTest method testDisplayPageAuditPageSetUpWithWrongContractId.
public void testDisplayPageAuditPageSetUpWithWrongContractId() {
System.out.println("testDisplayPageAuditPageSetUpWithWrongContractId");
// set-up
setUpMockUserDataServiceAndUser();
setUpMockAuthenticationContext();
setUpMockContractDataService(1, "Contract1");
// the contract Id cannot be converted as a Long. An exception is caught
try {
instance.displayPageAuditSetUp("Not a number", null, null, new ExtendedModelMap());
assertTrue(false);
} catch (ForbiddenPageException fue) {
assertTrue(true);
}
}
Aggregations