syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1440514 - /syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
Date Wed, 30 Jan 2013 16:48:32 GMT
Author: cschneider
Date: Wed Jan 30 16:48:32 2013
New Revision: 1440514

URL: http://svn.apache.org/viewvc?rev=1440514&view=rev
Log:
SYNCOPE-231 Refactored AuthenticationTestITCase

Modified:
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java?rev=1440514&r1=1440513&r2=1440514&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
(original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
Wed Jan 30 16:48:32 2013
@@ -232,52 +232,22 @@ public class AuthenticationTestITCase ex
 
         userTO = createUser(userTO);
         assertNotNull(userTO);
+        long userId = userTO.getId();
 
         UserService userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"password123");
-
-        UserTO readUserTO = userService2.read(userTO.getId());
-
-        assertNotNull(readUserTO);
-        assertNotNull(readUserTO.getFailedLogins());
-        assertEquals(Integer.valueOf(0), readUserTO.getFailedLogins());
+        assertEquals(0, getFailedLogins(userService2, userId));
 
         // authentications failed ...
-
         UserService userService3 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"wrongpwd1");
-
-        Throwable t = null;
-
-        try {
-            userService3.read(userTO.getId());
-            assertNotNull(readUserTO);
-        } catch (Exception e) {
-            t = e;
-        }
-
-        assertNotNull(t);
-        t = null;
-
-        try {
-            userService3.read(userTO.getId());
-            assertNotNull(readUserTO);
-        } catch (Exception e) {
-            t = e;
-        }
+        assertReadFails(userService3, userId);
+        assertReadFails(userService3, userId);
 
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
-
-        readUserTO = userService.read(userTO.getId());
-        assertNotNull(readUserTO);
-        assertNotNull(readUserTO.getFailedLogins());
-        assertEquals(Integer.valueOf(2), readUserTO.getFailedLogins());
+        assertEquals(2, getFailedLogins(userService, userId));
 
         UserService userService4 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"password123");
-
-        readUserTO = userService4.read(userTO.getId());
-        assertNotNull(readUserTO);
-        assertNotNull(readUserTO.getFailedLogins());
-        assertEquals(Integer.valueOf(0), readUserTO.getFailedLogins());
+        assertEquals(0, getFailedLogins(userService4, userId));
     }
 
     @Test
@@ -293,71 +263,26 @@ public class AuthenticationTestITCase ex
         userTO.addMembership(membershipTO);
 
         userTO = createUser(userTO);
+        long userId = userTO.getId();
         assertNotNull(userTO);
 
         UserService userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"password123");
-
-        userTO = userService2.read(userTO.getId());
-
-        assertNotNull(userTO);
-        assertNotNull(userTO.getFailedLogins());
-        assertEquals(Integer.valueOf(0), userTO.getFailedLogins());
+        assertEquals(0, getFailedLogins(userService2, userId));
 
         // authentications failed ...
-
         UserService userService3 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"wrongpwd1");
-
-        Throwable t = null;
-
-        try {
-            userService3.read(userTO.getId());
-            fail();
-        } catch (Exception e) {
-            t = e;
-        }
-
-        assertNotNull(t);
-        t = null;
-
-        try {
-            userService3.read(userTO.getId());
-        } catch (Exception e) {
-            t = e;
-        }
-
-        assertNotNull(t);
-        t = null;
-
-        try {
-            userService3.read(userTO.getId());
-        } catch (Exception e) {
-            t = e;
-        }
-
-        assertNotNull(t);
-        t = null;
+        assertReadFails(userService3, userId);
+        assertReadFails(userService3, userId);
+        assertReadFails(userService3, userId);
 
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
-
-        userTO = userService.read(userTO.getId());
-
-        assertNotNull(userTO);
-        assertNotNull(userTO.getFailedLogins());
-        assertEquals(Integer.valueOf(3), userTO.getFailedLogins());
+        assertEquals(3, getFailedLogins(userService, userId));
 
         // last authentication before suspension
         // TODO remove after CXF migration is complete
         userService3 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"wrongpwd1");
-
-        try {
-            userService3.read(userTO.getId());
-        } catch (Exception e) {
-            t = e;
-        }
-
-        assertNotNull(t);
-        t = null;
+        assertReadFails(userService3, userId);
 
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
@@ -369,35 +294,20 @@ public class AuthenticationTestITCase ex
         assertEquals(Integer.valueOf(3), userTO.getFailedLogins());
         assertEquals("suspended", userTO.getStatus());
 
-        // check for authentication
+        // Access with correct credentials should fail as user is suspended
         // TODO remove after CXF migration is complete
         userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"password123");
-
-        try {
-            userService2.read(userTO.getId());
-            assertNotNull(userTO);
-        } catch (Exception e) {
-            t = e;
-        }
-
-        assertNotNull(t);
-        t = null;
+        assertReadFails(userService2, userId);
 
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
-
         userTO = userService.reactivate(userTO.getId());
-
         assertNotNull(userTO);
         assertEquals("active", userTO.getStatus());
 
         // TODO remove after CXF migration is complete
         userService2 = setupCredentials(userService, UserService.class, userTO.getUsername(),
"password123");
-
-        userTO = userService2.read(userTO.getId());
-
-        assertNotNull(userTO);
-        assertEquals(Integer.valueOf(0), userTO.getFailedLogins());
+        assertEquals(0, getFailedLogins(userService2, userId));
     }
 
     @Test
@@ -445,4 +355,20 @@ public class AuthenticationTestITCase ex
         role1User = response.readEntity(UserTO.class);
         assertNotNull(role1User);
     }
+    
+    private int getFailedLogins(UserService testUserService, long userId) {
+        UserTO readUserTO = testUserService.read(userId);
+        assertNotNull(readUserTO);
+        assertNotNull(readUserTO.getFailedLogins());
+        return readUserTO.getFailedLogins();
+    }
+
+    private void assertReadFails(UserService userService, long id) {
+        try {
+            userService.read(id);
+            fail("access should not work");
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+    }
 }



Mime
View raw message