()
| 917 | } |
| 918 | |
| 919 | @Test |
| 920 | public void testUpdateUserRole() |
| 921 | { |
| 922 | String userName = new String("WasUserNowAdmin"); |
| 923 | String currentRole = new String(); |
| 924 | String newRole = new String(); |
| 925 | try |
| 926 | { |
| 927 | if(GetterTest.verifyTestUser(applicationRoot, userName, userName)) |
| 928 | { |
| 929 | Connection conn = Database.getCoreConnection(applicationRoot); |
| 930 | PreparedStatement ps = conn.prepareStatement("SELECT userRole FROM users WHERE userName = ?"); |
| 931 | ps.setString(1, userName); |
| 932 | ResultSet rs = ps.executeQuery(); |
| 933 | if(rs.next()) |
| 934 | { |
| 935 | currentRole = rs.getString(1); |
| 936 | if(currentRole.equalsIgnoreCase("admin")) |
| 937 | { |
| 938 | log.debug("User is currently an admin. Changing to player"); |
| 939 | newRole = new String("player"); |
| 940 | } |
| 941 | else |
| 942 | { |
| 943 | log.debug("User is currently a player. Changing to admin"); |
| 944 | newRole = new String("admin"); |
| 945 | } |
| 946 | } |
| 947 | else |
| 948 | { |
| 949 | fail("User not found in DB after it was created"); |
| 950 | } |
| 951 | rs.close(); |
| 952 | conn.close(); |
| 953 | String userId = Getter.getUserIdFromName(applicationRoot, userName); |
| 954 | if(!Setter.updateUserRole(applicationRoot, userId, newRole).equalsIgnoreCase(userName)) |
| 955 | { |
| 956 | fail("Could not update user role from " + currentRole + " to " + newRole); |
| 957 | } |
| 958 | else |
| 959 | { |
| 960 | log.debug("Checking if change occurred"); |
| 961 | conn = Database.getCoreConnection(applicationRoot); |
| 962 | ps = conn.prepareStatement("SELECT userRole FROM users WHERE userName = ?"); |
| 963 | ps.setString(1, userName); |
| 964 | rs = ps.executeQuery(); |
| 965 | if(rs.next()) |
| 966 | { |
| 967 | if(!newRole.equalsIgnoreCase(rs.getString(1))) |
| 968 | { |
| 969 | fail("User Role was not updated in DB"); |
| 970 | } |
| 971 | else |
| 972 | { |
| 973 | //Pass |
| 974 | } |
| 975 | } |
| 976 | else |
nothing calls this directly
no test coverage detected