@Test public void testListUsers() throws Exception { assertNull(action.getUsers()); assertEquals("success", action.list()); assertNotNull(action.getUsers()); assertFalse(action.hasActionErrors()); }
@Override public void onUserAction( com.sessionm.api.SessionM instance, UserAction action, Map<String, String> data) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, this + ".onUserAction(): " + action.getCode() + ", data: " + data); } JSONObject jsonObject = new JSONObject(); try { jsonObject.put("userAction", action.getCode()); if (data != null) { JSONObject dataObject = new JSONObject(); for (Map.Entry<String, String> entry : data.entrySet()) { dataObject.put(entry.getKey(), entry.getValue()); } jsonObject.put("data", dataObject); } } catch (JSONException e) { if (Log.isLoggable(TAG, Log.DEBUG)) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "JSONException when trying to get userAction: " + e); } } } if (callbackGameObjectName != null) { UnityPlayer.UnitySendMessage( callbackGameObjectName, "_sessionM_HandleUserActionMessage", jsonObject.toString()); } }
@Test public void testRemove() throws Exception { User user = new User("admin"); user.setId(-2L); action.setUser(user); assertEquals("success", action.delete()); assertFalse(action.hasActionErrors()); }
@Test public void testCancel() throws Exception { assertEquals(action.cancel(), "mainMenu"); assertFalse(action.hasActionErrors()); action.setFrom("list"); assertEquals("cancel", action.cancel()); }
@Test public void testSearch() throws Exception { compassGps.index(); action.setQ("admin"); assertEquals("success", action.list()); assertNotNull(action.getUsers()); assertTrue(action.getUsers().size() >= 1); assertFalse(action.hasActionErrors()); }
@Test public void testEdit() throws Exception { // so request.getRequestURL() doesn't fail MockHttpServletRequest request = new MockHttpServletRequest("GET", "/editUser.html"); ServletActionContext.setRequest(request); action.setId("-1"); // regular user assertNull(action.getUser()); assertEquals("success", action.edit()); assertNotNull(action.getUser()); assertFalse(action.hasActionErrors()); }
@Test public void testNewn() throws Exception { initServletMockObjects(); ActionProxy proxy = getActionProxy("/user/new"); UserAction userAction = (UserAction) proxy.getAction(); String result = proxy.execute(); assertEquals(Action.SUCCESS, result); User user = userAction.getUser(); assertNotNull(user); }
@Test public void testList() throws Exception { initServletMockObjects(); request.setParameter("search.firstName", "first_name_page"); request.setParameter("search.lastName", "last_name_page"); ActionProxy proxy = getActionProxy("/user/list"); UserAction userAction = (UserAction) proxy.getAction(); String result = proxy.execute(); assertEquals(Action.SUCCESS, result); List<UserView> listLogin = userAction.getListLogin(); assertEquals(3, listLogin.size()); }
@Test public void testEdit() throws Exception { initServletMockObjects(); request.setParameter("id", "102"); ActionProxy proxy = getActionProxy("/user/edit"); UserAction userAction = (UserAction) proxy.getAction(); String result = proxy.execute(); assertEquals(Action.SUCCESS, result); User user = userAction.getUser(); assertNotNull(user); assertEquals("first_name_102", user.getFirstName()); assertEquals("last_name_102", user.getLastName()); }
@Test public void testSave() throws Exception { UserManager userManager = (UserManager) applicationContext.getBean("userManager"); User user = userManager.getUserByUsername("user"); user.setPassword("user"); user.setConfirmPassword("user"); action.setUser(user); action.setFrom("list"); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("encryptPass", "true"); ServletActionContext.setRequest(request); assertEquals("input", action.save()); assertNotNull(action.getUser()); assertFalse(action.hasActionErrors()); }
@Test public void testSaveConflictingUser() throws Exception { UserManager userManager = (UserManager) applicationContext.getBean("userManager"); User user = userManager.getUserByUsername("user"); user.setPassword("user"); user.setConfirmPassword("user"); // e-mail address from existing user User existingUser = (User) userManager.getUsers().get(0); user.setEmail(existingUser.getEmail()); action.setUser(user); action.setFrom("list"); Integer originalVersionNumber = user.getVersion(); log.debug("original version #: " + originalVersionNumber); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("encryptPass", "true"); ServletActionContext.setRequest(request); assertEquals("input", action.save()); assertNotNull(action.getUser()); assertEquals(originalVersionNumber, user.getVersion()); assertTrue(action.hasActionErrors()); }
@Test public void testExecuteAction() throws Exception { // UserAction userAction = (UserAction) ac.getBean("userAction"); userAction.execute(); }