Author: jbernhardt
Date: Mon Jan  7 15:21:55 2013
New Revision: 1429839

URL: http://svn.apache.org/viewvc?rev=1429839&view=rev
Log:
[SYNCOPE-259]
Introduces Policy Service
Updates in UserTestITCase to only use new Service Interfaces.

Added:
    
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyService.java
    
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyServiceProxy.java
Modified:
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.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

Added: 
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyService.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyService.java?rev=1429839&view=auto
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyService.java
 (added)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyService.java
 Mon Jan  7 15:21:55 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.services;
+
+import java.util.List;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import org.apache.syncope.client.to.PolicyTO;
+import org.apache.syncope.types.PolicyType;
+
+@Path("policies")
+public interface PolicyService {
+
+       @POST
+    <T extends PolicyTO> T create(final T policyTO);
+
+       @PUT
+       @Path("{policyId}")
+    <T extends PolicyTO> T update(@PathParam("policyId") final Long policyId, 
final T policyTO);
+
+       @GET
+       @Path("{type}")
+       <T extends PolicyTO> List<T> listByType(@PathParam("type") final 
PolicyType type);
+
+       // TODO: policyClass is required only for Spring RestTemplate mock. 
Must be removed for CXF
+       @GET
+       @Path("global/{type}")
+       <T extends PolicyTO> T readGlobal(@PathParam("type") final PolicyType 
type, Class<T> policyClass);
+
+       // TODO: policyClass is required only for Spring RestTemplate mock. 
Must be removed for CXF
+       @GET
+       @Path("{policyId}")
+       <T extends PolicyTO> T read(@PathParam("policyId") final Long policyId, 
Class<T> policyClass);
+
+       // TODO: policyClass is required only for Spring RestTemplate mock. 
Must be removed for CXF
+       @DELETE
+       @Path("{policyId}")
+       <T extends PolicyTO> T delete(@PathParam("policyId") final Long 
policyId, Class<T> policyClass);
+
+}
\ No newline at end of file

Added: 
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyServiceProxy.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyServiceProxy.java?rev=1429839&view=auto
==============================================================================
--- 
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyServiceProxy.java
 (added)
+++ 
syncope/trunk/client/src/main/java/org/apache/syncope/services/PolicyServiceProxy.java
 Mon Jan  7 15:21:55 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.services;
+
+import java.util.List;
+
+import org.apache.syncope.client.to.PolicyTO;
+import org.apache.syncope.types.PolicyType;
+import org.springframework.web.client.RestTemplate;
+
+public class PolicyServiceProxy extends SpringServiceProxy implements 
PolicyService {
+
+       public PolicyServiceProxy(String baseUrl, RestTemplate restTemplate) {
+               super(baseUrl, restTemplate);
+       }
+
+       @Override
+       public <T extends PolicyTO> T create(final T policyTO) {
+               @SuppressWarnings("unchecked")
+               T result = (T) restTemplate.postForObject(BASE_URL
+                               + "policy/{kind}/create", policyTO, 
policyTO.getClass(),
+                               typeToUrl(policyTO.getType()));
+               return result;
+       }
+
+       @Override
+       public <T extends PolicyTO> T update(Long policyId, T policyTO) {
+               @SuppressWarnings("unchecked")
+               T result = (T) restTemplate.postForObject(BASE_URL
+                               + "policy/{kind}/update", policyTO, 
policyTO.getClass(),
+                               typeToUrl(policyTO.getType()));
+               return result;
+       }
+
+       @Override
+       public <T extends PolicyTO> List<T> listByType(PolicyType type) {
+               @SuppressWarnings("unchecked")
+               List<T> result = restTemplate.getForObject(BASE_URL + 
"policy/{kind}/list",
+                               List.class, typeToUrl(type));
+               return result;
+       }
+
+       @Override
+       public <T extends PolicyTO> T readGlobal(PolicyType type, Class<T> 
policyClass) {
+               T result = restTemplate.getForObject(BASE_URL + 
"policy/{kind}/global/read",
+                policyClass, typeToUrl(type));
+               return result;
+       }
+
+       @Override
+       public <T extends PolicyTO> T read(Long policyId, Class<T> policyClass) 
{
+               T result = restTemplate.getForObject(BASE_URL + 
"policy/read/{id}", policyClass, policyId);
+               return result;
+       }
+
+       @Override
+       public <T extends PolicyTO> T delete(Long policyId, Class<T> 
policyClass) {
+               T result = restTemplate.getForObject(BASE_URL + 
"policy/delete/{id}", policyClass, policyId);
+               return result;
+       }
+
+    private String typeToUrl(PolicyType type) {
+       String url = type.name().toLowerCase();
+       int index = url.indexOf("_");
+       if (index != -1) {
+               return url.substring(index + 1);
+       } else {
+               return url;
+       }
+    }
+}

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=1429839&r1=1429838&r2=1429839&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 
Mon Jan  7 15:21:55 2013
@@ -34,6 +34,7 @@ import org.apache.syncope.services.Resou
 import org.apache.syncope.services.RoleServiceProxy;
 import org.apache.syncope.services.TaskServiceProxy;
 import org.apache.syncope.services.UserServiceProxy;
+import org.apache.syncope.services.PolicyServiceProxy;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
@@ -76,6 +77,8 @@ public abstract class AbstractTest {
 
        public static final String ADMIN_PWD = "password";
 
+       protected PolicyServiceProxy policyService;
+
        @Autowired
        protected RestTemplate restTemplate;
 
@@ -126,5 +129,6 @@ public abstract class AbstractTest {
                loggerService = new LoggerServiceProxy(BASE_URL, restTemplate);
                reportService = new ReportServiceProxy(BASE_URL, restTemplate);
                taskService = new TaskServiceProxy(BASE_URL, restTemplate);
+               policyService = new PolicyServiceProxy(BASE_URL, restTemplate);
        }
 }

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=1429839&r1=1429838&r2=1429839&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
 Mon Jan  7 15:21:55 2013
@@ -18,11 +18,13 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
-import java.util.Arrays;
 import java.util.List;
-import org.junit.Test;
+
 import org.apache.syncope.client.to.AccountPolicyTO;
 import org.apache.syncope.client.to.PasswordPolicyTO;
 import org.apache.syncope.client.to.PolicyTO;
@@ -33,6 +35,7 @@ import org.apache.syncope.types.PolicyTy
 import org.apache.syncope.types.SyncPolicySpec;
 import org.apache.syncope.types.SyncopeClientExceptionType;
 import org.junit.FixMethodOrder;
+import org.junit.Test;
 import org.junit.runners.MethodSorters;
 
 @FixMethodOrder(MethodSorters.JVM)
@@ -40,24 +43,22 @@ public class PolicyTestITCase extends Ab
 
     @Test
     public void listByType() {
-        List<SyncPolicyTO> policyTOs = 
Arrays.asList(restTemplate.getForObject(BASE_URL + "policy/{kind}/list",
-                SyncPolicyTO[].class, PolicyType.SYNC.toString()));
-
+        List<SyncPolicyTO> policyTOs = 
policyService.listByType(PolicyType.SYNC);
+        
         assertNotNull(policyTOs);
         assertFalse(policyTOs.isEmpty());
     }
 
     @Test
     public void read() {
-        SyncPolicyTO policyTO = restTemplate.getForObject(BASE_URL + 
"policy/read/{id}", SyncPolicyTO.class, 1L);
+        SyncPolicyTO policyTO = policyService.read(1L, SyncPolicyTO.class);
 
         assertNotNull(policyTO);
     }
 
     @Test
     public void getGlobalPasswordPolicy() {
-        PasswordPolicyTO policyTO = restTemplate.getForObject(BASE_URL + 
"policy/password/global/read",
-                PasswordPolicyTO.class);
+        PasswordPolicyTO policyTO = 
policyService.readGlobal(PolicyType.PASSWORD, PasswordPolicyTO.class);
 
         assertNotNull(policyTO);
         assertEquals(PolicyType.GLOBAL_PASSWORD, policyTO.getType());
@@ -66,8 +67,7 @@ public class PolicyTestITCase extends Ab
 
     @Test
     public void getGlobalAccountPolicy() {
-        AccountPolicyTO policyTO = restTemplate.getForObject(BASE_URL + 
"policy/account/global/read",
-                AccountPolicyTO.class);
+        AccountPolicyTO policyTO = 
policyService.readGlobal(PolicyType.ACCOUNT, AccountPolicyTO.class);
 
         assertNotNull(policyTO);
         assertEquals(PolicyType.GLOBAL_ACCOUNT, policyTO.getType());
@@ -78,10 +78,11 @@ public class PolicyTestITCase extends Ab
         PasswordPolicyTO policy = new PasswordPolicyTO(true);
         policy.setSpecification(new PasswordPolicySpec());
         policy.setDescription("global password policy");
+        System.out.println(policy.getType());
 
         Throwable t = null;
         try {
-            restTemplate.postForObject(BASE_URL + "policy/password/create", 
policy, PasswordPolicyTO.class);
+            policyService.create(policy);
             fail();
         } catch (SyncopeClientCompositeErrorException sccee) {
             t = 
sccee.getException(SyncopeClientExceptionType.InvalidPasswordPolicy);
@@ -96,7 +97,7 @@ public class PolicyTestITCase extends Ab
 
         Throwable t = null;
         try {
-            restTemplate.postForObject(BASE_URL + "policy/sync/create", 
policy, PasswordPolicyTO.class);
+            policyService.create(policy);
             fail();
         } catch (SyncopeClientCompositeErrorException sccee) {
             t = 
sccee.getException(SyncopeClientExceptionType.InvalidSyncPolicy);
@@ -110,7 +111,7 @@ public class PolicyTestITCase extends Ab
         policy.setSpecification(new SyncPolicySpec());
         policy.setDescription("Sync policy");
 
-        SyncPolicyTO policyTO = restTemplate.postForObject(BASE_URL + 
"policy/sync/create", policy, SyncPolicyTO.class);
+        SyncPolicyTO policyTO = policyService.create(policy);
 
         assertNotNull(policyTO);
         assertEquals(PolicyType.SYNC, policyTO.getType());
@@ -119,18 +120,17 @@ public class PolicyTestITCase extends Ab
     @Test
     public void update() {
         // get global password
-        PasswordPolicyTO globalPolicy = restTemplate.getForObject(BASE_URL + 
"policy/read/{id}",
-                PasswordPolicyTO.class, 2L);
+        PasswordPolicyTO globalPolicy = policyService.read(2L, 
PasswordPolicyTO.class);
 
         PasswordPolicyTO policy = new PasswordPolicyTO();
         policy.setDescription("A simple password policy");
         policy.setSpecification(globalPolicy.getSpecification());
 
         // create a new password policy using global password as a template
-        policy = restTemplate.postForObject(BASE_URL + 
"policy/password/create", policy, PasswordPolicyTO.class);
+        policy = policyService.create(policy);
 
         // read new password policy
-        policy = restTemplate.getForObject(BASE_URL + "policy/read/{id}", 
PasswordPolicyTO.class, policy.getId());
+        policy = policyService.read(policy.getId(), PasswordPolicyTO.class);
 
         assertNotNull("find to update did not work", policy);
 
@@ -139,7 +139,7 @@ public class PolicyTestITCase extends Ab
         policy.setSpecification(policySpec);
 
         // update new password policy
-        policy = restTemplate.postForObject(BASE_URL + 
"policy/password/update", policy, PasswordPolicyTO.class);
+        policy = policyService.update(policy.getId(), policy);
 
         assertNotNull(policy);
         assertEquals(PolicyType.PASSWORD, policy.getType());
@@ -149,21 +149,22 @@ public class PolicyTestITCase extends Ab
 
     @Test
     public void delete() {
-        final PolicyTO policyTO = restTemplate.getForObject(BASE_URL + 
"policy/read/{id}", SyncPolicyTO.class, 7L);
+        final SyncPolicyTO policyTO = policyService.read(7L, 
SyncPolicyTO.class);
 
         assertNotNull("find to delete did not work", policyTO);
 
         PolicyTO policyToDelete =
-                restTemplate.getForObject(BASE_URL + "policy/delete/{id}", 
SyncPolicyTO.class, 7L);
+                policyService.delete(7L, SyncPolicyTO.class);
         assertNotNull(policyToDelete);
 
         Throwable t = null;
         try {
-            restTemplate.getForObject(BASE_URL + "policy/read/{id}", 
SyncPolicyTO.class, 7L);
+               policyService.read(7L, SyncPolicyTO.class);
         } catch (SyncopeClientCompositeErrorException e) {
             t = e;
         }
 
         assertNotNull(t);
     }
+    
 }

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=1429839&r1=1429838&r2=1429839&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
 Mon Jan  7 15:21:55 2013
@@ -18,15 +18,20 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
@@ -112,8 +117,7 @@ public class UserTestITCase extends Abst
     @Test
     public void createUserWithNoPropagation() {
         // get task list
-        List<PropagationTaskTO> tasks = 
Arrays.asList(restTemplate.getForObject(BASE_URL + "task/propagation/list",
-                PropagationTaskTO[].class));
+        List<PropagationTaskTO> tasks = taskService.list("propagation", 
PropagationTaskTO[].class);
 
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -141,7 +145,7 @@ public class UserTestITCase extends Abst
         userService.create(userTO);
 
         // get the new task list
-        tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + 
"task/propagation/list", PropagationTaskTO[].class));
+        tasks = taskService.list("propagation", PropagationTaskTO[].class);
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
 
@@ -156,8 +160,7 @@ public class UserTestITCase extends Abst
         assertTrue(newMaxId > maxId);
 
         // get last task
-        PropagationTaskTO taskTO = restTemplate.getForObject(BASE_URL + 
"task/read/{taskId}", PropagationTaskTO.class,
-                newMaxId);
+        PropagationTaskTO taskTO = taskService.read(newMaxId, 
PropagationTaskTO.class);
 
         assertNotNull(taskTO);
         assertTrue(taskTO.getExecutions().isEmpty());
@@ -171,11 +174,11 @@ public class UserTestITCase extends Abst
      * introducing a simple control.
      */
     public void issue172() {
-        PolicyTO policyTO = restTemplate.getForObject(BASE_URL + 
"policy/read/{id}", PasswordPolicyTO.class, 2L);
+        PolicyTO policyTO = policyService.read(2L, PasswordPolicyTO.class);
 
         assertNotNull(policyTO);
 
-        restTemplate.getForObject(BASE_URL + "policy/delete/{id}", 
PasswordPolicyTO.class, 2L);
+        policyService.delete(2L, PasswordPolicyTO.class);
 
         UserTO userTO = new UserTO();
         userTO.setUsername("[email protected]");
@@ -188,7 +191,7 @@ public class UserTestITCase extends Abst
 
         userService.create(userTO);
 
-        policyTO = restTemplate.postForObject(BASE_URL + 
"policy/password/create", policyTO, PasswordPolicyTO.class);
+        policyService.create(policyTO);
 
         assertNotNull(policyTO);
     }
@@ -284,12 +287,11 @@ public class UserTestITCase extends Abst
 
     @Test
     public void testEnforceMandatoryConditionOnDerived() {
-        ResourceTO resourceTO = restTemplate.getForObject(BASE_URL + 
"/resource/read/{resourceName}.json",
-                ResourceTO.class, "resource-csv");
+        ResourceTO resourceTO = resourceService.read("resource-csv");
         assertNotNull(resourceTO);
         resourceTO.setName("resource-csv-enforcing");
         resourceTO.setEnforceMandatoryCondition(true);
-        resourceTO = restTemplate.postForObject(BASE_URL + 
"resource/create.json", resourceTO, ResourceTO.class);
+        resourceTO = resourceService.create(resourceTO);
         assertNotNull(resourceTO);
 
         UserTO userTO = getSampleTO("[email protected]");
@@ -414,7 +416,7 @@ public class UserTestITCase extends Abst
     public void create() {
         // get task list
         List<PropagationTaskTO> tasks =
-                Arrays.asList(restTemplate.getForObject(BASE_URL + 
"task/propagation/list", PropagationTaskTO[].class));
+                taskService.list("propagation", PropagationTaskTO[].class);
 
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -426,8 +428,7 @@ public class UserTestITCase extends Abst
                 maxId = task.getId();
             }
         }
-        PropagationTaskTO taskTO =
-                restTemplate.getForObject(BASE_URL + "task/read/{taskId}", 
PropagationTaskTO.class, maxId);
+        PropagationTaskTO taskTO = taskService.read(maxId, 
PropagationTaskTO.class);
 
         assertNotNull(taskTO);
         int maxTaskExecutions = taskTO.getExecutions().size();
@@ -468,7 +469,7 @@ public class UserTestITCase extends Abst
         assertEquals("virtualvalue", 
newUserTO.getVirtualAttributeMap().get("virtualdata").getValues().get(0));
 
         // get the new task list
-        tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + 
"task/propagation/list", PropagationTaskTO[].class));
+        tasks = taskService.list("propagation", PropagationTaskTO[].class);
 
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -487,7 +488,7 @@ public class UserTestITCase extends Abst
         assertEquals(newMaxId, maxId);
 
         // get last task
-        taskTO = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", 
PropagationTaskTO.class, newMaxId);
+        taskTO = taskService.read(newMaxId, PropagationTaskTO.class);
 
         assertNotNull(taskTO);
         assertEquals(maxTaskExecutions, taskTO.getExecutions().size());
@@ -924,8 +925,7 @@ public class UserTestITCase extends Abst
 
     @Test
     public void updatePasswordOnly() {
-        List<PropagationTaskTO> beforeTasks = 
Arrays.asList(restTemplate.getForObject(BASE_URL
-                + "task/propagation/list", PropagationTaskTO[].class));
+        List<PropagationTaskTO> beforeTasks = taskService.list("propagation", 
PropagationTaskTO[].class);
         assertNotNull(beforeTasks);
         assertFalse(beforeTasks.isEmpty());
 
@@ -950,8 +950,7 @@ public class UserTestITCase extends Abst
         passwordTestUser.setPassword("newPassword123", CipherAlgorithm.SHA1, 
0);
         assertEquals(passwordTestUser.getPassword(), userTO.getPassword());
 
-        List<PropagationTaskTO> afterTasks = 
Arrays.asList(restTemplate.getForObject(
-                BASE_URL + "task/propagation/list", 
PropagationTaskTO[].class));
+        List<PropagationTaskTO> afterTasks = taskService.list("propagation", 
PropagationTaskTO[].class);
         assertNotNull(afterTasks);
         assertFalse(afterTasks.isEmpty());
 
@@ -961,8 +960,7 @@ public class UserTestITCase extends Abst
     @Test
     public void verifyTaskRegistration() {
         // get task list
-        List<PropagationTaskTO> tasks = 
Arrays.asList(restTemplate.getForObject(BASE_URL + "task/propagation/list",
-                PropagationTaskTO[].class));
+        List<PropagationTaskTO> tasks = taskService.list("propagation", 
PropagationTaskTO[].class);
 
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -991,7 +989,7 @@ public class UserTestITCase extends Abst
         assertNotNull(userTO);
 
         // get the new task list
-        tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + 
"task/propagation/list", PropagationTaskTO[].class));
+        tasks = taskService.list("propagation", PropagationTaskTO[].class);
 
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
@@ -1022,7 +1020,7 @@ public class UserTestITCase extends Abst
         assertNotNull(userTO);
 
         // get the new task list
-        tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + 
"task/propagation/list", PropagationTaskTO[].class));
+        tasks = taskService.list("propagation", PropagationTaskTO[].class);
 
         // get max task id
         maxId = newMaxId;
@@ -1037,8 +1035,7 @@ public class UserTestITCase extends Abst
         //             all update executions have to be registered
         assertTrue(newMaxId > maxId);
 
-        final PropagationTaskTO taskTO =
-                restTemplate.getForObject(BASE_URL + "task/read/{taskId}", 
PropagationTaskTO.class, newMaxId);
+        final PropagationTaskTO taskTO = taskService.read(newMaxId, 
PropagationTaskTO.class);
 
         assertNotNull(taskTO);
         assertEquals(1, taskTO.getExecutions().size());
@@ -1049,7 +1046,7 @@ public class UserTestITCase extends Abst
         userService.delete(userTO.getId());
 
         // get the new task list
-        tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + 
"task/propagation/list", PropagationTaskTO[].class));
+        tasks = taskService.list("propagation", PropagationTaskTO[].class);
 
         // get max task id
         maxId = newMaxId;
@@ -1175,14 +1172,12 @@ public class UserTestITCase extends Abst
         userTO.getMemberships().clear();
         userTO.getResources().clear();
 
-        ResourceTO dbTable = restTemplate.getForObject(BASE_URL + 
"/resource/read/{resourceName}.json",
-                ResourceTO.class, "resource-testdb");
+        ResourceTO dbTable = resourceService.read("resource-testdb");
 
         assertNotNull(dbTable);
         userTO.addResource(dbTable.getName());
 
-        ResourceTO ldap = restTemplate.getForObject(BASE_URL + 
"/resource/read/{resourceName}.json", ResourceTO.class,
-                "resource-ldap");
+        ResourceTO ldap = resourceService.read("resource-ldap");
 
         assertNotNull(ldap);
         userTO.addResource(ldap.getName());
@@ -1689,15 +1684,13 @@ public class UserTestITCase extends Abst
 
     @Test()
     public void issueSYNCOPE51() {
-        ConfigurationTO defaultConfigurationTO = restTemplate.getForObject(
-                BASE_URL + "configuration/read/{key}.json", 
ConfigurationTO.class, "password.cipher.algorithm");
+        ConfigurationTO defaultConfigurationTO = 
configurationService.read("password.cipher.algorithm");
 
         ConfigurationTO configurationTO = new ConfigurationTO();
         configurationTO.setKey("password.cipher.algorithm");
         configurationTO.setValue("MD5");
 
-        ConfigurationTO newConfTO =
-                restTemplate.postForObject(BASE_URL + "configuration/update", 
configurationTO, ConfigurationTO.class);
+        ConfigurationTO newConfTO = 
configurationService.update(configurationTO.getKey(), configurationTO);
 
         assertEquals(configurationTO, newConfTO);
 
@@ -1712,8 +1705,7 @@ public class UserTestITCase extends Abst
                     
e.getException(SyncopeClientExceptionType.NotFound).getElements().iterator().next().contains("MD5"));
         }
 
-        ConfigurationTO oldConfTO = restTemplate.postForObject(
-                BASE_URL + "configuration/update", defaultConfigurationTO, 
ConfigurationTO.class);
+        ConfigurationTO oldConfTO = 
configurationService.update(defaultConfigurationTO.getKey(), 
defaultConfigurationTO);
 
         assertEquals(defaultConfigurationTO, oldConfTO);
     }
@@ -1726,7 +1718,7 @@ public class UserTestITCase extends Abst
         UserTO userTO = getSampleTO("[email protected]");
         userTO.addResource("ws-target-resource-2");
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, 
UserTO.class);
+        userTO = userService.create(userTO);
         assertNotNull(userTO);
         assertFalse(userTO.getPropagationTOs().isEmpty());
         assertEquals("ws-target-resource-2", 
userTO.getPropagationTOs().get(0).getResourceName());
@@ -1750,7 +1742,7 @@ public class UserTestITCase extends Abst
 
         userMod.addVirtualAttributeToBeUpdated(attrMod);
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, 
UserTO.class);
+        userTO = userService.update(userMod.getId(), userMod);
         assertNotNull(userTO);
         assertFalse(userTO.getPropagationTOs().isEmpty());
         assertEquals("ws-target-resource-2", 
userTO.getPropagationTOs().get(0).getResourceName());
@@ -1794,7 +1786,7 @@ public class UserTestITCase extends Abst
 
         userMod.addAttributeToBeUpdated(attrMod);
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, 
UserTO.class);
+        userTO = userService.update(userMod.getId(), userMod);
         assertNotNull(userTO);
         assertFalse(userTO.getPropagationTOs().isEmpty());
         assertEquals("ws-target-resource-2", 
userTO.getPropagationTOs().get(0).getResourceName());
@@ -1816,7 +1808,7 @@ public class UserTestITCase extends Abst
         userMod.setId(userTO.getId());
         userMod.addVirtualAttributeToBeRemoved("virtualdata");
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, 
UserTO.class);
+        userTO = userService.update(userMod.getId(), userMod);
         assertNotNull(userTO);
         assertTrue(userTO.getVirtualAttributes().isEmpty());
         assertFalse(userTO.getPropagationTOs().isEmpty());


Reply via email to