syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1439928 - in /syncope/trunk/core/src: main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java test/java/org/apache/syncope/core/rest/AbstractTest.java test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java
Date Tue, 29 Jan 2013 15:23:28 GMT
Author: cschneider
Date: Tue Jan 29 15:23:14 2013
New Revision: 1439928

URL: http://svn.apache.org/viewvc?rev=1439928&view=rev
Log:
SYNCOPE-231 Handling client side exceptions in UserRequestService create

Modified:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java?rev=1439928&r1=1439927&r2=1439928&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java
Tue Jan 29 15:23:14 2013
@@ -61,7 +61,7 @@ public class UserRequestServiceImpl impl
             userRequestController.delete(userRequestTO.getUserId());
         }
         URI location = uriInfo.getAbsolutePathBuilder().path("" + outUserRequestTO.getId()).build();
-        return Response.created(location).entity(outUserRequestTO).build();
+        return Response.created(location).entity(outUserRequestTO.getId()).build();
     }
 
     @Override

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1439928&r1=1439927&r2=1439928&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java Tue Jan
29 15:23:14 2013
@@ -26,14 +26,17 @@ import java.util.UUID;
 
 import javax.sql.DataSource;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.jaxrs.client.Client;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.http.HttpStatus;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
+import org.apache.syncope.client.rest.utils.RestClientExceptionMapper;
 import org.apache.syncope.client.services.proxy.ConfigurationServiceProxy;
 import org.apache.syncope.client.services.proxy.ConnectorServiceProxy;
 import org.apache.syncope.client.services.proxy.EntitlementServiceProxy;
@@ -144,6 +147,9 @@ public abstract class AbstractTest {
     protected UserRequestService userRequestService;
 
     protected PolicyService policyService;
+    
+    @Autowired
+    protected RestClientExceptionMapper clientExceptionMapper;
 
     @Before
     public void setup() throws Exception {
@@ -300,4 +306,17 @@ public abstract class AbstractTest {
         Response response = userService.create(userTO);
         return response.readEntity(UserTO.class);
     }
+
+    protected void assertCreated(Response response) {
+        if (response.getStatus() != HttpStatus.SC_CREATED) {
+            StringBuilder builder = new StringBuilder();
+            MultivaluedMap<String, Object> headers = response.getHeaders();
+            builder.append("Headers (");
+            for (String key : headers.keySet()) {
+                builder.append(key + ":" + headers.getFirst(key) + ",");
+            }
+            builder.append(")");
+            throw new RuntimeException("Error on create. Status is : " + response.getStatus()
+ " with headers " + builder.toString());
+        }
+    }
 }

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=1439928&r1=1439927&r2=1439928&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
Tue Jan 29 15:23:14 2013
@@ -64,7 +64,7 @@ public class UserRequestTestITCase exten
         // 2. get unauthorized when trying to request user create
         SyncopeClientException exception = null;
         try {
-            userRequestService.create(new UserRequestTO(userTO));
+            createUserRequest(new UserRequestTO(userTO));
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
             exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole);
@@ -117,7 +117,7 @@ public class UserRequestTestITCase exten
         // 2. try to request user update as admin: failure
         SyncopeClientException exception = null;
         try {
-            userRequestService.create(new UserRequestTO(userMod));
+            createUserRequest(new UserRequestTO(userMod));
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
             exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole);
@@ -130,7 +130,7 @@ public class UserRequestTestITCase exten
         // 4. update with same password: not matching password policy
         exception = null;
         try {
-            userRequestService.create(new UserRequestTO(userMod));
+            createUserRequest(new UserRequestTO(userMod));
         } catch (SyncopeClientCompositeErrorException scce) {
             exception = scce.getException(SyncopeClientExceptionType.InvalidSyncopeUser);
         }
@@ -169,7 +169,7 @@ public class UserRequestTestITCase exten
         // 2. try to request user delete as admin: failure
         SyncopeClientException exception = null;
         try {
-            userRequestService.create(new UserRequestTO(userTO.getId()));
+            createUserRequest(new UserRequestTO(userTO.getId()));
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
             exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole);
@@ -180,8 +180,7 @@ public class UserRequestTestITCase exten
         super.setupRestTemplate(userTO.getUsername(), initialPassword);
 
         // 4. now request user delete works
-        Response response = userRequestService.create(new UserRequestTO(userTO.getId()));
-        assertEquals(org.apache.http.HttpStatus.SC_CREATED, response.getStatus());
+        createUserRequest(new UserRequestTO(userTO.getId()));
 
         // 5. switch back to admin
         super.resetRestTemplate();
@@ -201,4 +200,12 @@ public class UserRequestTestITCase exten
             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
         }
     }
+
+    private Long createUserRequest(UserRequestTO userRequestTO) throws RuntimeException {
+        Response response = userRequestService.create(userRequestTO);
+        if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) {
+            throw (RuntimeException)clientExceptionMapper.fromResponse(response);
+        }
+        return (Long) response.readEntity(Long.class);
+    }
 }



Mime
View raw message