syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbernha...@apache.org
Subject svn commit: r1430219 - in /syncope/trunk: client/src/main/java/org/apache/syncope/client/to/ client/src/main/java/org/apache/syncope/services/ client/src/main/java/org/apache/syncope/services/proxy/ core/src/main/java/org/apache/syncope/core/rest/contr...
Date Tue, 08 Jan 2013 11:24:02 GMT
Author: jbernhardt
Date: Tue Jan  8 11:24:02 2013
New Revision: 1430219

URL: http://svn.apache.org/viewvc?rev=1430219&view=rev
Log:
[SYNCOPE-259]
Introduces Schema Service.

Added:
    syncope/trunk/client/src/main/java/org/apache/syncope/client/to/AbstractSchemaTO.java
    syncope/trunk/client/src/main/java/org/apache/syncope/services/SchemaService.java
    syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/SchemaServiceProxy.java
Modified:
    syncope/trunk/client/src/main/java/org/apache/syncope/client/to/DerivedSchemaTO.java
    syncope/trunk/client/src/main/java/org/apache/syncope/client/to/SchemaTO.java
    syncope/trunk/client/src/main/java/org/apache/syncope/client/to/VirtualSchemaTO.java
    syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/TaskServiceProxy.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.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/DerivedSchemaTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
    syncope/trunk/core/src/test/resources/restClientContext.xml

Added: syncope/trunk/client/src/main/java/org/apache/syncope/client/to/AbstractSchemaTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/to/AbstractSchemaTO.java?rev=1430219&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/to/AbstractSchemaTO.java
(added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/to/AbstractSchemaTO.java
Tue Jan  8 11:24:02 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.client.to;
+
+import org.apache.syncope.client.AbstractBaseBean;
+
+public abstract class AbstractSchemaTO extends AbstractBaseBean {
+
+    private static final long serialVersionUID = 4088388951694301759L;
+
+    private String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/to/DerivedSchemaTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/to/DerivedSchemaTO.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/to/DerivedSchemaTO.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/to/DerivedSchemaTO.java Tue
Jan  8 11:24:02 2013
@@ -18,22 +18,13 @@
  */
 package org.apache.syncope.client.to;
 
-import org.apache.syncope.client.AbstractBaseBean;
 
-public class DerivedSchemaTO extends AbstractBaseBean {
+public class DerivedSchemaTO extends AbstractSchemaTO {
 
-    private String name;
+    private static final long serialVersionUID = -6747399803792103108L;
 
     private String expression;
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
     public String getExpression() {
         return expression;
     }

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/to/SchemaTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/to/SchemaTO.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/to/SchemaTO.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/to/SchemaTO.java Tue Jan
 8 11:24:02 2013
@@ -19,15 +19,12 @@
 package org.apache.syncope.client.to;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.syncope.client.AbstractBaseBean;
 import org.apache.syncope.types.SchemaType;
 
-public class SchemaTO extends AbstractBaseBean {
+public class SchemaTO extends AbstractSchemaTO {
 
     private static final long serialVersionUID = -8133983392476990308L;
 
-    private String name;
-
     private SchemaType type;
 
     private String mandatoryCondition;
@@ -108,14 +105,6 @@ public class SchemaTO extends AbstractBa
         this.readonly = readonly;
     }
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
     public SchemaType getType() {
         return type;
     }

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/to/VirtualSchemaTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/to/VirtualSchemaTO.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/to/VirtualSchemaTO.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/to/VirtualSchemaTO.java Tue
Jan  8 11:24:02 2013
@@ -18,17 +18,8 @@
  */
 package org.apache.syncope.client.to;
 
-import org.apache.syncope.client.AbstractBaseBean;
+public class VirtualSchemaTO extends AbstractSchemaTO {
 
-public class VirtualSchemaTO extends AbstractBaseBean {
+    private static final long serialVersionUID = -8198557479659701343L;
 
-    private String name;
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
 }

Added: syncope/trunk/client/src/main/java/org/apache/syncope/services/SchemaService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/SchemaService.java?rev=1430219&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/SchemaService.java (added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/SchemaService.java Tue
Jan  8 11:24:02 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.AbstractSchemaTO;
+
+@Path("schemas")
+public interface SchemaService {
+
+    @POST
+    //    @RequestMapping(method = RequestMethod.POST, value = "/{kind}/create")
+    <T extends AbstractSchemaTO> T create(@PathParam("kind") final String kind, final
T schemaTO);
+
+    @DELETE
+    @Path("{kind}/{schema}")
+    //    @RequestMapping(method = RequestMethod.GET, value = "/{kind}/delete/{schema}")
+    <T extends AbstractSchemaTO> T delete(@PathParam("kind") final String kind,
+            @PathParam("schema") final String schemaName, final Class<T> type);
+
+    @GET
+    @Path("{kind}")
+    //    @RequestMapping(method = RequestMethod.GET, value = "/{kind}/list")
+    <T extends AbstractSchemaTO> List<T> list(@PathParam("kind") final String
kind, final Class<T[]> type);
+
+    @GET
+    @Path("{kind}/{schema}")
+    //    @RequestMapping(method = RequestMethod.GET, value = "/{kind}/read/{schema}")
+    <T extends AbstractSchemaTO> T read(@PathParam("kind") final String kind,
+            @PathParam("schema") final String schemaName, final Class<T> type);
+
+    @PUT
+    @Path("{kind}/{schema}")
+    //    @RequestMapping(method = RequestMethod.POST, value = "/{kind}/update")
+    <T extends AbstractSchemaTO> T update(@PathParam("kind") final String kind,
+            @PathParam("schema") final String schemaName, final T schemaTO);
+
+}
\ No newline at end of file

Added: syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/SchemaServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/SchemaServiceProxy.java?rev=1430219&view=auto
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/SchemaServiceProxy.java
(added)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/SchemaServiceProxy.java
Tue Jan  8 11:24:02 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.proxy;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.syncope.client.to.AbstractSchemaTO;
+import org.apache.syncope.client.to.DerivedSchemaTO;
+import org.apache.syncope.client.to.SchemaTO;
+import org.apache.syncope.client.to.VirtualSchemaTO;
+import org.apache.syncope.services.SchemaService;
+import org.springframework.web.client.RestTemplate;
+
+public class SchemaServiceProxy extends SpringServiceProxy implements SchemaService {
+
+    public SchemaServiceProxy(String baseUrl, RestTemplate restTemplate) {
+        super(baseUrl, restTemplate);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends AbstractSchemaTO> T create(String kind, T schemaTO) {
+        String schemaType = getSchemaType(schemaTO.getClass());
+
+        return (T) restTemplate.postForObject(BASE_URL + schemaType + "/{kind}/create", schemaTO,
+                schemaTO.getClass(), kind);
+    }
+
+    @Override
+    public <T extends AbstractSchemaTO> T delete(String kind, String schemaName, Class<T>
type) {
+        String schemaType = getSchemaType(type);
+        return restTemplate.getForObject(BASE_URL + schemaType + "/{kind}/delete/{name}.json",
type, kind,
+                schemaName);
+    }
+
+    @Override
+    public <T extends AbstractSchemaTO> List<T> list(String kind, Class<T[]>
type) {
+        String schemaType = getSchemaTypeArray(type);
+        return Arrays.asList(restTemplate.getForObject(BASE_URL + schemaType + "/{kind}/list.json",
type,
+                kind));
+    }
+
+    @Override
+    public <T extends AbstractSchemaTO> T read(String kind, String schemaName, Class<T>
type) {
+        String schemaType = getSchemaType(type);
+        return restTemplate.getForObject(BASE_URL + schemaType + "/{kind}/read/{name}.json",
type, kind,
+                schemaName);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public <T extends AbstractSchemaTO> T update(String kind, String schemaName, T
schemaTO) {
+        String schemaType = getSchemaType(schemaTO.getClass());
+        return (T) restTemplate.postForObject(BASE_URL + schemaType + "/{kind}/update", schemaTO,
+                schemaTO.getClass(), kind);
+    }
+
+    private String getSchemaType(Class<? extends AbstractSchemaTO> type) {
+        return (type.isAssignableFrom(SchemaTO.class))
+                ? "schema"
+                : (type.isAssignableFrom(DerivedSchemaTO.class))
+                        ? "derivedSchema"
+                        : (type.isAssignableFrom(VirtualSchemaTO.class))
+                                ? "virtualSchema"
+                                : "";
+    }
+
+    private <T extends AbstractSchemaTO> String getSchemaTypeArray(Class<T[]>
type) {
+        return (type.isAssignableFrom(SchemaTO[].class))
+                ? "schema"
+                : (type.isAssignableFrom(DerivedSchemaTO[].class))
+                        ? "derivedSchema"
+                        : (type.isAssignableFrom(VirtualSchemaTO[].class))
+                                ? "virtualSchema"
+                                : "";
+    }
+}

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/TaskServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/TaskServiceProxy.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/TaskServiceProxy.java
(original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/services/proxy/TaskServiceProxy.java
Tue Jan  8 11:24:02 2013
@@ -129,7 +129,6 @@ public class TaskServiceProxy extends Sp
                 ? "sync"
                 : (taskTO instanceof SchedTaskTO)
                         ? "sched"
-
                         : null;
         if (path == null)
             throw new IllegalArgumentException("Task can only be instance of SchedTaskTO
or SyncTaskTO");

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java
Tue Jan  8 11:24:02 2013
@@ -20,7 +20,9 @@ package org.apache.syncope.core.rest.con
 
 import java.util.ArrayList;
 import java.util.List;
+
 import javax.servlet.http.HttpServletResponse;
+
 import org.apache.syncope.client.to.SchemaTO;
 import org.apache.syncope.core.audit.AuditManager;
 import org.apache.syncope.core.persistence.beans.AbstractSchema;
@@ -78,14 +80,14 @@ public class SchemaController extends Ab
         if (schema == null) {
             throw new NotFoundException("Schema '" + schemaName + "'");
         }
-        
+
         SchemaTO schemaToDelete = schemaDataBinder.getSchemaTO(schema, getAttributableUtil(kind));
 
         schemaDAO.delete(schemaName, getAttributableUtil(kind));
 
         auditManager.audit(Category.schema, SchemaSubCategory.delete, Result.success,
                 "Successfully deleted schema: " + kind + "/" + schema.getName());
-        
+
         return schemaToDelete;
     }
 

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=1430219&r1=1430218&r2=1430219&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
 8 11:24:02 2013
@@ -34,6 +34,7 @@ import org.apache.syncope.services.proxy
 import org.apache.syncope.services.proxy.ReportServiceProxy;
 import org.apache.syncope.services.proxy.ResourceServiceProxy;
 import org.apache.syncope.services.proxy.RoleServiceProxy;
+import org.apache.syncope.services.proxy.SchemaServiceProxy;
 import org.apache.syncope.services.proxy.TaskServiceProxy;
 import org.apache.syncope.services.proxy.UserServiceProxy;
 import org.apache.syncope.services.proxy.WorkflowServiceProxy;
@@ -69,7 +70,7 @@ public abstract class AbstractTest {
      */
     protected static final Logger LOG = LoggerFactory.getLogger(AbstractTest.class);
 
-    protected static final String BASE_URL = "http://localhost:9080/syncope/rest/";
+    protected static final String BASE_URL = "http://localhost:9081/syncope/rest/";
 
     public static final String ADMIN_UID = "admin";
 
@@ -102,6 +103,8 @@ public abstract class AbstractTest {
 
     protected NotificationServiceProxy notificationService;
 
+    protected SchemaServiceProxy schemaService;
+
     @Autowired
     protected DataSource testDataSource;
 
@@ -132,5 +135,6 @@ public abstract class AbstractTest {
         policyService = new PolicyServiceProxy(BASE_URL, restTemplate);
         workflowService = new WorkflowServiceProxy(BASE_URL, restTemplate);
         notificationService = new NotificationServiceProxy(BASE_URL, restTemplate);
+        schemaService = new SchemaServiceProxy(BASE_URL, restTemplate);
     }
 }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
(original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/DerivedSchemaTestITCase.java
Tue Jan  8 11:24:02 2013
@@ -32,6 +32,10 @@ import org.junit.runners.MethodSorters;
 @FixMethodOrder(MethodSorters.JVM)
 public class DerivedSchemaTestITCase extends AbstractTest {
 
+    private static final String ROLE = "role";
+    private static final String USER = "user";
+    private static final String MEMBERSHIP = "membership";
+
     @Test
     public void list() {
         List<DerivedSchemaTO> derivedSchemas = Arrays.asList(restTemplate.getForObject(BASE_URL
@@ -44,8 +48,7 @@ public class DerivedSchemaTestITCase ext
 
     @Test
     public void read() {
-        DerivedSchemaTO derivedSchemaTO = restTemplate.getForObject(BASE_URL + "derivedSchema/user/read/cn.json",
-                DerivedSchemaTO.class);
+        DerivedSchemaTO derivedSchemaTO = schemaService.read(USER, "cn", DerivedSchemaTO.class);
         assertNotNull(derivedSchemaTO);
     }
 
@@ -55,30 +58,25 @@ public class DerivedSchemaTestITCase ext
         schema.setName("derived");
         schema.setExpression("derived_sx + '_' + derived_dx");
 
-        DerivedSchemaTO actual = restTemplate.postForObject(BASE_URL + "derivedSchema/user/create.json",
schema,
-                DerivedSchemaTO.class);
+        DerivedSchemaTO actual = schemaService.create(USER, schema);
         assertNotNull(actual);
 
-        actual = restTemplate.getForObject(BASE_URL + "derivedSchema/user/read/" + actual.getName()
+ ".json",
-                DerivedSchemaTO.class);
+        actual = schemaService.read(USER, actual.getName(), DerivedSchemaTO.class);
         assertNotNull(actual);
         assertEquals(actual.getExpression(), "derived_sx + '_' + derived_dx");
     }
 
     @Test
     public void delete() {
-        DerivedSchemaTO schema = restTemplate.getForObject(BASE_URL + "derivedSchema/role/read/rderiveddata.json",
-                DerivedSchemaTO.class);
+        DerivedSchemaTO schema = schemaService.read(ROLE, "rderiveddata", DerivedSchemaTO.class);
         assertNotNull(schema);
 
-        DerivedSchemaTO schemaToDelete =
-                restTemplate.getForObject(
-                BASE_URL + "derivedSchema/role/delete/{schema}", DerivedSchemaTO.class, schema.getName());
+        DerivedSchemaTO schemaToDelete = schemaService.delete(ROLE, schema.getName(), DerivedSchemaTO.class);
         assertNotNull(schemaToDelete);
 
         Throwable t = null;
         try {
-            restTemplate.getForObject(BASE_URL + "derivedSchema/role/read/rderiveddata.json",
DerivedSchemaTO.class);
+            schemaService.read(ROLE, "rderiveddata", DerivedSchemaTO.class);
         } catch (SyncopeClientCompositeErrorException e) {
             t = e;
             assertNotNull(e.getException(SyncopeClientExceptionType.NotFound));
@@ -88,19 +86,16 @@ public class DerivedSchemaTestITCase ext
 
     @Test
     public void update() {
-        DerivedSchemaTO schema = restTemplate.getForObject(
-                BASE_URL + "derivedSchema/membership/read/mderiveddata.json", DerivedSchemaTO.class);
+        DerivedSchemaTO schema = schemaService.read(MEMBERSHIP, "mderiveddata", DerivedSchemaTO.class);
         assertNotNull(schema);
         assertEquals("mderived_sx + '-' + mderived_dx", schema.getExpression());
 
         schema.setExpression("mderived_sx + '.' + mderived_dx");
 
-        schema = restTemplate.postForObject(BASE_URL + "derivedSchema/membership/update.json",
schema,
-                DerivedSchemaTO.class);
+        schema = schemaService.update(MEMBERSHIP, schema.getName(), schema);
         assertNotNull(schema);
 
-        schema = restTemplate.getForObject(BASE_URL + "derivedSchema/membership/read/mderiveddata.json",
-                DerivedSchemaTO.class);
+        schema = schemaService.read(MEMBERSHIP, "mderiveddata", DerivedSchemaTO.class);
         assertNotNull(schema);
         assertEquals("mderived_sx + '.' + mderived_dx", schema.getExpression());
     }

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java Tue
Jan  8 11:24:02 2013
@@ -18,8 +18,15 @@
  */
 package org.apache.syncope.core.rest;
 
-import java.util.Arrays;
+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.util.List;
+
 import org.apache.syncope.client.mod.UserMod;
 import org.apache.syncope.client.to.MembershipTO;
 import org.apache.syncope.client.to.SchemaTO;
@@ -30,12 +37,6 @@ import org.apache.syncope.client.validat
 import org.apache.syncope.types.EntityViolationType;
 import org.apache.syncope.types.SchemaType;
 import org.apache.syncope.types.SyncopeClientExceptionType;
-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 org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
@@ -45,6 +46,10 @@ import org.springframework.web.client.Ht
 @FixMethodOrder(MethodSorters.JVM)
 public class SchemaTestITCase extends AbstractTest {
 
+    private static final String ROLE = "role";
+    private static final String USER = "user";
+    private static final String MEMBERSHIP = "membership";
+
     @Test
     public void create() {
         SchemaTO schemaTO = new SchemaTO();
@@ -52,10 +57,10 @@ public class SchemaTestITCase extends Ab
         schemaTO.setMandatoryCondition("false");
         schemaTO.setType(SchemaType.String);
 
-        SchemaTO newSchemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create",
schemaTO, SchemaTO.class);
+        SchemaTO newSchemaTO = schemaService.create(USER, schemaTO);
         assertEquals(schemaTO, newSchemaTO);
 
-        newSchemaTO = restTemplate.postForObject(BASE_URL + "schema/membership/create", schemaTO,
SchemaTO.class);
+        newSchemaTO = schemaService.create(MEMBERSHIP, schemaTO);
         assertEquals(schemaTO, newSchemaTO);
     }
 
@@ -66,14 +71,15 @@ public class SchemaTestITCase extends Ab
         schemaTO.setType(SchemaType.String);
 
         try {
-            restTemplate.postForObject(BASE_URL + "schema/user/create", schemaTO, SchemaTO.class);
+            schemaService.create(USER, schemaTO);
             fail("This should not be reacheable");
         } catch (SyncopeClientCompositeErrorException scce) {
             SyncopeClientException sce = scce.getException(SyncopeClientExceptionType.InvalidUSchema);
 
             assertNotNull(sce.getElements());
             assertEquals(1, sce.getElements().size());
-            assertTrue(sce.getElements().iterator().next().contains(EntityViolationType.InvalidUSchema.name()));
+            assertTrue(sce.getElements().iterator().next()
+                    .contains(EntityViolationType.InvalidUSchema.name()));
         }
     }
 
@@ -84,15 +90,15 @@ public class SchemaTestITCase extends Ab
         schemaTO.setType(SchemaType.Enum);
 
         try {
-            restTemplate.postForObject(BASE_URL + "schema/role/create", schemaTO, SchemaTO.class);
+            schemaService.create(ROLE, schemaTO);
             fail("This should not be reacheable");
         } catch (SyncopeClientCompositeErrorException scce) {
             SyncopeClientException sce = scce.getException(SyncopeClientExceptionType.InvalidRSchema);
 
             assertNotNull(sce.getElements());
             assertEquals(1, sce.getElements().size());
-            assertTrue(sce.getElements().iterator().next().contains(
-                    EntityViolationType.InvalidSchemaTypeSpecification.name()));
+            assertTrue(sce.getElements().iterator().next()
+                    .contains(EntityViolationType.InvalidSchemaTypeSpecification.name()));
         }
     }
 
@@ -103,26 +109,25 @@ public class SchemaTestITCase extends Ab
         schemaTO.setType(SchemaType.Enum);
 
         try {
-            restTemplate.postForObject(BASE_URL + "schema/user/create", schemaTO, SchemaTO.class);
+            schemaService.create(USER, schemaTO);
             fail("This should not be reacheable");
         } catch (SyncopeClientCompositeErrorException scce) {
             SyncopeClientException sce = scce.getException(SyncopeClientExceptionType.InvalidUSchema);
 
             assertNotNull(sce.getElements());
             assertEquals(1, sce.getElements().size());
-            assertTrue(sce.getElements().iterator().next().contains(
-                    EntityViolationType.InvalidSchemaTypeSpecification.name()));
+            assertTrue(sce.getElements().iterator().next()
+                    .contains(EntityViolationType.InvalidSchemaTypeSpecification.name()));
         }
     }
 
     @Test
     public void delete() {
-        SchemaTO deletedSchema =
-                restTemplate.getForObject(BASE_URL + "schema/user/delete/cool.json", SchemaTO.class);
+        SchemaTO deletedSchema = schemaService.delete(USER, "cool", SchemaTO.class);
         assertNotNull(deletedSchema);
         SchemaTO firstname = null;
         try {
-            firstname = restTemplate.getForObject(BASE_URL + "schema/user/read/cool.json",
SchemaTO.class);
+            firstname = schemaService.read(USER, "cool", SchemaTO.class);
         } catch (HttpClientErrorException e) {
             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
         }
@@ -131,22 +136,19 @@ public class SchemaTestITCase extends Ab
 
     @Test
     public void list() {
-        List<SchemaTO> userSchemas = Arrays.asList(restTemplate.getForObject(BASE_URL
+ "schema/user/list.json",
-                SchemaTO[].class));
+        List<SchemaTO> userSchemas = schemaService.list(USER, SchemaTO[].class);
         assertFalse(userSchemas.isEmpty());
         for (SchemaTO schemaTO : userSchemas) {
             assertNotNull(schemaTO);
         }
 
-        List<SchemaTO> roleSchemas = Arrays.asList(restTemplate.getForObject(BASE_URL
+ "schema/role/list.json",
-                SchemaTO[].class));
+        List<SchemaTO> roleSchemas = schemaService.list(ROLE, SchemaTO[].class);
         assertFalse(roleSchemas.isEmpty());
         for (SchemaTO schemaTO : roleSchemas) {
             assertNotNull(schemaTO);
         }
 
-        List<SchemaTO> membershipSchemas = Arrays.asList(restTemplate.getForObject(BASE_URL
-                + "schema/membership/list.json", SchemaTO[].class));
+        List<SchemaTO> membershipSchemas = schemaService.list(MEMBERSHIP, SchemaTO[].class);
         assertFalse(membershipSchemas.isEmpty());
         for (SchemaTO schemaTO : membershipSchemas) {
             assertNotNull(schemaTO);
@@ -155,15 +157,15 @@ public class SchemaTestITCase extends Ab
 
     @Test
     public void update() {
-        SchemaTO schemaTO = restTemplate.getForObject(BASE_URL + "schema/role/read/icon.json",
SchemaTO.class);
+        SchemaTO schemaTO = schemaService.read(ROLE, "icon", SchemaTO.class);
         assertNotNull(schemaTO);
 
-        SchemaTO updatedTO = restTemplate.postForObject(BASE_URL + "schema/role/update",
schemaTO, SchemaTO.class);
+        SchemaTO updatedTO = schemaService.update(ROLE, schemaTO.getName(), schemaTO);
         assertEquals(schemaTO, updatedTO);
 
         updatedTO.setType(SchemaType.Date);
         try {
-            restTemplate.postForObject(BASE_URL + "schema/role/update", updatedTO, SchemaTO.class);
+            schemaService.update(ROLE, schemaTO.getName(), updatedTO);
             fail("This should not be reacheable");
         } catch (SyncopeClientCompositeErrorException scce) {
             SyncopeClientException sce = scce.getException(SyncopeClientExceptionType.InvalidRSchema);
@@ -177,18 +179,18 @@ public class SchemaTestITCase extends Ab
         schemaTO.setName("schema_issue258");
         schemaTO.setType(SchemaType.Double);
 
-        schemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create", schemaTO,
SchemaTO.class);
+        schemaTO = schemaService.create(USER, schemaTO);
         assertNotNull(schemaTO);
 
         UserTO userTO = UserTestITCase.getSampleTO("issue258@syncope.apache.org");
         userTO.addAttribute(attributeTO(schemaTO.getName(), "1.2"));
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+        userTO = userService.create(userTO);
         assertNotNull(userTO);
 
         schemaTO.setType(SchemaType.Long);
         try {
-            restTemplate.postForObject(BASE_URL + "schema/user/update", schemaTO, SchemaTO.class);
+            schemaService.update(USER, schemaTO.getName(), schemaTO);
             fail("This should not be reacheable");
         } catch (SyncopeClientCompositeErrorException scce) {
             SyncopeClientException sce = scce.getException(SyncopeClientExceptionType.InvalidUSchema);
@@ -203,12 +205,12 @@ public class SchemaTestITCase extends Ab
         schemaTO.setUniqueConstraint(true);
         schemaTO.setType(SchemaType.Long);
 
-        schemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create", schemaTO,
SchemaTO.class);
+        schemaTO = schemaService.create(USER, schemaTO);
         assertNotNull(schemaTO);
 
         UserTO userTO = UserTestITCase.getSampleTO("issue259@syncope.apache.org");
         userTO.addAttribute(attributeTO(schemaTO.getName(), "1"));
-        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+        userTO = userService.create(userTO);
         assertNotNull(userTO);
 
         UserTO newUserTO = AttributableOperations.clone(userTO);
@@ -218,7 +220,7 @@ public class SchemaTestITCase extends Ab
 
         UserMod userMod = AttributableOperations.diff(newUserTO, userTO);
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
+        userTO = userService.update(userMod.getId(), userMod);
         assertNotNull(userTO);
     }
 
@@ -229,17 +231,17 @@ public class SchemaTestITCase extends Ab
         schemaTO.setType(SchemaType.Double);
         schemaTO.setUniqueConstraint(true);
 
-        schemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create", schemaTO,
SchemaTO.class);
+        schemaTO = schemaService.create(USER, schemaTO);
         assertNotNull(schemaTO);
 
         UserTO userTO = UserTestITCase.getSampleTO("issue260@syncope.apache.org");
         userTO.addAttribute(attributeTO(schemaTO.getName(), "1.2"));
-        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+        userTO = userService.create(userTO);
         assertNotNull(userTO);
 
         schemaTO.setUniqueConstraint(false);
         try {
-            restTemplate.postForObject(BASE_URL + "schema/user/update", schemaTO, SchemaTO.class);
+            schemaService.update(USER, schemaTO.getName(), schemaTO);
             fail("This should not be reacheable");
         } catch (SyncopeClientCompositeErrorException scce) {
             SyncopeClientException sce = scce.getException(SyncopeClientExceptionType.InvalidUSchema);

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
(original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/VirtualSchemaTestITCase.java
Tue Jan  8 11:24:02 2013
@@ -18,10 +18,11 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 
-import java.util.Arrays;
 import java.util.List;
+
 import org.apache.syncope.client.to.VirtualSchemaTO;
 import org.apache.syncope.client.validation.SyncopeClientCompositeErrorException;
 import org.apache.syncope.types.SyncopeClientExceptionType;
@@ -32,10 +33,13 @@ import org.junit.runners.MethodSorters;
 @FixMethodOrder(MethodSorters.JVM)
 public class VirtualSchemaTestITCase extends AbstractTest {
 
+    private static final String ROLE = "role";
+    private static final String USER = "user";
+    private static final String MEMBERSHIP = "membership";
+
     @Test
     public void list() {
-        List<VirtualSchemaTO> VirtualSchemas = Arrays.asList(restTemplate.getForObject(BASE_URL
-                + "virtualSchema/user/list.json", VirtualSchemaTO[].class));
+        List<VirtualSchemaTO> VirtualSchemas = schemaService.list(USER, VirtualSchemaTO[].class);
         assertFalse(VirtualSchemas.isEmpty());
         for (VirtualSchemaTO VirtualSchemaTO : VirtualSchemas) {
             assertNotNull(VirtualSchemaTO);
@@ -44,8 +48,8 @@ public class VirtualSchemaTestITCase ext
 
     @Test
     public void read() {
-        VirtualSchemaTO VirtualSchemaTO = restTemplate.getForObject(BASE_URL
-                + "virtualSchema/membership/read/mvirtualdata.json", VirtualSchemaTO.class);
+        VirtualSchemaTO VirtualSchemaTO = schemaService.read(MEMBERSHIP, "mvirtualdata",
+                VirtualSchemaTO.class);
         assertNotNull(VirtualSchemaTO);
     }
 
@@ -54,30 +58,24 @@ public class VirtualSchemaTestITCase ext
         VirtualSchemaTO schema = new VirtualSchemaTO();
         schema.setName("virtual");
 
-        VirtualSchemaTO actual = restTemplate.postForObject(BASE_URL + "virtualSchema/user/create.json",
schema,
-                VirtualSchemaTO.class);
+        VirtualSchemaTO actual = schemaService.create(USER, schema);
         assertNotNull(actual);
 
-        actual = restTemplate.getForObject(BASE_URL + "virtualSchema/user/read/" + actual.getName()
+ ".json",
-                VirtualSchemaTO.class);
+        actual = schemaService.read(USER, actual.getName(), VirtualSchemaTO.class);
         assertNotNull(actual);
     }
 
     @Test
     public void delete() {
-        VirtualSchemaTO schema = restTemplate.getForObject(BASE_URL + "virtualSchema/role/read/rvirtualdata.json",
-                VirtualSchemaTO.class);
+        VirtualSchemaTO schema = schemaService.read(ROLE, "rvirtualdata", VirtualSchemaTO.class);
         assertNotNull(schema);
 
-        VirtualSchemaTO deletedSchema =
-                restTemplate.getForObject(BASE_URL + "virtualSchema/role/delete/{schema}",
VirtualSchemaTO.class,
-                schema.getName());
+        VirtualSchemaTO deletedSchema = schemaService.delete(ROLE, schema.getName(), VirtualSchemaTO.class);
         assertNotNull(deletedSchema);
 
         Throwable t = null;
         try {
-            schema = restTemplate.getForObject(BASE_URL + "virtualSchema/role/read/rvirtualdata.json",
-                    VirtualSchemaTO.class);
+            schema = schemaService.read(ROLE, "rvirtualdata", VirtualSchemaTO.class);
         } catch (SyncopeClientCompositeErrorException e) {
             t = e;
             assertNotNull(e.getException(SyncopeClientExceptionType.NotFound));

Modified: syncope/trunk/core/src/test/resources/restClientContext.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/resources/restClientContext.xml?rev=1430219&r1=1430218&r2=1430219&view=diff
==============================================================================
--- syncope/trunk/core/src/test/resources/restClientContext.xml (original)
+++ syncope/trunk/core/src/test/resources/restClientContext.xml Tue Jan  8 11:24:02 2013
@@ -42,7 +42,7 @@ under the License.
   
   <bean id="httpClientFactory" class="org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory">
     <constructor-arg value="localhost"/>
-    <constructor-arg value="9080"/>
+    <constructor-arg value="9081"/>
     <constructor-arg value="http"/>
     <constructor-arg ref="httpClientConnManager"/>
     <constructor-arg ref="httpClientParams"/>



Mime
View raw message