You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by cs...@apache.org on 2013/01/31 10:50:05 UTC

svn commit: r1440889 - /syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java

Author: cschneider
Date: Thu Jan 31 09:50:05 2013
New Revision: 1440889

URL: http://svn.apache.org/viewvc?rev=1440889&view=rev
Log:
SYNCOPE-231 Do not read UserRequest after create as it will fail with anon user

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

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java?rev=1440889&r1=1440888&r2=1440889&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java Thu Jan 31 09:50:05 2013
@@ -64,7 +64,7 @@ public class UserRequestTestITCase exten
 
         // 2. get unauthorized when trying to request user create
         try {
-            createUserRequest(new UserRequestTO(userTO));
+            createUserRequest(userRequestService, new UserRequestTO(userTO));
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
             assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole));
@@ -81,8 +81,7 @@ public class UserRequestTestITCase exten
 
         // 4. as anonymous, request user create works
         UserRequestService userRequestService2 = setupCredentials(userRequestService, UserRequestService.class, null, null);
-        response = userRequestService2.create(new UserRequestTO(userTO));
-        UserRequestTO request = getObject(response, UserRequestTO.class, userRequestService2);
+        response = createUserRequest(userRequestService2, new UserRequestTO(userTO));
 
         // 5. switch back to admin
         super.resetRestTemplate(); // TODO remove after CXF migration is complete
@@ -96,7 +95,7 @@ public class UserRequestTestITCase exten
         assertTrue(matchingUsers.isEmpty());
 
         // 7. actually create user
-        userTO = createUser(request.getUserTO());
+        userTO = createUser(userTO);
         assertNotNull(userTO);
     }
 
@@ -115,7 +114,7 @@ public class UserRequestTestITCase exten
 
         // 2. try to request user update as admin: failure
         try {
-            createUserRequest(new UserRequestTO(userMod));
+            createUserRequest(userRequestService, new UserRequestTO(userMod));
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
             assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole));
@@ -127,10 +126,7 @@ public class UserRequestTestITCase exten
 
         // 4. update with same password: not matching password policy
         try {
-            Response response = userRequestService2.create(new UserRequestTO(userMod));
-            if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) {
-                throw (RuntimeException) clientExceptionMapper.fromResponse(response);
-            }
+            createUserRequest(userRequestService2, new UserRequestTO(userMod));
             fail();
         } catch (SyncopeClientCompositeErrorException scce) {
             assertNotNull(scce.getException(SyncopeClientExceptionType.InvalidSyncopeUser));
@@ -138,8 +134,7 @@ public class UserRequestTestITCase exten
 
         // 5. now request user update works
         userMod.setPassword("new" + initialPassword);
-        Response response = userRequestService.create(new UserRequestTO(userMod));
-        assertEquals(org.apache.http.HttpStatus.SC_CREATED, response.getStatus());
+        createUserRequest(userRequestService2, new UserRequestTO(userMod));
 
         // 6. switch back to admin
         super.resetRestTemplate();
@@ -168,7 +163,7 @@ public class UserRequestTestITCase exten
 
         // 2. try to request user delete as admin: failure
         try {
-            createUserRequest(new UserRequestTO(userTO.getId()));
+            createUserRequest(userRequestService, new UserRequestTO(userTO.getId()));
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
             assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole));
@@ -179,9 +174,7 @@ public class UserRequestTestITCase exten
                 initialPassword);
 
         // 4. now request user delete works
-        Response response = userRequestService2.create(new UserRequestTO(userTO.getId()));
-        assertNotNull(response);
-        assertEquals(org.apache.http.HttpStatus.SC_CREATED, response.getStatus());
+        createUserRequest(userRequestService2, new UserRequestTO(userTO.getId()));
 
         // 5. switch back to admin
         super.resetRestTemplate();
@@ -202,11 +195,11 @@ public class UserRequestTestITCase exten
         }
     }
 
-    private UserRequestTO createUserRequest(final UserRequestTO userRequestTO) {
-        Response response = userRequestService.create(userRequestTO);
+    private Response createUserRequest(UserRequestService service, final UserRequestTO userRequestTO) {
+        Response response = service.create(userRequestTO);
         if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) {
             throw (RuntimeException) clientExceptionMapper.fromResponse(response);
         }
-        return getObject(response, UserRequestTO.class, userRequestService);
+        return response;
     }
 }