You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by jb...@apache.org on 2013/01/23 08:58:27 UTC

svn commit: r1437286 - in /syncope/trunk: client/src/main/java/org/apache/syncope/client/rest/utils/ client/src/main/java/org/apache/syncope/client/services/proxy/ common/src/main/java/org/apache/syncope/common/services/ common/src/main/java/org/apache...

Author: jbernhardt
Date: Wed Jan 23 07:58:26 2013
New Revision: 1437286

URL: http://svn.apache.org/viewvc?rev=1437286&view=rev
Log:
[SYNCOPE-231]
* Added PolicyService implementation
* Adding JAX-B Annotations for related TOs
* Code cleanup (according to checkstyle and PMD)

Added:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java
Modified:
    syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java
    syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java
    syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/services/ConfigurationService.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/to/AccountPolicyTO.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PasswordPolicyTO.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PolicyTO.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/to/SyncPolicyTO.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AccountPolicySpec.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PolicyType.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/types/SyncPolicySpec.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/PolicyRestClient.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ConfigurationServiceImpl.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/NotFoundException.java
    syncope/trunk/core/src/main/resources/restContext.xml
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/rest/utils/RestClientExceptionMapper.java Wed Jan 23 07:58:26 2013
@@ -38,63 +38,64 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Provider
-public class RestClientExceptionMapper implements ExceptionMapper<Exception>,
-		ResponseExceptionMapper<Exception> {
+public class RestClientExceptionMapper implements ExceptionMapper<Exception>, ResponseExceptionMapper<Exception> {
 
     private static final Logger LOG = LoggerFactory.getLogger(RestClientExceptionMapper.class);
 
     @Override
-	public Response toResponse(Exception e) {
-		throw new UnsupportedOperationException("Call of toResponse() method is not expected in RestClientExceptionnMapper");
-	}
-
-	@Override
-	public Exception fromResponse(Response response) {
-		Exception ex = null;
-		int statusCode = response.getStatus();
-		
-		// 1. Check for composite exception in HTTP header 
-		SyncopeClientCompositeErrorException scce = checkCompositeException(response);
-		if (scce != null) {
-			ex = scce;
-			
-			// 2. TODO Map  SC_FORBIDDEN
-//		} else if (statusCode == HttpStatus.SC_FORBIDDEN) {
-//			ex = new UnauthorizedRoleException(-1L);
-			
-			// 3. Map  SC_UNAUTHORIZED
-		} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
-			ex = new AccessControlException("Remote unauthorized exception");
-			
-		} else {
-			// 3. All other codes are mapped to runtime exception with HTTP code information 
-			ex = new RuntimeException(String.format(
-					"Remote exception with status code: %s",
-					Response.Status.fromStatusCode(statusCode).name()));
-		}
+    public Response toResponse(final Exception e) {
+        throw new UnsupportedOperationException(
+                "Call of toResponse() method is not expected in RestClientExceptionnMapper");
+    }
+
+    @Override
+    public Exception fromResponse(final Response response) {
+        Exception ex = null;
+        int statusCode = response.getStatus();
+
+        // 1. Check for composite exception in HTTP header
+        SyncopeClientCompositeErrorException scce = checkCompositeException(response);
+        if (scce != null) {
+            ex = scce;
+
+            // 2. TODO Map SC_FORBIDDEN
+            // } else if (statusCode == HttpStatus.SC_FORBIDDEN) {
+            // ex = new UnauthorizedRoleException(-1L);
+
+            // 3. Map SC_UNAUTHORIZED
+        } else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
+            ex = new AccessControlException("Remote unauthorized exception");
+
+        } else {
+            // 3. All other codes are mapped to runtime exception with HTTP code information
+            ex = new RuntimeException(String.format("Remote exception with status code: %s", Response.Status
+                    .fromStatusCode(statusCode).name()));
+        }
         LOG.error("Exception thrown by REST methods: " + ex.getMessage(), ex);
-		return ex;
-	}
-	
-	private SyncopeClientCompositeErrorException checkCompositeException(Response response) {
-		int statusCode = response.getStatus();
-        List<Object> exceptionTypesInHeaders = response.getHeaders().get(SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER);
+        return ex;
+    }
+
+    private SyncopeClientCompositeErrorException checkCompositeException(final Response response) {
+        int statusCode = response.getStatus();
+        List<Object> exceptionTypesInHeaders = response.getHeaders().get(
+                SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER);
         if (exceptionTypesInHeaders == null) {
             LOG.debug("No " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + " provided");
             return null;
         }
 
-		SyncopeClientCompositeErrorException compositeException = new SyncopeClientCompositeErrorException(
-				org.springframework.http.HttpStatus.valueOf(statusCode));
+        SyncopeClientCompositeErrorException compositeException = new SyncopeClientCompositeErrorException(
+                org.springframework.http.HttpStatus.valueOf(statusCode));
 
         Set<String> handledExceptions = new HashSet<String>();
         for (Object exceptionTypeValue : exceptionTypesInHeaders) {
-        	String exceptionTypeAsString = (String) exceptionTypeValue; 
+            String exceptionTypeAsString = (String) exceptionTypeValue;
             SyncopeClientExceptionType exceptionType = null;
             try {
                 exceptionType = SyncopeClientExceptionType.getFromHeaderValue(exceptionTypeAsString);
             } catch (IllegalArgumentException e) {
-                LOG.error("Unexpected value of " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + ": " + exceptionTypeAsString, e);
+                LOG.error("Unexpected value of " + SyncopeClientErrorHandler.EXCEPTION_TYPE_HEADER + ": "
+                        + exceptionTypeAsString, e);
             }
             if (exceptionType != null) {
                 handledExceptions.add(exceptionTypeAsString);
@@ -103,14 +104,14 @@ public class RestClientExceptionMapper i
                 clientException.setType(exceptionType);
                 if (response.getHeaders().get(exceptionType.getElementHeaderName()) != null
                         && !response.getHeaders().get(exceptionType.getElementHeaderName()).isEmpty()) {
-                	// TODO: update clientException to support list of objects
-                	List<Object> elementsObjectList = response.getHeaders().get(exceptionType.getElementHeaderName());
-                	List<String> elementsStringList = new ArrayList<String>();
-                	for (Object elementObject : elementsObjectList) {
-                		if (elementObject instanceof String) {
-                			elementsStringList.add((String) elementObject);
-                		}
-                	}
+                    // TODO update clientException to support list of objects
+                    List<Object> elementsObjectList = response.getHeaders().get(exceptionType.getElementHeaderName());
+                    List<String> elementsStringList = new ArrayList<String>();
+                    for (Object elementObject : elementsObjectList) {
+                        if (elementObject instanceof String) {
+                            elementsStringList.add((String) elementObject);
+                        }
+                    }
                     clientException.setElements(elementsStringList);
                 }
                 compositeException.addException(clientException);
@@ -125,7 +126,7 @@ public class RestClientExceptionMapper i
         if (compositeException.hasExceptions()) {
             return compositeException;
         }
-        
+
         return null;
-	}
+    }
 }

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/ConfigurationServiceProxy.java Wed Jan 23 07:58:26 2013
@@ -65,8 +65,8 @@ public class ConfigurationServiceProxy e
     }
 
     @Override
-    public ConfigurationTO update(final String key, final ConfigurationTO configurationTO) {
-        return getRestTemplate().postForObject(baseUrl + "configuration/update", configurationTO,
+    public void update(final String key, final ConfigurationTO configurationTO) {
+        getRestTemplate().postForObject(baseUrl + "configuration/update", configurationTO,
                 ConfigurationTO.class);
     }
 

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/PolicyServiceProxy.java Wed Jan 23 07:58:26 2013
@@ -18,8 +18,12 @@
  */
 package org.apache.syncope.client.services.proxy;
 
+import java.net.URI;
 import java.util.Arrays;
 import java.util.List;
+
+import javax.ws.rs.core.Response;
+
 import org.apache.syncope.common.services.PolicyService;
 import org.apache.syncope.common.to.AccountPolicyTO;
 import org.apache.syncope.common.to.PasswordPolicyTO;
@@ -36,36 +40,35 @@ public class PolicyServiceProxy extends 
     }
 
     @Override
-    public <T extends PolicyTO> T create(final PolicyType type, final T policyTO) {
-        return (T) getRestTemplate().postForObject(baseUrl + "policy/{kind}/create", policyTO, policyTO.getClass(),
-                typeToUrl(policyTO.getType()));
+    public <T extends PolicyTO> Response create(final PolicyType type, final T policyTO) {
+        PolicyTO policy = getRestTemplate().postForObject(baseUrl + "policy/{kind}/create", policyTO,
+                policyTO.getClass(), typeToUrl(policyTO.getType()));
+
+        return Response.created(URI.create(baseUrl + "policy/read/" + policy.getId() + ".json")).build();
     }
 
     @Override
-    public <T extends PolicyTO> T delete(final PolicyType type, final Long policyId) {
-        return (T) getRestTemplate().getForObject(baseUrl + "policy/delete/{id}", getTOClass(type), policyId);
+    public <T extends PolicyTO> void delete(final PolicyType type, final Long policyId) {
+        getRestTemplate().getForObject(baseUrl + "policy/delete/{id}", getTOClass(type), policyId);
     }
 
     @Override
-    public <T extends PolicyTO> List<T> listByType(final PolicyType type) {
+    public <T extends PolicyTO> List<T> list(final PolicyType type) {
         switch (type) {
             case ACCOUNT:
             case GLOBAL_ACCOUNT:
-                return (List<T>) Arrays.asList(getRestTemplate().getForObject(
-                        baseUrl + "policy/{kind}/list", AccountPolicyTO[].class,
-                        type));
+                return (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
+                        AccountPolicyTO[].class, type));
 
             case PASSWORD:
             case GLOBAL_PASSWORD:
-                return (List<T>) Arrays.asList(getRestTemplate().getForObject(
-                        baseUrl + "policy/{kind}/list", PasswordPolicyTO[].class,
-                        type));
+                return (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
+                        PasswordPolicyTO[].class, type));
 
             case SYNC:
             case GLOBAL_SYNC:
-                return (List<T>) Arrays.asList(getRestTemplate().getForObject(
-                        baseUrl + "policy/{kind}/list", SyncPolicyTO[].class,
-                        type));
+                return (List<T>) Arrays.asList(getRestTemplate().getForObject(baseUrl + "policy/{kind}/list",
+                        SyncPolicyTO[].class, type));
 
             default:
                 throw new IllegalArgumentException("Policy Type not supported: " + type);
@@ -74,21 +77,19 @@ public class PolicyServiceProxy extends 
 
     @Override
     public <T extends PolicyTO> T read(final PolicyType type, final Long policyId) {
-        return (T) getRestTemplate().getForObject(baseUrl + "policy/read/{id}", getTOClass(type), policyId);
+        return (T) getRestTemplate().getForObject(baseUrl + "policy/read/{id}.json", getTOClass(type), policyId);
     }
 
     @Override
     public <T extends PolicyTO> T readGlobal(final PolicyType type) {
-        return (T) getRestTemplate().getForObject(baseUrl + "policy/{kind}/global/read", getTOClass(type),
+        return (T) getRestTemplate().getForObject(baseUrl + "policy/{kind}/global/read.json", getTOClass(type),
                 typeToUrl(type));
     }
 
     @Override
-    public <T extends PolicyTO> T update(final PolicyType type, final Long policyId, final T policyTO) {
-        @SuppressWarnings("unchecked")
-        T result = (T) getRestTemplate().postForObject(baseUrl + "policy/{kind}/update", policyTO, policyTO.getClass(),
+    public <T extends PolicyTO> void update(final PolicyType type, final Long policyId, final T policyTO) {
+        getRestTemplate().postForObject(baseUrl + "policy/{kind}/update", policyTO, policyTO.getClass(),
                 typeToUrl(policyTO.getType()));
-        return result;
     }
 
     private Class<? extends PolicyTO> getTOClass(final PolicyType type) {

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/ConfigurationService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/ConfigurationService.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/ConfigurationService.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/ConfigurationService.java Wed Jan 23 07:58:26 2013
@@ -64,5 +64,5 @@ public interface ConfigurationService {
 
     @PUT
     @Path("{key}")
-    ConfigurationTO update(@PathParam("key") String key, ConfigurationTO configurationTO);
+    void update(@PathParam("key") String key, ConfigurationTO configurationTO);
 }

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/PolicyService.java Wed Jan 23 07:58:26 2013
@@ -25,6 +25,7 @@ import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
 
 import org.apache.syncope.common.to.PolicyTO;
 import org.apache.syncope.common.types.PolicyType;
@@ -33,25 +34,25 @@ import org.apache.syncope.common.types.P
 public interface PolicyService {
 
     @POST
-    <T extends PolicyTO> T create(@PathParam("kind") PolicyType type, T policyTO);
+    <T extends PolicyTO> Response create(@PathParam("kind") PolicyType type, T policyTO);
 
-    // TODO: policyClass is required only for Spring RestTemplate mock. Must be removed for CXF
     @DELETE
     @Path("{policyId}")
-    <T extends PolicyTO> T delete(@PathParam("kind") PolicyType type, @PathParam("policyId") Long policyId);
+    <T extends PolicyTO> void delete(@PathParam("kind") PolicyType type, @PathParam("policyId") Long policyId);
 
     @GET
-    <T extends PolicyTO> List<T> listByType(@PathParam("kind") PolicyType type);
+    <T extends PolicyTO> List<T> list(@PathParam("kind") PolicyType type);
 
     @GET
     @Path("{policyId}")
     <T extends PolicyTO> T read(@PathParam("kind") PolicyType type, @PathParam("policyId") Long policyId);
 
     @GET
-    @Path("global")
+    @Path("0")
     <T extends PolicyTO> T readGlobal(@PathParam("kind") PolicyType type);
 
     @PUT
     @Path("{policyId}")
-    <T extends PolicyTO> T update(@PathParam("kind") PolicyType type,@PathParam("policyId") Long policyId, T policyTO);
+    <T extends PolicyTO> void update(@PathParam("kind") PolicyType type,@PathParam("policyId") Long policyId,
+            T policyTO);
 }

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/to/AccountPolicyTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/to/AccountPolicyTO.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/to/AccountPolicyTO.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/to/AccountPolicyTO.java Wed Jan 23 07:58:26 2013
@@ -18,9 +18,14 @@
  */
 package org.apache.syncope.common.to;
 
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.types.AccountPolicySpec;
 import org.apache.syncope.common.types.PolicyType;
 
+@XmlRootElement(name = "accountPolicy")
+@XmlType
 public class AccountPolicyTO extends PolicyTO {
 
     private static final long serialVersionUID = -1557150042828800134L;

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PasswordPolicyTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PasswordPolicyTO.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PasswordPolicyTO.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PasswordPolicyTO.java Wed Jan 23 07:58:26 2013
@@ -18,9 +18,14 @@
  */
 package org.apache.syncope.common.to;
 
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.types.PasswordPolicySpec;
 import org.apache.syncope.common.types.PolicyType;
 
+@XmlRootElement(name = "passwordPolicy")
+@XmlType
 public class PasswordPolicyTO extends PolicyTO {
 
     private static final long serialVersionUID = -5606086441294799690L;

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PolicyTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PolicyTO.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PolicyTO.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/to/PolicyTO.java Wed Jan 23 07:58:26 2013
@@ -18,9 +18,17 @@
  */
 package org.apache.syncope.common.to;
 
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.AbstractBaseBean;
 import org.apache.syncope.common.types.PolicyType;
 
+@XmlRootElement(name = "policy")
+@XmlType
+@XmlSeeAlso({AccountPolicyTO.class, PasswordPolicyTO.class, SyncPolicyTO.class})
+//@JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="class")
 public abstract class PolicyTO extends AbstractBaseBean {
 
     private static final long serialVersionUID = -2903888572649721035L;

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/to/SyncPolicyTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/to/SyncPolicyTO.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/to/SyncPolicyTO.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/to/SyncPolicyTO.java Wed Jan 23 07:58:26 2013
@@ -18,9 +18,14 @@
  */
 package org.apache.syncope.common.to;
 
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.types.PolicyType;
 import org.apache.syncope.common.types.SyncPolicySpec;
 
+@XmlRootElement(name = "syncPolicy")
+@XmlType
 public class SyncPolicyTO extends PolicyTO {
 
     private static final long serialVersionUID = 993024634238024242L;

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AbstractPolicySpec.java Wed Jan 23 07:58:26 2013
@@ -24,6 +24,4 @@ public class AbstractPolicySpec extends 
 
     private static final long serialVersionUID = 2740439904103716653L;
 
-    public AbstractPolicySpec() {
-    }
 }

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AccountPolicySpec.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AccountPolicySpec.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AccountPolicySpec.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/AccountPolicySpec.java Wed Jan 23 07:58:26 2013
@@ -21,8 +21,13 @@ package org.apache.syncope.common.types;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.annotation.SchemaList;
 
+@XmlType
 public class AccountPolicySpec extends AbstractPolicySpec {
 
     private static final long serialVersionUID = 3259256974414758406L;
@@ -114,6 +119,8 @@ public class AccountPolicySpec extends A
         this.minLength = minLength;
     }
 
+    @XmlElementWrapper(name = "prefixesNotPermitted")
+    @XmlElement(name = "prefix")
     public List<String> getPrefixesNotPermitted() {
         if (prefixesNotPermitted == null) {
             prefixesNotPermitted = new ArrayList<String>();
@@ -125,6 +132,8 @@ public class AccountPolicySpec extends A
         this.prefixesNotPermitted = prefixesNotPermitted;
     }
 
+    @XmlElementWrapper(name = "schemasNotPermitted")
+    @XmlElement(name = "schema")
     public List<String> getSchemasNotPermitted() {
         if (schemasNotPermitted == null) {
             schemasNotPermitted = new ArrayList<String>();
@@ -136,6 +145,8 @@ public class AccountPolicySpec extends A
         this.schemasNotPermitted = schemasNotPermitted;
     }
 
+    @XmlElementWrapper(name = "suffixesNotPermitted")
+    @XmlElement(name = "suffix")
     public List<String> getSuffixesNotPermitted() {
         if (suffixesNotPermitted == null) {
             suffixesNotPermitted = new ArrayList<String>();
@@ -147,6 +158,8 @@ public class AccountPolicySpec extends A
         this.suffixesNotPermitted = suffixesNotPermitted;
     }
 
+    @XmlElementWrapper(name = "wordsNotPermitted")
+    @XmlElement(name = "word")
     public List<String> getWordsNotPermitted() {
         if (wordsNotPermitted == null) {
             wordsNotPermitted = new ArrayList<String>();

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PasswordPolicySpec.java Wed Jan 23 07:58:26 2013
@@ -21,8 +21,13 @@ package org.apache.syncope.common.types;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.annotation.SchemaList;
 
+@XmlType
 public class PasswordPolicySpec extends AbstractPolicySpec {
 
     private static final long serialVersionUID = -7988778083915548547L;
@@ -252,6 +257,8 @@ public class PasswordPolicySpec extends 
         this.nonAlphanumericRequired = nonAlphanumericRequired;
     }
 
+    @XmlElementWrapper(name = "prefixesNotPermitted")
+    @XmlElement(name = "prefix")
     public List<String> getPrefixesNotPermitted() {
         if (prefixesNotPermitted == null) {
             prefixesNotPermitted = new ArrayList<String>();
@@ -263,6 +270,8 @@ public class PasswordPolicySpec extends 
         this.prefixesNotPermitted = prefixesNotPermitted;
     }
 
+    @XmlElementWrapper(name = "schemasNotPermitted")
+    @XmlElement(name = "schema")
     public List<String> getSchemasNotPermitted() {
         if (schemasNotPermitted == null) {
             schemasNotPermitted = new ArrayList<String>();
@@ -274,6 +283,8 @@ public class PasswordPolicySpec extends 
         this.schemasNotPermitted = schemasNotPermitted;
     }
 
+    @XmlElementWrapper(name = "suffixesNotPermitted")
+    @XmlElement(name = "suffix")
     public List<String> getSuffixesNotPermitted() {
         if (suffixesNotPermitted == null) {
             suffixesNotPermitted = new ArrayList<String>();
@@ -293,6 +304,8 @@ public class PasswordPolicySpec extends 
         this.uppercaseRequired = uppercaseRequired;
     }
 
+    @XmlElementWrapper(name = "wordsNotPermitted")
+    @XmlElement(name = "word")
     public List<String> getWordsNotPermitted() {
         if (wordsNotPermitted == null) {
             wordsNotPermitted = new ArrayList<String>();

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PolicyType.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PolicyType.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PolicyType.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/PolicyType.java Wed Jan 23 07:58:26 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.syncope.common.types;
 
+import javax.xml.bind.annotation.XmlEnum;
+
+@XmlEnum
 public enum PolicyType {
 
     /**
@@ -26,11 +29,13 @@ public enum PolicyType {
      */
     ACCOUNT("Account Policy"),
     GLOBAL_ACCOUNT("Account Global Policy"),
+
     /**
      * Password policy regarding password syntax.
      */
     PASSWORD("Password Policy"),
     GLOBAL_PASSWORD("Password Global Policy"),
+
     /**
      * SYNC policy regarding account conflicts resolution.
      */
@@ -46,4 +51,8 @@ public enum PolicyType {
     public String getDescription() {
         return description;
     }
+
+    public static PolicyType fromString(String value) {
+        return PolicyType.valueOf(value.toUpperCase());
+    }
 }

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/types/SyncPolicySpec.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/types/SyncPolicySpec.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/types/SyncPolicySpec.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/types/SyncPolicySpec.java Wed Jan 23 07:58:26 2013
@@ -21,8 +21,13 @@ package org.apache.syncope.common.types;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlType;
+
 import org.apache.syncope.common.annotation.SchemaList;
 
+@XmlType
 public class SyncPolicySpec extends AbstractPolicySpec {
 
     private static final long serialVersionUID = -3144027171719498127L;
@@ -61,6 +66,8 @@ public class SyncPolicySpec extends Abst
         this.conflictResolutionAction = conflictResolutionAction;
     }
 
+    @XmlElementWrapper(name = "userAltSearchSchemas")
+    @XmlElement(name = "userAltSearchSchema")
     public List<String> getuAltSearchSchemas() {
         return uAltSearchSchemas;
     }
@@ -69,6 +76,8 @@ public class SyncPolicySpec extends Abst
         this.uAltSearchSchemas = uAltSearchSchemas;
     }
 
+    @XmlElementWrapper(name = "roleAltSearchSchemas")
+    @XmlElement(name = "roleAltSearchSchema")
     public List<String> getrAltSearchSchemas() {
         return rAltSearchSchemas;
     }

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/PolicyRestClient.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/PolicyRestClient.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/PolicyRestClient.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/PolicyRestClient.java Wed Jan 23 07:58:26 2013
@@ -69,7 +69,7 @@ public class PolicyRestClient extends Ba
         List<T> policies = new ArrayList<T>();
 
         try {
-            policies = (List<T>) getService(PolicyService.class).listByType(type);
+            policies = (List<T>) getService(PolicyService.class).list(type);
             res.addAll(policies);
         } catch (Exception ignore) {
             LOG.debug("No policy found", ignore);
@@ -87,26 +87,27 @@ public class PolicyRestClient extends Ba
         return res;
     }
 
-    public <T extends PolicyTO> T createPolicy(final T policy) throws InvalidPolicyType {
-        return getService(PolicyService.class).create(policy.getType(), policy);
+    public <T extends PolicyTO> void createPolicy(final T policy) {
+        getService(PolicyService.class).create(policy.getType(), policy);
     }
 
-    public <T extends PolicyTO> T updatePolicy(final T policy) throws InvalidPolicyType {
-        return getService(PolicyService.class).update(policy.getType(), policy.getId(), policy);
+    public <T extends PolicyTO> void updatePolicy(final T policy) {
+        getService(PolicyService.class).update(policy.getType(), policy.getId(), policy);
     }
 
-    public PolicyTO delete(final Long id, Class<? extends PolicyTO> policyClass) {
-        return getService(PolicyService.class).delete(getPolicyType(policyClass), id);
+    public void delete(final Long id, final Class<? extends PolicyTO> policyClass) {
+        getService(PolicyService.class).delete(getPolicyType(policyClass), id);
     }
 
-    private PolicyType getPolicyType(Class<? extends PolicyTO> clazz) {
-        if (AccountPolicyTO.class.equals(clazz))
+    private PolicyType getPolicyType(final Class<? extends PolicyTO> clazz) {
+        if (AccountPolicyTO.class.equals(clazz)) {
             return PolicyType.ACCOUNT;
-        else if (PasswordPolicyTO.class.equals(clazz))
+        } else if (PasswordPolicyTO.class.equals(clazz)) {
             return PolicyType.PASSWORD;
-        else if (SyncPolicyTO.class.equals(clazz))
+        } else if (SyncPolicyTO.class.equals(clazz)) {
             return PolicyType.SYNC;
-        else
+        } else {
             throw new IllegalArgumentException("Policy Type not supported");
+        }
     }
 }

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ConfigurationServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ConfigurationServiceImpl.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ConfigurationServiceImpl.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ConfigurationServiceImpl.java Wed Jan 23 07:58:26 2013
@@ -18,12 +18,15 @@
  */
 package org.apache.syncope.core.services;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import java.net.URI;
 import java.util.List;
 import java.util.Set;
 
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.syncope.common.services.ConfigurationService;
@@ -55,7 +58,17 @@ public class ConfigurationServiceImpl im
     public Response dbExport() {
         configurationController.dbExport(new DummyHTTPServletResponse());
         // TODO catch output-stream and forward it to response
-        return null;
+        return Response.ok(new StreamingOutput() {
+
+            @Override
+            public void write(final OutputStream output) throws IOException {
+//                FileInputStream is = new FileInputStream("/etc/hosts");
+//                while (is.available() > 0) {
+//                    output.write(is.read());
+//                }
+//                is.close();
+            }
+        }).build();
     }
 
     @Override
@@ -92,9 +105,9 @@ public class ConfigurationServiceImpl im
     }
 
     @Override
-    public ConfigurationTO update(final String key, final ConfigurationTO configurationTO) {
+    public void update(final String key, final ConfigurationTO configurationTO) {
         try {
-            return configurationController.update(null, configurationTO);
+            configurationController.update(null, configurationTO);
         } catch (MissingConfKeyException e) {
             throw new NotFoundException(e);
         }

Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java?rev=1437286&view=auto
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java (added)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java Wed Jan 23 07:58:26 2013
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.services;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.BadRequestException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.syncope.common.services.PolicyService;
+import org.apache.syncope.common.to.AccountPolicyTO;
+import org.apache.syncope.common.to.PasswordPolicyTO;
+import org.apache.syncope.common.to.PolicyTO;
+import org.apache.syncope.common.to.SyncPolicyTO;
+import org.apache.syncope.common.types.PolicyType;
+import org.apache.syncope.core.rest.controller.PolicyController;
+import org.apache.syncope.core.util.NotFoundException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PolicyServiceImpl implements PolicyService, ContextAware {
+
+    @Autowired
+    private PolicyController policyController;
+
+    private UriInfo uriInfo;
+
+    @Override
+    public <T extends PolicyTO> Response create(final PolicyType type, final T policyTO) {
+        PolicyTO policy;
+        switch (type) {
+            case ACCOUNT:
+                policy = policyController.create(new DummyHTTPServletResponse(), (AccountPolicyTO) policyTO);
+                break;
+
+            case PASSWORD:
+                policy = policyController.create(new DummyHTTPServletResponse(), (PasswordPolicyTO) policyTO);
+                break;
+
+            case SYNC:
+                policy = policyController.create(new DummyHTTPServletResponse(), (SyncPolicyTO) policyTO);
+                break;
+
+            default:
+                throw new BadRequestException();
+        }
+        URI location = uriInfo.getAbsolutePathBuilder().path(policy.getId() + "").build();
+        return Response.created(location).build();
+    }
+
+    @Override
+    public void delete(final PolicyType type, final Long policyId) {
+        try {
+            policyController.delete(policyId);
+        } catch (NotFoundException e) {
+            throw new javax.ws.rs.NotFoundException(e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends PolicyTO> List<T> list(final PolicyType type) {
+        return (List<T>) policyController.listByType(type.toString());
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends PolicyTO> T read(final PolicyType type, final Long policyId) {
+        try {
+            return (T) policyController.read(policyId);
+        } catch (NotFoundException e) {
+            throw new javax.ws.rs.NotFoundException(e);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends PolicyTO> T readGlobal(final PolicyType type) {
+        try {
+            switch (type) {
+                case ACCOUNT:
+                case GLOBAL_ACCOUNT:
+                    return (T) policyController.getGlobalAccountPolicy();
+
+                case PASSWORD:
+                case GLOBAL_PASSWORD:
+                    return (T) policyController.getGlobalPasswordPolicy();
+
+                case SYNC:
+                case GLOBAL_SYNC:
+                    return (T) policyController.getGlobalSyncPolicy();
+
+                default:
+                    throw new BadRequestException();
+            }
+        } catch (NotFoundException e) {
+            throw new javax.ws.rs.NotFoundException(e);
+        }
+    }
+
+    @Override
+    public <T extends PolicyTO> void update(final PolicyType type, final Long policyId, final T policyTO) {
+        try {
+            switch (type) {
+                case ACCOUNT:
+                case GLOBAL_ACCOUNT:
+                    policyController.update((AccountPolicyTO) policyTO);
+                    break;
+
+                case PASSWORD:
+                case GLOBAL_PASSWORD:
+                    policyController.update((PasswordPolicyTO) policyTO);
+                    break;
+
+                case SYNC:
+                case GLOBAL_SYNC:
+                    policyController.update((SyncPolicyTO) policyTO);
+                    break;
+
+                default:
+                    break;
+            }
+        } catch (NotFoundException e) {
+            throw new javax.ws.rs.NotFoundException(e);
+        }
+    }
+
+    @Override
+    public void setUriInfo(final UriInfo ui) {
+        this.uriInfo = ui;
+    }
+
+}

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/NotFoundException.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/NotFoundException.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/NotFoundException.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/NotFoundException.java Wed Jan 23 07:58:26 2013
@@ -25,11 +25,11 @@ public class NotFoundException extends E
 
     private static final long serialVersionUID = 4810651769126663580L;
 
-    public NotFoundException(String msg) {
+    public NotFoundException(final String msg) {
         super(msg);
     }
 
-    public NotFoundException(String msg, Exception e) {
+    public NotFoundException(final String msg, final Exception e) {
         super(msg, e);
     }
 }

Modified: syncope/trunk/core/src/main/resources/restContext.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/resources/restContext.xml?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/core/src/main/resources/restContext.xml (original)
+++ syncope/trunk/core/src/main/resources/restContext.xml Wed Jan 23 07:58:26 2013
@@ -69,6 +69,7 @@ under the License.
       <ref bean="configurationServiceImpl"/>
       <ref bean="connectorServiceImpl"/>
       <ref bean="entitlementServiceImpl"/>
+      <ref bean="policyServiceImpl"/>
       <ref bean="schemaServiceImpl"/>
     </jaxrs:serviceBeans>
     <jaxrs:resourceComparator>

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ConfigurationTestITCase.java Wed Jan 23 07:58:26 2013
@@ -99,7 +99,8 @@ public class ConfigurationTestITCase ext
         value++;
         configurationTO.setValue(value + "");
 
-        ConfigurationTO newConfigurationTO = configurationService.update(configurationTO.getKey(), configurationTO);
+        configurationService.update(configurationTO.getKey(), configurationTO);
+        ConfigurationTO newConfigurationTO = configurationService.read(configurationTO.getKey());
         assertEquals(configurationTO, newConfigurationTO);
 
         newConfigurationTO = configurationService.read("token.expireTime");

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/PolicyTestITCase.java Wed Jan 23 07:58:26 2013
@@ -25,6 +25,8 @@ import static org.junit.Assert.fail;
 
 import java.util.List;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.syncope.common.to.AccountPolicyTO;
 import org.apache.syncope.common.to.PasswordPolicyTO;
 import org.apache.syncope.common.to.PolicyTO;
@@ -43,7 +45,7 @@ public class PolicyTestITCase extends Ab
 
     @Test
     public void listByType() {
-        List<SyncPolicyTO> policyTOs = policyService.listByType(PolicyType.SYNC);
+        List<SyncPolicyTO> policyTOs = policyService.list(PolicyType.SYNC);
 
         assertNotNull(policyTOs);
         assertFalse(policyTOs.isEmpty());
@@ -109,7 +111,9 @@ public class PolicyTestITCase extends Ab
     public void create() {
         SyncPolicyTO policy = buildSyncPolicyTO();
 
-        SyncPolicyTO policyTO = policyService.create(PolicyType.SYNC, policy);
+        Response response = policyService.create(PolicyType.SYNC, policy);
+        assertNotNull(response);
+        SyncPolicyTO policyTO = getObject(response.getLocation(), SyncPolicyTO.class);
 
         assertNotNull(policyTO);
         assertEquals(PolicyType.SYNC, policyTO.getType());
@@ -125,7 +129,9 @@ public class PolicyTestITCase extends Ab
         policy.setSpecification(globalPolicy.getSpecification());
 
         // create a new password policy using global password as a template
-        policy = policyService.create(PolicyType.PASSWORD, policy);
+        Response response = policyService.create(PolicyType.PASSWORD, policy);
+        assertNotNull(response);
+        policy = getObject(response.getLocation(), PasswordPolicyTO.class);
 
         // read new password policy
         policy = policyService.read(PolicyType.PASSWORD, policy.getId());
@@ -137,7 +143,8 @@ public class PolicyTestITCase extends Ab
         policy.setSpecification(policySpec);
 
         // update new password policy
-        policy = policyService.update(PolicyType.PASSWORD, policy.getId(), policy);
+        policyService.update(PolicyType.PASSWORD, policy.getId(), policy);
+        policy = policyService.read(PolicyType.PASSWORD, policy.getId());
 
         assertNotNull(policy);
         assertEquals(PolicyType.PASSWORD, policy.getType());
@@ -148,16 +155,16 @@ public class PolicyTestITCase extends Ab
     @Test
     public void delete() {
         SyncPolicyTO policy = buildSyncPolicyTO();
-        SyncPolicyTO policyTO = policyService.create(PolicyType.SYNC, policy);
+        Response response = policyService.create(PolicyType.SYNC, policy);
+        assertNotNull(response);
+        SyncPolicyTO policyTO = getObject(response.getLocation(), SyncPolicyTO.class);
         assertNotNull(policyTO);
 
-        PolicyTO policyToDelete =
-                policyService.delete(PolicyType.SYNC, policyTO.getId());
-        assertNotNull(policyToDelete);
+        policyService.delete(PolicyType.SYNC, policyTO.getId());
 
         Throwable t = null;
         try {
-        	policyService.read(PolicyType.SYNC, policyTO.getId());
+            policyService.read(PolicyType.SYNC, policyTO.getId());
         } catch (SyncopeClientCompositeErrorException e) {
             t = e;
         }
@@ -165,10 +172,10 @@ public class PolicyTestITCase extends Ab
         assertNotNull(t);
     }
 
-	private SyncPolicyTO buildSyncPolicyTO() {
-		SyncPolicyTO policy = new SyncPolicyTO();
+    private SyncPolicyTO buildSyncPolicyTO() {
+        SyncPolicyTO policy = new SyncPolicyTO();
         policy.setSpecification(new SyncPolicySpec());
         policy.setDescription("Sync policy");
-		return policy;
-	}
+        return policy;
+    }
 }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1437286&r1=1437285&r2=1437286&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Wed Jan 23 07:58:26 2013
@@ -32,6 +32,8 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.syncope.common.mod.AttributeMod;
 import org.apache.syncope.common.mod.MembershipMod;
 import org.apache.syncope.common.mod.UserMod;
@@ -73,7 +75,7 @@ import org.springframework.web.client.Ht
 @FixMethodOrder(MethodSorters.JVM)
 public class UserTestITCase extends AbstractTest {
 
-    private ConnObjectTO readUserConnObj(String resourceName, String userId) {
+    private ConnObjectTO readUserConnObj(final String resourceName, final String userId) {
         return resourceService.getConnector(resourceName, AttributableType.USER, userId);
     }
 
@@ -105,7 +107,7 @@ public class UserTestITCase extends Abst
         super.setupRestTemplate("user1", ADMIN_PWD);
 
         try {
-            userService.read(1l);
+            userService.read(1L);
             fail();
         } catch (HttpClientErrorException e) {
             assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode());
@@ -169,7 +171,7 @@ public class UserTestITCase extends Abst
      * introducing a simple control.
      */
     public void issue172() {
-        List<PasswordPolicyTO> policies = policyService.listByType(PolicyType.GLOBAL_PASSWORD);
+        List<PasswordPolicyTO> policies = policyService.list(PolicyType.GLOBAL_PASSWORD);
         for (PasswordPolicyTO policyTO : policies) {
             policyService.delete(PolicyType.PASSWORD, policyTO.getId());
         }
@@ -179,7 +181,9 @@ public class UserTestITCase extends Abst
             userService.create(userTO);
         } finally {
             for (PasswordPolicyTO policyTO : policies) {
-                PolicyTO cPolicyTO = policyService.create(PolicyType.GLOBAL_PASSWORD, policyTO);
+                Response response = policyService.create(PolicyType.GLOBAL_PASSWORD, policyTO);
+                assertNotNull(response);
+                PolicyTO cPolicyTO = getObject(response.getLocation(), PasswordPolicyTO.class);
                 assertNotNull(cPolicyTO);
             }
         }
@@ -399,8 +403,7 @@ public class UserTestITCase extends Abst
     @Test
     public void create() {
         // get task list
-        List<PropagationTaskTO> tasks =
-                taskService.list(TaskType.PROPAGATION);
+        List<PropagationTaskTO> tasks = taskService.list(TaskType.PROPAGATION);
 
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -467,7 +470,7 @@ public class UserTestITCase extends Abst
         }
 
         // default configuration for ws-target-resource2:
-        //             only failed executions have to be registered
+        // only failed executions have to be registered
         // --> no more tasks/executions should be added
         assertEquals(newMaxId, maxId);
 
@@ -667,8 +670,8 @@ public class UserTestITCase extends Abst
 
         exception = null;
         try {
-            final String username = jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class, userTO.
-                    getUsername());
+            final String username = jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class,
+                    userTO.getUsername());
             assertEquals(userTO.getUsername(), username);
         } catch (EmptyResultDataAccessException e) {
             exception = e;
@@ -687,7 +690,7 @@ public class UserTestITCase extends Abst
     @Test
     public void delete() {
         try {
-            userService.delete(0l);
+            userService.delete(0L);
         } catch (HttpStatusCodeException e) {
             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
         }
@@ -789,7 +792,7 @@ public class UserTestITCase extends Abst
 
     @Test
     public void read() {
-        UserTO userTO = userService.read(1l);
+        UserTO userTO = userService.read(1L);
 
         assertNotNull(userTO);
         assertNotNull(userTO.getAttributes());
@@ -985,7 +988,7 @@ public class UserTestITCase extends Abst
         }
 
         // default configuration for ws-target-resource2:
-        //             only failed executions have to be registered
+        // only failed executions have to be registered
         // --> no more tasks/executions should be added
         assertEquals(newMaxId, maxId);
 
@@ -1014,7 +1017,7 @@ public class UserTestITCase extends Abst
         }
 
         // default configuration for ws-target-resource2:
-        //             all update executions have to be registered
+        // all update executions have to be registered
         assertTrue(newMaxId > maxId);
 
         final PropagationTaskTO taskTO = taskService.read(TaskType.PROPAGATION, newMaxId);
@@ -1091,7 +1094,6 @@ public class UserTestITCase extends Abst
 
         userTO = userService.activateByUsername(userTO.getUsername(), userTO.getToken());
 
-
         assertNotNull(userTO);
         assertNull(userTO.getToken());
         assertNull(userTO.getTokenExpireTime());
@@ -1110,7 +1112,9 @@ public class UserTestITCase extends Abst
         userTO = userService.create(userTO);
 
         assertNotNull(userTO);
-        assertEquals(ActivitiDetector.isActivitiEnabledForUsers() ? "active" : "created", userTO.getStatus());
+        assertEquals(ActivitiDetector.isActivitiEnabledForUsers()
+                ? "active"
+                : "created", userTO.getStatus());
 
         userTO = userService.suspend(userTO.getId());
 
@@ -1134,7 +1138,9 @@ public class UserTestITCase extends Abst
         userTO = userService.create(userTO);
 
         assertNotNull(userTO);
-        assertEquals(ActivitiDetector.isActivitiEnabledForUsers() ? "active" : "created", userTO.getStatus());
+        assertEquals(ActivitiDetector.isActivitiEnabledForUsers()
+                ? "active"
+                : "created", userTO.getStatus());
 
         userTO = userService.suspendByUsername(userTO.getUsername());
 
@@ -1167,7 +1173,9 @@ public class UserTestITCase extends Abst
         userTO = userService.create(userTO);
 
         assertNotNull(userTO);
-        assertEquals(ActivitiDetector.isActivitiEnabledForUsers() ? "active" : "created", userTO.getStatus());
+        assertEquals(ActivitiDetector.isActivitiEnabledForUsers()
+                ? "active"
+                : "created", userTO.getStatus());
 
         String query = "?resourceNames=" + dbTable.getName() + "&resourceNames=" + ldap.getName()
                 + "&performLocally=true"; // check also performLocally
@@ -1181,9 +1189,8 @@ public class UserTestITCase extends Abst
         assertNotNull(dbTableUID);
 
         ConnObjectTO connObjectTO = readUserConnObj(dbTable.getName(), dbTableUID);
-        assertFalse(Boolean.parseBoolean(connObjectTO.getAttributeMap().get(OperationalAttributes.ENABLE_NAME).
-                getValues().
-                get(0)));
+        assertFalse(Boolean.parseBoolean(connObjectTO.getAttributeMap().get(OperationalAttributes.ENABLE_NAME)
+                .getValues().get(0)));
 
         String ldapUID = userTO.getUsername();
         assertNotNull(ldapUID);
@@ -1198,9 +1205,8 @@ public class UserTestITCase extends Abst
         assertEquals("suspended", userTO.getStatus());
 
         connObjectTO = readUserConnObj(dbTable.getName(), dbTableUID);
-        assertFalse(Boolean.parseBoolean(connObjectTO.getAttributeMap().get(OperationalAttributes.ENABLE_NAME).
-                getValues().
-                get(0)));
+        assertFalse(Boolean.parseBoolean(connObjectTO.getAttributeMap().get(OperationalAttributes.ENABLE_NAME)
+                .getValues().get(0)));
 
         query = "?resourceNames=" + dbTable.getName() + "&performLocally=true"; // check also performLocally
 
@@ -1209,9 +1215,8 @@ public class UserTestITCase extends Abst
         assertEquals("active", userTO.getStatus());
 
         connObjectTO = readUserConnObj(dbTable.getName(), dbTableUID);
-        assertTrue(Boolean.parseBoolean(connObjectTO.getAttributeMap().get(OperationalAttributes.ENABLE_NAME).
-                getValues().
-                get(0)));
+        assertTrue(Boolean.parseBoolean(connObjectTO.getAttributeMap().get(OperationalAttributes.ENABLE_NAME)
+                .getValues().get(0)));
     }
 
     public void updateMultivalueAttribute() {
@@ -1254,8 +1259,8 @@ public class UserTestITCase extends Abst
 
         JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
 
-        String username =
-                jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class, userTO.getUsername());
+        String username = jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class,
+                userTO.getUsername());
 
         assertEquals(userTO.getUsername(), username);
 
@@ -1615,7 +1620,8 @@ public class UserTestITCase extends Abst
         userMod.setId(actual.getId());
 
         MembershipTO membershipTO = actual.getMemberships().get(0).getRoleId() == 12L
-                ? actual.getMemberships().get(0) : actual.getMemberships().get(1);
+                ? actual.getMemberships().get(0)
+                : actual.getMemberships().get(1);
 
         userMod.addMembershipToBeRemoved(membershipTO.getId());
 
@@ -1627,8 +1633,8 @@ public class UserTestITCase extends Abst
         assertNotNull(connObjectTO);
 
         postalAddress = connObjectTO.getAttributeMap().get("postalAddress");
-        assertTrue(postalAddress == null
-                || postalAddress.getValues().isEmpty() || StringUtils.hasText(postalAddress.getValues().get(0)));
+        assertTrue(postalAddress == null || postalAddress.getValues().isEmpty()
+                || StringUtils.hasText(postalAddress.getValues().get(0)));
 
         title = connObjectTO.getAttributeMap().get("title");
         assertNotNull(title);
@@ -1672,7 +1678,8 @@ public class UserTestITCase extends Abst
         configurationTO.setKey("password.cipher.algorithm");
         configurationTO.setValue("MD5");
 
-        ConfigurationTO newConfTO = configurationService.update(configurationTO.getKey(), configurationTO);
+        configurationService.update(configurationTO.getKey(), configurationTO);
+        ConfigurationTO newConfTO = configurationService.read(configurationTO.getKey());
 
         assertEquals(configurationTO, newConfTO);
 
@@ -1683,11 +1690,12 @@ public class UserTestITCase extends Abst
             userService.create(userTO);
             fail();
         } catch (SyncopeClientCompositeErrorException e) {
-            assertTrue(
-                    e.getException(SyncopeClientExceptionType.NotFound).getElements().iterator().next().contains("MD5"));
+            assertTrue(e.getException(SyncopeClientExceptionType.NotFound).getElements().iterator().next()
+                    .contains("MD5"));
         }
 
-        ConfigurationTO oldConfTO = configurationService.update(defaultConfigurationTO.getKey(), defaultConfigurationTO);
+        configurationService.update(defaultConfigurationTO.getKey(), defaultConfigurationTO);
+        ConfigurationTO oldConfTO = configurationService.read(defaultConfigurationTO.getKey());
 
         assertEquals(defaultConfigurationTO, oldConfTO);
     }