You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2015/01/12 17:31:56 UTC

[17/52] [abbrv] [partial] syncope git commit: [SYNCOPE-620] Unit tests all in

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/RoleTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/RoleTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/RoleTest.java
deleted file mode 100644
index 9eddc6e..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/RoleTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.persistence.jpa.relationship;
-
-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 java.util.List;
-import org.apache.syncope.persistence.api.attrvalue.validation.InvalidEntityException;
-import org.apache.syncope.persistence.api.dao.EntitlementDAO;
-import org.apache.syncope.persistence.api.dao.PlainAttrDAO;
-import org.apache.syncope.persistence.api.dao.PlainAttrValueDAO;
-import org.apache.syncope.persistence.api.dao.PlainSchemaDAO;
-import org.apache.syncope.persistence.api.dao.PolicyDAO;
-import org.apache.syncope.persistence.api.dao.RoleDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.entity.PasswordPolicy;
-import org.apache.syncope.persistence.api.entity.role.RPlainAttr;
-import org.apache.syncope.persistence.api.entity.role.RPlainAttrValue;
-import org.apache.syncope.persistence.api.entity.role.RPlainSchema;
-import org.apache.syncope.persistence.api.entity.role.Role;
-import org.apache.syncope.persistence.api.entity.user.User;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class RoleTest extends AbstractTest {
-
-    @Autowired
-    private UserDAO userDAO;
-
-    @Autowired
-    private RoleDAO roleDAO;
-
-    @Autowired
-    private PlainSchemaDAO plainSchemaDAO;
-
-    @Autowired
-    private PlainAttrDAO plainAttrDAO;
-
-    @Autowired
-    private PlainAttrValueDAO plainAttrValueDAO;
-
-    @Autowired
-    private EntitlementDAO entitlementDAO;
-
-    @Autowired
-    private PolicyDAO policyDAO;
-
-    @Test(expected = InvalidEntityException.class)
-    public void saveWithTwoOwners() {
-        Role root = roleDAO.find("root", null);
-        assertNotNull("did not find expected role", root);
-
-        User user = userDAO.find(1L);
-        assertNotNull("did not find expected user", user);
-
-        Role role = entityFactory.newEntity(Role.class);
-        role.setName("error");
-        role.setUserOwner(user);
-        role.setRoleOwner(root);
-
-        roleDAO.save(role);
-    }
-
-    @Test
-    public void findByOwner() {
-        Role role = roleDAO.find(6L);
-        assertNotNull("did not find expected role", role);
-
-        User user = userDAO.find(5L);
-        assertNotNull("did not find expected user", user);
-
-        assertEquals(user, role.getUserOwner());
-
-        Role child1 = roleDAO.find(7L);
-        assertNotNull(child1);
-        assertEquals(role, child1.getParent());
-
-        Role child2 = roleDAO.find(10L);
-        assertNotNull(child2);
-        assertEquals(role, child2.getParent());
-
-        List<Role> ownedRoles = roleDAO.findOwnedByUser(user.getKey());
-        assertFalse(ownedRoles.isEmpty());
-        assertEquals(2, ownedRoles.size());
-        assertTrue(ownedRoles.contains(role));
-        assertTrue(ownedRoles.contains(child1));
-        assertFalse(ownedRoles.contains(child2));
-    }
-
-    public void createWithPasswordPolicy() {
-        PasswordPolicy policy = (PasswordPolicy) policyDAO.find(4L);
-        Role role = entityFactory.newEntity(Role.class);
-        role.setName("roleWithPasswordPolicy");
-        role.setPasswordPolicy(policy);
-
-        Role actual = roleDAO.save(role);
-        assertNotNull(actual);
-
-        actual = roleDAO.find(actual.getKey());
-        assertNotNull(actual);
-        assertNotNull(actual.getPasswordPolicy());
-
-        roleDAO.delete(actual.getKey());
-        assertNull(roleDAO.find(actual.getKey()));
-
-        assertNotNull(policyDAO.find(4L));
-    }
-
-    @Test
-    public void delete() {
-        roleDAO.delete(2L);
-
-        roleDAO.flush();
-
-        assertNull(roleDAO.find(2L));
-        assertEquals(1, roleDAO.findByEntitlement(entitlementDAO.find("base")).size());
-        assertEquals(userDAO.find(2L).getRoles().size(), 2);
-        assertNull(plainAttrDAO.find(700L, RPlainAttr.class));
-        assertNull(plainAttrValueDAO.find(41L, RPlainAttrValue.class));
-        assertNotNull(plainSchemaDAO.find("icon", RPlainSchema.class));
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/SecurityQuestionTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/SecurityQuestionTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/SecurityQuestionTest.java
deleted file mode 100644
index e4231b7..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/SecurityQuestionTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.persistence.jpa.relationship;
-
-import static org.junit.Assert.assertNull;
-
-import org.apache.syncope.persistence.api.dao.SecurityQuestionDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.entity.user.User;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class SecurityQuestionTest extends AbstractTest {
-
-    @Autowired
-    private SecurityQuestionDAO securityQuestionDAO;
-
-    @Autowired
-    private UserDAO userDAO;
-
-    @Test
-    public void test() {
-        User user = userDAO.find(4L);
-        assertNull(user.getSecurityQuestion());
-        assertNull(user.getSecurityAnswer());
-
-        user.setSecurityQuestion(securityQuestionDAO.find(1L));
-        user.setSecurityAnswer("Rossi");
-        userDAO.save(user);
-
-        userDAO.flush();
-
-        securityQuestionDAO.delete(1L);
-
-        userDAO.flush();
-
-        user = userDAO.find(4L);
-
-        assertNull(user.getSecurityQuestion());
-        assertNull(user.getSecurityAnswer());
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/TaskTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/TaskTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/TaskTest.java
deleted file mode 100644
index 27ffb1e..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/TaskTest.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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.persistence.jpa.relationship;
-
-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 java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-import org.apache.syncope.common.lib.types.AttributableType;
-import org.apache.syncope.common.lib.types.PropagationMode;
-import org.apache.syncope.common.lib.types.PropagationTaskExecStatus;
-import org.apache.syncope.common.lib.types.ResourceOperation;
-import org.apache.syncope.common.lib.types.TaskType;
-import org.apache.syncope.persistence.api.dao.ExternalResourceDAO;
-import org.apache.syncope.persistence.api.dao.TaskDAO;
-import org.apache.syncope.persistence.api.dao.TaskExecDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.entity.ExternalResource;
-import org.apache.syncope.persistence.api.entity.task.PropagationTask;
-import org.apache.syncope.persistence.api.entity.task.PushTask;
-import org.apache.syncope.persistence.api.entity.task.SyncTask;
-import org.apache.syncope.persistence.api.entity.task.TaskExec;
-import org.apache.syncope.persistence.api.entity.user.User;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.identityconnectors.framework.common.objects.Attribute;
-import org.identityconnectors.framework.common.objects.AttributeBuilder;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class TaskTest extends AbstractTest {
-
-    @Autowired
-    private TaskDAO taskDAO;
-
-    @Autowired
-    private TaskExecDAO taskExecDAO;
-
-    @Autowired
-    private ExternalResourceDAO resourceDAO;
-
-    @Autowired
-    private UserDAO userDAO;
-
-    @Test
-    public void read() {
-        PropagationTask task = taskDAO.find(1L);
-        assertNotNull(task);
-
-        assertNotNull(task.getExecs());
-        assertFalse(task.getExecs().isEmpty());
-        assertEquals(1, task.getExecs().size());
-    }
-
-    @Test
-    public void save() {
-        ExternalResource resource = resourceDAO.find("ws-target-resource-1");
-        assertNotNull(resource);
-
-        User user = userDAO.find(2L);
-        assertNotNull(user);
-
-        PropagationTask task = entityFactory.newEntity(PropagationTask.class);
-        task.setResource(resource);
-        task.setSubjectType(AttributableType.USER);
-        task.setPropagationMode(PropagationMode.TWO_PHASES);
-        task.setPropagationOperation(ResourceOperation.CREATE);
-        task.setAccountId("one@two.com");
-
-        Set<Attribute> attributes = new HashSet<>();
-        attributes.add(AttributeBuilder.build("testAttribute", "testValue1", "testValue2"));
-        attributes.add(AttributeBuilder.buildPassword("password".toCharArray()));
-        task.setAttributes(attributes);
-
-        task = taskDAO.save(task);
-        assertNotNull(task);
-
-        PropagationTask actual = taskDAO.find(task.getKey());
-        assertEquals(task, actual);
-
-        taskDAO.flush();
-
-        resource = resourceDAO.find("ws-target-resource-1");
-        assertTrue(taskDAO.findAll(resource, TaskType.PROPAGATION).contains(task));
-    }
-
-    @Test
-    public void addPropagationTaskExecution() {
-        PropagationTask task = taskDAO.find(1L);
-        assertNotNull(task);
-
-        int executionNumber = task.getExecs().size();
-
-        TaskExec execution = entityFactory.newEntity(TaskExec.class);
-        execution.setTask(task);
-        execution.setStatus(PropagationTaskExecStatus.CREATED.name());
-        task.addExec(execution);
-        execution.setStartDate(new Date());
-
-        taskDAO.save(task);
-        taskDAO.flush();
-
-        task = taskDAO.find(1L);
-        assertNotNull(task);
-
-        assertEquals(executionNumber + 1, task.getExecs().size());
-    }
-
-    @Test
-    public void addSyncTaskExecution() {
-        SyncTask task = taskDAO.find(4L);
-        assertNotNull(task);
-
-        int executionNumber = task.getExecs().size();
-
-        TaskExec execution = entityFactory.newEntity(TaskExec.class);
-        execution.setStatus("Text-free status");
-        execution.setTask(task);
-        task.addExec(execution);
-        execution.setMessage("A message");
-
-        taskDAO.save(task);
-        taskDAO.flush();
-
-        task = taskDAO.find(4L);
-        assertNotNull(task);
-
-        assertEquals(executionNumber + 1, task.getExecs().size());
-    }
-
-    @Test
-    public void addPushTaskExecution() {
-        PushTask task = taskDAO.find(13L);
-        assertNotNull(task);
-
-        int executionNumber = task.getExecs().size();
-
-        TaskExec execution = entityFactory.newEntity(TaskExec.class);
-        execution.setStatus("Text-free status");
-        execution.setTask(task);
-        task.addExec(execution);
-        execution.setMessage("A message");
-
-        taskDAO.save(task);
-        taskDAO.flush();
-
-        task = taskDAO.find(13L);
-        assertNotNull(task);
-
-        assertEquals(executionNumber + 1, task.getExecs().size());
-    }
-
-    @Test
-    public void deleteTask() {
-        taskDAO.delete(1L);
-
-        taskDAO.flush();
-
-        assertNull(taskDAO.find(1L));
-        assertNull(taskExecDAO.find(1L));
-    }
-
-    @Test
-    public void deleteTaskExecution() {
-        TaskExec execution = taskExecDAO.find(1L);
-        int executionNumber = execution.getTask().getExecs().size();
-
-        taskExecDAO.delete(1L);
-
-        taskExecDAO.flush();
-
-        assertNull(taskExecDAO.find(1L));
-
-        PropagationTask task = taskDAO.find(1L);
-        assertEquals(task.getExecs().size(), executionNumber - 1);
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/UserTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/UserTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/UserTest.java
deleted file mode 100644
index bc1dad4..0000000
--- a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/persistence/jpa/relationship/UserTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.persistence.jpa.relationship;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import org.apache.syncope.persistence.api.dao.PlainAttrDAO;
-import org.apache.syncope.persistence.api.dao.PlainAttrValueDAO;
-import org.apache.syncope.persistence.api.dao.PlainSchemaDAO;
-import org.apache.syncope.persistence.api.dao.RoleDAO;
-import org.apache.syncope.persistence.api.dao.UserDAO;
-import org.apache.syncope.persistence.api.entity.membership.Membership;
-import org.apache.syncope.persistence.api.entity.user.UPlainAttr;
-import org.apache.syncope.persistence.api.entity.user.UPlainAttrValue;
-import org.apache.syncope.persistence.api.entity.user.UPlainSchema;
-import org.apache.syncope.persistence.jpa.AbstractTest;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-
-@Transactional
-public class UserTest extends AbstractTest {
-
-    @Autowired
-    private UserDAO userDAO;
-
-    @Autowired
-    private RoleDAO roleDAO;
-
-    @Autowired
-    private PlainSchemaDAO plainSchemaDAO;
-
-    @Autowired
-    private PlainAttrDAO plainAttrDAO;
-
-    @Autowired
-    private PlainAttrValueDAO plainAttrValueDAO;
-
-    @Test
-    public void test() {
-        userDAO.delete(4L);
-
-        userDAO.flush();
-
-        assertNull(userDAO.find(4L));
-        assertNull(plainAttrDAO.find(550L, UPlainAttr.class));
-        assertNull(plainAttrValueDAO.find(22L, UPlainAttrValue.class));
-        assertNotNull(plainSchemaDAO.find("loginDate", UPlainSchema.class));
-
-        List<Membership> memberships = roleDAO.findMemberships(roleDAO.find(7L));
-        assertTrue(memberships.isEmpty());
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/AbstractTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/AbstractTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/AbstractTest.java
new file mode 100644
index 0000000..a05a794
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/AbstractTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.server.persistence.jpa;
+
+import org.apache.syncope.server.persistence.api.entity.AttributableUtilFactory;
+import org.apache.syncope.server.persistence.api.entity.EntityFactory;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:persistenceTest.xml" })
+public abstract class AbstractTest {
+
+    @Autowired
+    protected EntityFactory entityFactory;
+
+    @Autowired
+    protected AttributableUtilFactory attrUtilFactory;
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/DummyConnectorRegistry.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/DummyConnectorRegistry.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/DummyConnectorRegistry.java
new file mode 100644
index 0000000..16c2a9d
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/DummyConnectorRegistry.java
@@ -0,0 +1,47 @@
+/*
+ * 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.server.persistence.jpa;
+
+import java.util.Set;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.server.persistence.api.dao.NotFoundException;
+import org.apache.syncope.server.persistence.api.entity.ConnInstance;
+import org.apache.syncope.server.persistence.api.entity.ExternalResource;
+import org.apache.syncope.server.provisioning.api.ConnectorRegistry;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DummyConnectorRegistry implements ConnectorRegistry {
+
+    @Override
+    public ConnInstance getOverriddenConnInstance(
+            final ConnInstance connInstance, final Set<ConnConfProperty> overridden) {
+
+        return connInstance;
+    }
+
+    @Override
+    public void registerConnector(final ExternalResource resource)
+            throws NotFoundException {
+    }
+
+    @Override
+    public void unregisterConnector(final String id) {
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/TestInitializer.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/TestInitializer.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/TestInitializer.java
new file mode 100644
index 0000000..0a2c238
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/TestInitializer.java
@@ -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.server.persistence.jpa;
+
+import org.apache.syncope.server.persistence.api.content.ContentLoader;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class TestInitializer implements InitializingBean {
+
+    @Autowired
+    private ContentLoader contentLoader;
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        contentLoader.load();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttrTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttrTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttrTest.java
new file mode 100644
index 0000000..35e21e5
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttrTest.java
@@ -0,0 +1,235 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+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.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Random;
+import javax.validation.ValidationException;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.server.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.server.persistence.api.dao.PlainAttrDAO;
+import org.apache.syncope.server.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.server.persistence.api.dao.UserDAO;
+import org.apache.syncope.server.persistence.api.entity.user.UPlainAttr;
+import org.apache.syncope.server.persistence.api.entity.user.UPlainAttrUniqueValue;
+import org.apache.syncope.server.persistence.api.entity.user.UPlainSchema;
+import org.apache.syncope.server.persistence.api.entity.user.User;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.apache.syncope.server.misc.security.Encryptor;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.crypto.codec.Base64;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class AttrTest extends AbstractTest {
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Autowired
+    private PlainAttrDAO plainAttrDAO;
+
+    @Autowired
+    private PlainSchemaDAO userSchemaDAO;
+
+    @Test
+    public void findById() {
+        UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class);
+        assertNotNull("did not find expected attribute schema", attribute);
+        attribute = plainAttrDAO.find(104L, UPlainAttr.class);
+        assertNotNull("did not find expected attribute schema", attribute);
+    }
+
+    @Test
+    public void read() {
+        UPlainAttr attribute = plainAttrDAO.find(100L, UPlainAttr.class);
+        assertNotNull(attribute);
+        assertTrue(attribute.getValues().isEmpty());
+        assertNotNull(attribute.getUniqueValue());
+    }
+
+    @Test
+    public void save() throws ClassNotFoundException {
+        User user = userDAO.find(1L);
+
+        UPlainSchema emailSchema = userSchemaDAO.find("email", UPlainSchema.class);
+        assertNotNull(emailSchema);
+
+        UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+        attribute.setSchema(emailSchema);
+        attribute.setOwner(user);
+
+        Exception thrown = null;
+        try {
+            attribute.addValue("john.doe@gmail.com", attrUtilFactory.getInstance(AttributableType.USER));
+            attribute.addValue("mario.rossi@gmail.com", attrUtilFactory.getInstance(AttributableType.USER));
+        } catch (ValidationException e) {
+            thrown = e;
+        }
+        assertNull("no validation exception expected here ", thrown);
+
+        try {
+            attribute.addValue("http://www.apache.org", attrUtilFactory.getInstance(AttributableType.USER));
+        } catch (ValidationException e) {
+            thrown = e;
+        }
+        assertNotNull("validation exception expected here ", thrown);
+    }
+
+    @Test
+    public void saveWithEnum() throws ClassNotFoundException {
+        User user = userDAO.find(1L);
+
+        UPlainSchema gender = userSchemaDAO.find("gender", UPlainSchema.class);
+        assertNotNull(gender);
+        assertNotNull(gender.getType());
+        assertNotNull(gender.getEnumerationValues());
+
+        UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+        attribute.setSchema(gender);
+        attribute.setOwner(user);
+        user.addPlainAttr(attribute);
+
+        Exception thrown = null;
+
+        try {
+            attribute.addValue("A", attrUtilFactory.getInstance(AttributableType.USER));
+        } catch (ValidationException e) {
+            thrown = e;
+        }
+        assertNotNull("validation exception expected here ", thrown);
+
+        attribute.addValue("M", attrUtilFactory.getInstance(AttributableType.USER));
+
+        InvalidEntityException iee = null;
+        try {
+            userDAO.save(user);
+        } catch (InvalidEntityException e) {
+            iee = e;
+        }
+        assertNull(iee);
+    }
+
+    @Test
+    public void validateAndSave() {
+        User user = userDAO.find(1L);
+
+        final UPlainSchema emailSchema = userSchemaDAO.find("email", UPlainSchema.class);
+        assertNotNull(emailSchema);
+
+        final UPlainSchema fullnameSchema = userSchemaDAO.find("fullname", UPlainSchema.class);
+        assertNotNull(fullnameSchema);
+
+        UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+        attribute.setSchema(emailSchema);
+
+        UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class);
+        uauv.setAttr(attribute);
+        uauv.setSchema(fullnameSchema);
+        uauv.setStringValue("a value");
+
+        attribute.setUniqueValue(uauv);
+
+        user.addPlainAttr(attribute);
+
+        InvalidEntityException iee = null;
+        try {
+            userDAO.save(user);
+            fail();
+        } catch (InvalidEntityException e) {
+            iee = e;
+        }
+        assertNotNull(iee);
+        // for attribute
+        assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList));
+        // for uauv
+        assertTrue(iee.hasViolation(EntityViolationType.InvalidUPlainSchema));
+    }
+
+    @Test
+    public void saveWithEncrypted() throws Exception {
+        User user = userDAO.find(1L);
+
+        final UPlainSchema obscureSchema = userSchemaDAO.find("obscure", UPlainSchema.class);
+        assertNotNull(obscureSchema);
+        assertNotNull(obscureSchema.getSecretKey());
+        assertNotNull(obscureSchema.getCipherAlgorithm());
+
+        UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+        attribute.setSchema(obscureSchema);
+        attribute.addValue("testvalue", attrUtilFactory.getInstance(AttributableType.USER));
+        attribute.setOwner(user);
+        user.addPlainAttr(attribute);
+
+        userDAO.save(user);
+
+        UPlainAttr obscure = user.getPlainAttr("obscure");
+        assertNotNull(obscure);
+        assertEquals(1, obscure.getValues().size());
+        assertEquals(Encryptor.getInstance(obscureSchema.getSecretKey()).
+                encode("testvalue", obscureSchema.getCipherAlgorithm()), obscure.getValues().get(0).getStringValue());
+    }
+
+    @Test
+    public void saveWithBinary() throws UnsupportedEncodingException {
+        User user = userDAO.find(1L);
+
+        final UPlainSchema photoSchema = userSchemaDAO.find("photo", UPlainSchema.class);
+        assertNotNull(photoSchema);
+        assertNotNull(photoSchema.getMimeType());
+
+        final byte[] bytes = new byte[20];
+        new Random().nextBytes(bytes);
+        final String photoB64Value = new String(Base64.encode(bytes), SyncopeConstants.DEFAULT_ENCODING);
+
+        UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+        attribute.setSchema(photoSchema);
+        attribute.addValue(photoB64Value, attrUtilFactory.getInstance(AttributableType.USER));
+        attribute.setOwner(user);
+        user.addPlainAttr(attribute);
+
+        userDAO.save(user);
+
+        UPlainAttr obscure = user.getPlainAttr("photo");
+        assertNotNull(obscure);
+        assertEquals(1, obscure.getValues().size());
+        assertTrue(Arrays.equals(bytes, obscure.getValues().get(0).getBinaryValue()));
+    }
+
+    @Test
+    public void delete() {
+        UPlainAttr attribute = plainAttrDAO.find(104L, UPlainAttr.class);
+        String attrSchemaName = attribute.getSchema().getKey();
+
+        plainAttrDAO.delete(attribute.getKey(), UPlainAttr.class);
+
+        UPlainSchema schema = userSchemaDAO.find(attrSchemaName, UPlainSchema.class);
+        assertNotNull("user attribute schema deleted when deleting values", schema);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttributableSearchTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttributableSearchTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttributableSearchTest.java
new file mode 100644
index 0000000..4b6345b
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/AttributableSearchTest.java
@@ -0,0 +1,480 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.syncope.common.lib.types.SubjectType;
+import org.apache.syncope.server.persistence.api.RoleEntitlementUtil;
+import org.apache.syncope.server.persistence.api.dao.EntitlementDAO;
+import org.apache.syncope.server.persistence.api.dao.RoleDAO;
+import org.apache.syncope.server.persistence.api.dao.SubjectSearchDAO;
+import org.apache.syncope.server.persistence.api.dao.UserDAO;
+import org.apache.syncope.server.persistence.api.dao.search.AttributeCond;
+import org.apache.syncope.server.persistence.api.dao.search.MembershipCond;
+import org.apache.syncope.server.persistence.api.dao.search.OrderByClause;
+import org.apache.syncope.server.persistence.api.dao.search.ResourceCond;
+import org.apache.syncope.server.persistence.api.dao.search.SearchCond;
+import org.apache.syncope.server.persistence.api.dao.search.SubjectCond;
+import org.apache.syncope.server.persistence.api.entity.role.Role;
+import org.apache.syncope.server.persistence.api.entity.user.User;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class AttributableSearchTest extends AbstractTest {
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Autowired
+    private RoleDAO roleDAO;
+
+    @Autowired
+    private SubjectSearchDAO searchDAO;
+
+    @Autowired
+    private EntitlementDAO entitlementDAO;
+
+    @Test
+    public void userMatch() {
+        User user = userDAO.find(1L);
+        assertNotNull(user);
+
+        MembershipCond membershipCond = new MembershipCond();
+        membershipCond.setRoleId(5L);
+
+        assertFalse(searchDAO.matches(user, SearchCond.getLeafCond(membershipCond), SubjectType.USER));
+
+        membershipCond.setRoleId(1L);
+
+        assertTrue(searchDAO.matches(user, SearchCond.getLeafCond(membershipCond), SubjectType.USER));
+    }
+
+    @Test
+    public void roleMatch() {
+        Role role = roleDAO.find(1L);
+        assertNotNull(role);
+
+        AttributeCond attrCond = new AttributeCond();
+        attrCond.setSchema("show");
+        attrCond.setType(AttributeCond.Type.ISNOTNULL);
+
+        assertTrue(searchDAO.matches(role, SearchCond.getLeafCond(attrCond), SubjectType.ROLE));
+    }
+
+    @Test
+    public void searchWithLikeCondition() {
+        AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
+        fullnameLeafCond.setSchema("fullname");
+        fullnameLeafCond.setExpression("%o%");
+
+        MembershipCond membershipCond = new MembershipCond();
+        membershipCond.setRoleId(1L);
+
+        AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
+        loginDateCond.setSchema("loginDate");
+        loginDateCond.setExpression("2009-05-26");
+
+        SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(
+                membershipCond));
+
+        assertTrue(subCond.isValid());
+
+        SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
+
+        assertTrue(cond.isValid());
+
+        List<User> users =
+                searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(1, users.size());
+    }
+
+    @Test
+    public void searchWithNotCondition() {
+        AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.EQ);
+        fullnameLeafCond.setSchema("fullname");
+        fullnameLeafCond.setExpression("Giuseppe Verdi");
+
+        SearchCond cond = SearchCond.getNotLeafCond(fullnameLeafCond);
+        assertTrue(cond.isValid());
+
+        List<User> users =
+                searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(4, users.size());
+
+        Set<Long> ids = new HashSet<Long>(users.size());
+        for (User user : users) {
+            ids.add(user.getKey());
+        }
+        assertTrue(ids.contains(1L));
+        assertTrue(ids.contains(3L));
+    }
+
+    @Test
+    public void searchByBoolean() {
+        AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.EQ);
+        coolLeafCond.setSchema("cool");
+        coolLeafCond.setExpression("true");
+
+        SearchCond cond = SearchCond.getLeafCond(coolLeafCond);
+        assertTrue(cond.isValid());
+
+        List<User> users =
+                searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), cond, SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(1, users.size());
+
+        assertEquals(Long.valueOf(4L), users.get(0).getKey());
+    }
+
+    @Test
+    public void searchByPageAndSize() {
+        AttributeCond fullnameLeafCond = new AttributeCond(AttributeCond.Type.LIKE);
+        fullnameLeafCond.setSchema("fullname");
+        fullnameLeafCond.setExpression("%o%");
+
+        MembershipCond membershipCond = new MembershipCond();
+        membershipCond.setRoleId(1L);
+
+        AttributeCond loginDateCond = new AttributeCond(AttributeCond.Type.EQ);
+        loginDateCond.setSchema("loginDate");
+        loginDateCond.setExpression("2009-05-26");
+
+        SearchCond subCond = SearchCond.getAndCond(SearchCond.getLeafCond(fullnameLeafCond), SearchCond.getLeafCond(
+                membershipCond));
+
+        assertTrue(subCond.isValid());
+
+        SearchCond cond = SearchCond.getAndCond(subCond, SearchCond.getLeafCond(loginDateCond));
+
+        assertTrue(cond.isValid());
+
+        List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                cond, 1, 2, Collections.<OrderByClause>emptyList(),
+                SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(1, users.size());
+
+        users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                cond, 2, 2, Collections.<OrderByClause>emptyList(),
+                SubjectType.USER);
+        assertNotNull(users);
+        assertTrue(users.isEmpty());
+    }
+
+    @Test
+    public void searchByMembership() {
+        MembershipCond membershipCond = new MembershipCond();
+        membershipCond.setRoleId(1L);
+
+        List<User> users = searchDAO.search(
+                RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(membershipCond),
+                SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(2, users.size());
+
+        membershipCond = new MembershipCond();
+        membershipCond.setRoleId(5L);
+
+        users = searchDAO.search(
+                RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getNotLeafCond(membershipCond),
+                SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(5, users.size());
+    }
+
+    @Test
+    public void searchByIsNull() {
+        AttributeCond coolLeafCond = new AttributeCond(AttributeCond.Type.ISNULL);
+        coolLeafCond.setSchema("cool");
+
+        List<User> users = searchDAO.search(
+                RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(coolLeafCond),
+                SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(4, users.size());
+
+        coolLeafCond = new AttributeCond(AttributeCond.Type.ISNOTNULL);
+        coolLeafCond.setSchema("cool");
+
+        users = searchDAO.search(
+                RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), SearchCond.getLeafCond(coolLeafCond),
+                SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(1, users.size());
+    }
+
+    @Test
+    public void searchByResource() {
+        ResourceCond ws2 = new ResourceCond();
+        ws2.setResourceName("ws-target-resource-2");
+
+        ResourceCond ws1 = new ResourceCond();
+        ws1.setResourceName("ws-target-resource-list-mappings-2");
+
+        SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getNotLeafCond(ws2), SearchCond.getLeafCond(ws1));
+
+        assertTrue(searchCondition.isValid());
+
+        List<User> users = searchDAO.search(
+                RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+                SubjectType.USER);
+
+        assertNotNull(users);
+        assertEquals(1, users.size());
+    }
+
+    @Test
+    public void searchByUsernameAndId() {
+        SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+        usernameLeafCond.setSchema("username");
+        usernameLeafCond.setExpression("rossini");
+
+        SubjectCond idRightCond = new SubjectCond(SubjectCond.Type.LT);
+        idRightCond.setSchema("id");
+        idRightCond.setExpression("2");
+
+        SearchCond searchCondition = SearchCond.getOrCond(SearchCond.getLeafCond(usernameLeafCond),
+                SearchCond.getLeafCond(idRightCond));
+
+        List<User> matchingUsers = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.USER);
+
+        assertNotNull(matchingUsers);
+        assertEquals(1, matchingUsers.size());
+        assertEquals("rossini", matchingUsers.iterator().next().getUsername());
+        assertEquals(1L, matchingUsers.iterator().next().getKey().longValue());
+    }
+
+    @Test
+    public void searchByRolenameAndId() {
+        SubjectCond rolenameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+        rolenameLeafCond.setSchema("name");
+        rolenameLeafCond.setExpression("root");
+
+        SubjectCond idRightCond = new SubjectCond(SubjectCond.Type.LT);
+        idRightCond.setSchema("id");
+        idRightCond.setExpression("2");
+
+        SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(rolenameLeafCond),
+                SearchCond.getLeafCond(idRightCond));
+
+        assertTrue(searchCondition.isValid());
+
+        List<Role> matchingRoles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.ROLE);
+
+        assertNotNull(matchingRoles);
+        assertEquals(1, matchingRoles.size());
+        assertEquals("root", matchingRoles.iterator().next().getName());
+        assertEquals(1L, matchingRoles.iterator().next().getKey().longValue());
+    }
+
+    @Test
+    public void searchByUsernameAndFullname() {
+        SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+        usernameLeafCond.setSchema("username");
+        usernameLeafCond.setExpression("rossini");
+
+        AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
+        idRightCond.setSchema("fullname");
+        idRightCond.setExpression("Giuseppe V%");
+
+        SearchCond searchCondition = SearchCond.getOrCond(SearchCond.getLeafCond(usernameLeafCond),
+                SearchCond.getLeafCond(idRightCond));
+
+        List<User> matchingUsers =
+                searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+                        SubjectType.USER);
+
+        assertNotNull(matchingUsers);
+        assertEquals(2, matchingUsers.size());
+    }
+
+    @Test
+    public void searchById() {
+        SubjectCond idLeafCond = new SubjectCond(SubjectCond.Type.LT);
+        idLeafCond.setSchema("id");
+        idLeafCond.setExpression("2");
+
+        SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
+        assertTrue(searchCondition.isValid());
+
+        List<User> users =
+                searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+                        SubjectType.USER);
+
+        assertNotNull(users);
+        assertEquals(1, users.size());
+        assertEquals(1L, users.iterator().next().getKey().longValue());
+
+        idLeafCond = new SubjectCond(SubjectCond.Type.LT);
+        idLeafCond.setSchema("id");
+        idLeafCond.setExpression("4");
+
+        searchCondition = SearchCond.getNotLeafCond(idLeafCond);
+        assertTrue(searchCondition.isValid());
+
+        users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCondition,
+                SubjectType.USER);
+
+        assertNotNull(users);
+        assertEquals(2, users.size());
+        boolean found = false;
+        for (User user : users) {
+            if (user.getKey() == 4) {
+                found = true;
+            }
+        }
+        assertTrue(found);
+    }
+
+    @Test
+    public void userOrderBy() {
+        SubjectCond usernameLeafCond = new SubjectCond(SubjectCond.Type.EQ);
+        usernameLeafCond.setSchema("username");
+        usernameLeafCond.setExpression("rossini");
+        AttributeCond idRightCond = new AttributeCond(AttributeCond.Type.LIKE);
+        idRightCond.setSchema("fullname");
+        idRightCond.setExpression("Giuseppe V%");
+        SearchCond searchCondition = SearchCond.getOrCond(
+                SearchCond.getLeafCond(usernameLeafCond), SearchCond.getLeafCond(idRightCond));
+
+        List<OrderByClause> orderByClauses = new ArrayList<OrderByClause>();
+        OrderByClause orderByClause = new OrderByClause();
+        orderByClause.setField("username");
+        orderByClause.setDirection(OrderByClause.Direction.DESC);
+        orderByClauses.add(orderByClause);
+        orderByClause = new OrderByClause();
+        orderByClause.setField("fullname");
+        orderByClause.setDirection(OrderByClause.Direction.ASC);
+        orderByClauses.add(orderByClause);
+
+        List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, Collections.singletonList(orderByClause),
+                SubjectType.USER);
+        assertEquals(searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.USER),
+                users.size());
+    }
+
+    @Test
+    public void roleOrderBy() {
+        SubjectCond idLeafCond = new SubjectCond(SubjectCond.Type.LIKE);
+        idLeafCond.setSchema("name");
+        idLeafCond.setExpression("%r");
+        SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
+        assertTrue(searchCondition.isValid());
+
+        OrderByClause orderByClause = new OrderByClause();
+        orderByClause.setField("name");
+
+        List<Role> roles = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, Collections.singletonList(orderByClause), SubjectType.ROLE);
+        assertEquals(searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.ROLE),
+                roles.size());
+    }
+
+    @Test
+    public void issue202() {
+        ResourceCond ws2 = new ResourceCond();
+        ws2.setResourceName("ws-target-resource-2");
+
+        ResourceCond ws1 = new ResourceCond();
+        ws1.setResourceName("ws-target-resource-list-mappings-1");
+
+        SearchCond searchCondition =
+                SearchCond.getAndCond(SearchCond.getNotLeafCond(ws2), SearchCond.getNotLeafCond(ws1));
+        assertTrue(searchCondition.isValid());
+
+        List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(2, users.size());
+        boolean found = false;
+        for (User user : users) {
+            if (user.getKey() == 4) {
+                found = true;
+            }
+        }
+        assertTrue(found);
+    }
+
+    @Test
+    public void issue242() {
+        SubjectCond cond = new SubjectCond(AttributeCond.Type.LIKE);
+        cond.setSchema("id");
+        cond.setExpression("test%");
+
+        SearchCond searchCondition = SearchCond.getLeafCond(cond);
+        assertTrue(searchCondition.isValid());
+
+        List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.USER);
+        assertNotNull(users);
+        assertTrue(users.isEmpty());
+    }
+
+    @Test
+    public void issueSYNCOPE46() {
+        SubjectCond cond = new SubjectCond(AttributeCond.Type.LIKE);
+        cond.setSchema("username");
+        cond.setExpression("%ossin%");
+
+        SearchCond searchCondition = SearchCond.getLeafCond(cond);
+        assertTrue(searchCondition.isValid());
+
+        List<User> users = searchDAO.search(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()),
+                searchCondition, SubjectType.USER);
+        assertNotNull(users);
+        assertEquals(1, users.size());
+    }
+
+    @Test
+    public void issueSYNCOPE433() {
+        AttributeCond isNullCond = new AttributeCond(AttributeCond.Type.ISNULL);
+        isNullCond.setSchema("loginDate");
+
+        SubjectCond likeCond = new SubjectCond(AttributeCond.Type.LIKE);
+        likeCond.setSchema("username");
+        likeCond.setExpression("%ossin%");
+
+        SearchCond searchCond = SearchCond.getOrCond(
+                SearchCond.getLeafCond(isNullCond), SearchCond.getLeafCond(likeCond));
+
+        Integer count = searchDAO.count(RoleEntitlementUtil.getRoleKeys(entitlementDAO.findAll()), searchCond,
+                SubjectType.USER);
+        assertNotNull(count);
+        assertTrue(count > 0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConfTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConfTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConfTest.java
new file mode 100644
index 0000000..5f504fc
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConfTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+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.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.server.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.server.persistence.api.dao.ConfDAO;
+import org.apache.syncope.server.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.server.persistence.api.entity.conf.CPlainAttr;
+import org.apache.syncope.server.persistence.api.entity.conf.CPlainSchema;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ConfTest extends AbstractTest {
+
+    @Autowired
+    private ConfDAO confDAO;
+
+    @Autowired
+    private PlainSchemaDAO plainSchemaDAO;
+
+    @Test
+    public void read() {
+        CPlainAttr conf = confDAO.find("selfRegistration.allowed");
+        assertNotNull(conf);
+        assertTrue(conf.getValues().get(0).getBooleanValue());
+
+        conf = confDAO.find("authentication.statuses");
+        assertNotNull(conf);
+        assertEquals(2, conf.getValues().size());
+
+        conf = confDAO.find("non.existing");
+        assertNull(conf);
+    }
+
+    @Test
+    public void setAndDelete() {
+        // 1. create CSChema
+        CPlainSchema useless = entityFactory.newEntity(CPlainSchema.class);
+        useless.setKey("useless");
+        useless.setType(AttrSchemaType.Date);
+        useless.setConversionPattern("yyyy-MM-dd");
+        useless = plainSchemaDAO.save(useless);
+
+        // 2. create conf
+        CPlainAttr newConf = entityFactory.newEntity(CPlainAttr.class);
+        newConf.setSchema(useless);
+        newConf.addValue("2014-06-20", attrUtilFactory.getInstance(AttributableType.CONFIGURATION));
+        confDAO.save(newConf);
+
+        CPlainAttr actual = confDAO.find("useless");
+        assertEquals(actual.getValuesAsStrings(), newConf.getValuesAsStrings());
+
+        // 3. update conf
+        newConf.getValues().clear();
+        newConf.addValue("2014-06-20", attrUtilFactory.getInstance(AttributableType.CONFIGURATION));
+        confDAO.save(newConf);
+
+        actual = confDAO.find("useless");
+        assertEquals(actual.getValuesAsStrings(), newConf.getValuesAsStrings());
+
+        // 4. delete conf
+        confDAO.delete("useless");
+        assertNull(confDAO.find("useless"));
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        try {
+            CPlainSchema failing = entityFactory.newEntity(CPlainSchema.class);
+            failing.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+            failing.setType(AttrSchemaType.String);
+            plainSchemaDAO.save(failing);
+
+            fail();
+        } catch (InvalidEntityException e) {
+            assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConnInstanceTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConnInstanceTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConnInstanceTest.java
new file mode 100644
index 0000000..15630d8
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/ConnInstanceTest.java
@@ -0,0 +1,145 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.apache.syncope.common.lib.types.ConnConfPropSchema;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+import org.apache.syncope.server.persistence.api.dao.ConnInstanceDAO;
+import org.apache.syncope.server.persistence.api.entity.ConnInstance;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ConnInstanceTest extends AbstractTest {
+
+    @Autowired
+    private ConnInstanceDAO connInstanceDAO;
+
+    @Test
+    public void findAll() {
+        List<ConnInstance> connectors = connInstanceDAO.findAll();
+        assertNotNull(connectors);
+        assertFalse(connectors.isEmpty());
+    }
+
+    @Test
+    public void findById() {
+        ConnInstance connectorInstance = connInstanceDAO.find(100L);
+
+        assertNotNull("findById did not work", connectorInstance);
+
+        assertEquals("invalid connector name",
+                "net.tirasa.connid.bundles.soap.WebServiceConnector", connectorInstance.getConnectorName());
+
+        assertEquals("invalid bundle name", "net.tirasa.connid.bundles.soap", connectorInstance.getBundleName());
+    }
+
+    @Test
+    public void save() throws ClassNotFoundException {
+        ConnInstance connInstance = entityFactory.newEntity(ConnInstance.class);
+
+        connInstance.setLocation(new File(System.getProperty("java.io.tmpdir")).toURI().toString());
+
+        // set connector version
+        connInstance.setVersion("1.0");
+
+        // set connector name
+        connInstance.setConnectorName("WebService");
+
+        // set bundle name
+        connInstance.setBundleName("org.apache.syncope.core.persistence.test.util");
+
+        connInstance.setDisplayName("New");
+
+        connInstance.setConnRequestTimeout(60);
+
+        // set the connector configuration using PropertyTO
+        Set<ConnConfProperty> conf = new HashSet<ConnConfProperty>();
+
+        ConnConfPropSchema endpointSchema = new ConnConfPropSchema();
+        endpointSchema.setName("endpoint");
+        endpointSchema.setType(String.class.getName());
+        endpointSchema.setRequired(true);
+        ConnConfProperty endpoint = new ConnConfProperty();
+        endpoint.setSchema(endpointSchema);
+        endpoint.getValues().add("http://host.domain");
+
+        ConnConfPropSchema servicenameSchema = new ConnConfPropSchema();
+        servicenameSchema.setName("servicename");
+        servicenameSchema.setType(String.class.getName());
+        servicenameSchema.setRequired(true);
+        ConnConfProperty servicename = new ConnConfProperty();
+        servicename.setSchema(servicenameSchema);
+        endpoint.getValues().add("Provisioning");
+
+        conf.add(endpoint);
+        conf.add(servicename);
+
+        // set connector configuration
+        connInstance.setConfiguration(conf);
+        assertFalse(connInstance.getConfiguration().isEmpty());
+
+        // perform save operation
+        ConnInstance actual = connInstanceDAO.save(connInstance);
+
+        assertNotNull("save did not work", actual.getKey());
+
+        assertTrue("save did not work", actual.getKey() > 100L);
+
+        assertEquals("save did not work for \"name\" attribute", "WebService", actual.getConnectorName());
+
+        assertEquals("save did not work for \"bundle name\" attribute", "org.apache.syncope.core.persistence.test.util",
+                actual.getBundleName());
+
+        assertEquals("save did not work for \"majorVersion\" attribute", "1.0", connInstance.getVersion());
+
+        assertEquals("New", actual.getDisplayName());
+
+        assertEquals(new Integer(60), actual.getConnRequestTimeout());
+
+        conf = connInstance.getConfiguration();
+        assertFalse(conf.isEmpty());
+
+        assertNotNull("configuration retrieving failed", conf);
+        assertTrue(conf.size() == 2);
+    }
+
+    @Test
+    public void delete() {
+        ConnInstance connectorInstance = connInstanceDAO.find(100L);
+        assertNotNull("find to delete did not work", connectorInstance);
+
+        connInstanceDAO.delete(connectorInstance.getKey());
+
+        ConnInstance actual = connInstanceDAO.find(100L);
+        assertNull("delete did not work", actual);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerAttrTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerAttrTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerAttrTest.java
new file mode 100644
index 0000000..797e893
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerAttrTest.java
@@ -0,0 +1,272 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+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 java.util.List;
+import org.apache.syncope.server.persistence.api.dao.DerAttrDAO;
+import org.apache.syncope.server.persistence.api.dao.DerSchemaDAO;
+import org.apache.syncope.server.persistence.api.dao.MembershipDAO;
+import org.apache.syncope.server.persistence.api.dao.RoleDAO;
+import org.apache.syncope.server.persistence.api.dao.UserDAO;
+import org.apache.syncope.server.persistence.api.entity.membership.MDerAttr;
+import org.apache.syncope.server.persistence.api.entity.membership.MDerAttrTemplate;
+import org.apache.syncope.server.persistence.api.entity.membership.MDerSchema;
+import org.apache.syncope.server.persistence.api.entity.membership.MPlainAttrValue;
+import org.apache.syncope.server.persistence.api.entity.membership.Membership;
+import org.apache.syncope.server.persistence.api.entity.role.RDerAttr;
+import org.apache.syncope.server.persistence.api.entity.role.RDerAttrTemplate;
+import org.apache.syncope.server.persistence.api.entity.role.RDerSchema;
+import org.apache.syncope.server.persistence.api.entity.role.RPlainAttrValue;
+import org.apache.syncope.server.persistence.api.entity.role.Role;
+import org.apache.syncope.server.persistence.api.entity.user.UDerAttr;
+import org.apache.syncope.server.persistence.api.entity.user.UDerSchema;
+import org.apache.syncope.server.persistence.api.entity.user.UPlainAttrValue;
+import org.apache.syncope.server.persistence.api.entity.user.User;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DerAttrTest extends AbstractTest {
+
+    @Autowired
+    private DerAttrDAO derAttrDAO;
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Autowired
+    private MembershipDAO membershipDAO;
+
+    @Autowired
+    private RoleDAO roleDAO;
+
+    @Autowired
+    private DerSchemaDAO derSchemaDAO;
+
+    @Test
+    public void findAll() {
+        List<UDerAttr> list = derAttrDAO.findAll(UDerAttr.class);
+        assertEquals("did not get expected number of derived attributes ", 2, list.size());
+    }
+
+    @Test
+    public void findById() {
+        UDerAttr attribute = derAttrDAO.find(100L, UDerAttr.class);
+        assertNotNull("did not find expected attribute schema", attribute);
+    }
+
+    @Test
+    public void saveUDerAttribute() {
+        UDerSchema cnSchema = derSchemaDAO.find("cn", UDerSchema.class);
+        assertNotNull(cnSchema);
+
+        User owner = userDAO.find(3L);
+        assertNotNull("did not get expected user", owner);
+
+        UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setSchema(cnSchema);
+
+        derAttr = derAttrDAO.save(derAttr);
+
+        UDerAttr actual = derAttrDAO.find(derAttr.getKey(), UDerAttr.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(derAttr, actual);
+
+        UPlainAttrValue firstname = owner.getPlainAttr("firstname").getValues().iterator().next();
+        UPlainAttrValue surname = owner.getPlainAttr("surname").getValues().iterator().next();
+
+        assertEquals(surname.getValue() + ", " + firstname.getValue(), derAttr.getValue(owner.getPlainAttrs()));
+    }
+
+    @Test
+    public void saveMDerAttribute() {
+        Membership owner = membershipDAO.find(1L);
+        assertNotNull("did not get expected user", owner);
+
+        MDerAttr derAttr = entityFactory.newEntity(MDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setTemplate(owner.getRole().getAttrTemplate(MDerAttrTemplate.class, "mderiveddata"));
+
+        derAttr = derAttrDAO.save(derAttr);
+        assertNotNull(derAttr.getTemplate());
+
+        MDerAttr actual = derAttrDAO.find(derAttr.getKey(), MDerAttr.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(derAttr, actual);
+
+        MPlainAttrValue sx = owner.getPlainAttr("mderived_sx").getValues().iterator().next();
+        MPlainAttrValue dx = owner.getPlainAttr("mderived_dx").getValues().iterator().next();
+
+        assertEquals(sx.getValue() + "-" + dx.getValue(), derAttr.getValue(owner.getPlainAttrs()));
+    }
+
+    @Test
+    public void saveRDerAttribute() {
+        Role owner = roleDAO.find(1L);
+        assertNotNull("did not get expected user", owner);
+
+        RDerAttr derAttr = entityFactory.newEntity(RDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setTemplate(owner.getAttrTemplate(RDerAttrTemplate.class, "rderiveddata"));
+
+        derAttr = derAttrDAO.save(derAttr);
+        assertNotNull(derAttr.getTemplate());
+
+        RDerAttr actual = derAttrDAO.find(derAttr.getKey(), RDerAttr.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(derAttr, actual);
+
+        RPlainAttrValue sx = owner.getPlainAttr("rderived_sx").getValues().iterator().next();
+        RPlainAttrValue dx = owner.getPlainAttr("rderived_dx").getValues().iterator().next();
+
+        assertEquals(sx.getValue() + "-" + dx.getValue(), derAttr.getValue(owner.getPlainAttrs()));
+    }
+
+    @Test
+    public void delete() {
+        UDerAttr attribute = derAttrDAO.find(100L, UDerAttr.class);
+        String attributeSchemaName = attribute.getSchema().getKey();
+
+        derAttrDAO.delete(attribute.getKey(), UDerAttr.class);
+
+        UDerAttr actual = derAttrDAO.find(100L, UDerAttr.class);
+        assertNull("delete did not work", actual);
+
+        UDerSchema attributeSchema = derSchemaDAO.find(attributeSchemaName, UDerSchema.class);
+        assertNotNull("user derived attribute schema deleted " + "when deleting values", attributeSchema);
+    }
+
+    @Test
+    public void issueSYNCOPE134User() {
+        UDerSchema sderived = entityFactory.newEntity(UDerSchema.class);
+        sderived.setKey("sderived");
+        sderived.setExpression("status + ' - ' + username + ' - ' + creationDate + '[' + failedLogins + ']'");
+
+        sderived = derSchemaDAO.save(sderived);
+        derSchemaDAO.flush();
+
+        UDerSchema actual = derSchemaDAO.find("sderived", UDerSchema.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(sderived, actual);
+
+        User owner = userDAO.find(3L);
+        assertNotNull("did not get expected user", owner);
+
+        UDerAttr derAttr = entityFactory.newEntity(UDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setSchema(sderived);
+
+        derAttr = derAttrDAO.save(derAttr);
+        derAttrDAO.flush();
+
+        derAttr = derAttrDAO.find(derAttr.getKey(), UDerAttr.class);
+        assertNotNull("expected save to work", derAttr);
+
+        String value = derAttr.getValue(owner.getPlainAttrs());
+        assertNotNull(value);
+        assertFalse(value.isEmpty());
+        assertTrue(value.startsWith("active - vivaldi - 2010-10-20"));
+        assertTrue(value.endsWith("[0]"));
+    }
+
+    @Test
+    public void issueSYNCOPE134Role() {
+        RDerSchema sderived = entityFactory.newEntity(RDerSchema.class);
+        sderived.setKey("sderived");
+        sderived.setExpression("name");
+
+        sderived = derSchemaDAO.save(sderived);
+        derSchemaDAO.flush();
+
+        RDerSchema actual = derSchemaDAO.find("sderived", RDerSchema.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(sderived, actual);
+
+        Role owner = roleDAO.find(7L);
+        assertNotNull("did not get expected role", owner);
+
+        RDerAttrTemplate template = entityFactory.newEntity(RDerAttrTemplate.class);
+        template.setSchema(sderived);
+        owner.getAttrTemplates(RDerAttrTemplate.class).add(template);
+
+        RDerAttr derAttr = entityFactory.newEntity(RDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setTemplate(owner.getAttrTemplate(RDerAttrTemplate.class, sderived.getKey()));
+
+        derAttr = derAttrDAO.save(derAttr);
+        assertNotNull(derAttr.getTemplate());
+        derAttrDAO.flush();
+
+        derAttr = derAttrDAO.find(derAttr.getKey(), RDerAttr.class);
+        assertNotNull("expected save to work", derAttr);
+
+        String value = derAttr.getValue(owner.getPlainAttrs());
+        assertNotNull(value);
+        assertFalse(value.isEmpty());
+        assertTrue(value.startsWith("managingDirector"));
+    }
+
+    @Test
+    public void issueSYNCOPE134Memb() {
+        MDerSchema mderived = entityFactory.newEntity(MDerSchema.class);
+        mderived.setKey("mderived");
+        mderived.setExpression("key");
+
+        mderived = derSchemaDAO.save(mderived);
+        derSchemaDAO.flush();
+
+        MDerSchema actual = derSchemaDAO.find("mderived", MDerSchema.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(mderived, actual);
+
+        Membership owner = membershipDAO.find(4L);
+        assertNotNull("did not get expected membership", owner);
+
+        MDerAttrTemplate template = entityFactory.newEntity(MDerAttrTemplate.class);
+        template.setSchema(mderived);
+        owner.getRole().getAttrTemplates(MDerAttrTemplate.class).add(template);
+
+        derSchemaDAO.flush();
+
+        MDerAttr derAttr = entityFactory.newEntity(MDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setTemplate(owner.getRole().getAttrTemplate(MDerAttrTemplate.class, mderived.getKey()));
+
+        derAttr = derAttrDAO.save(derAttr);
+        assertNotNull(derAttr.getTemplate());
+        derAttrDAO.flush();
+
+        derAttr = derAttrDAO.find(derAttr.getKey(), MDerAttr.class);
+        assertNotNull("expected save to work", derAttr);
+
+        String value = derAttr.getValue(owner.getPlainAttrs());
+        assertNotNull(value);
+        assertFalse(value.isEmpty());
+        assertTrue(value.equalsIgnoreCase("4"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerSchemaTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerSchemaTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerSchemaTest.java
new file mode 100644
index 0000000..ff958fa
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/DerSchemaTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+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.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.server.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.server.persistence.api.dao.DerSchemaDAO;
+import org.apache.syncope.server.persistence.api.entity.DerSchema;
+import org.apache.syncope.server.persistence.api.entity.role.RDerSchema;
+import org.apache.syncope.server.persistence.api.entity.user.UDerSchema;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class DerSchemaTest extends AbstractTest {
+
+    @Autowired
+    private DerSchemaDAO derSchemaDAO;
+
+    @Test
+    public void findAll() {
+        List<UDerSchema> list = derSchemaDAO.findAll(UDerSchema.class);
+        assertEquals(3, list.size());
+    }
+
+    @Test
+    public void findByName() {
+        UDerSchema attributeSchema = derSchemaDAO.find("cn", UDerSchema.class);
+        assertNotNull("did not find expected derived attribute schema", attributeSchema);
+    }
+
+    @Test
+    public void save() {
+        UDerSchema derivedAttributeSchema = entityFactory.newEntity(UDerSchema.class);
+        derivedAttributeSchema.setKey("cn2");
+        derivedAttributeSchema.setExpression("firstname surname");
+
+        derSchemaDAO.save(derivedAttributeSchema);
+
+        UDerSchema actual = derSchemaDAO.find("cn2", UDerSchema.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(derivedAttributeSchema, actual);
+    }
+
+    @Test
+    public void delete() {
+        UDerSchema cn = derSchemaDAO.find("cn", UDerSchema.class);
+        assertNotNull(cn);
+
+        derSchemaDAO.delete(cn.getKey(), attrUtilFactory.getInstance(AttributableType.USER));
+
+        DerSchema actual = derSchemaDAO.find("cn", UDerSchema.class);
+        assertNull("delete did not work", actual);
+
+        // ------------- //
+        RDerSchema rderiveddata = derSchemaDAO.find("rderiveddata", RDerSchema.class);
+        assertNotNull(rderiveddata);
+
+        derSchemaDAO.delete(rderiveddata.getKey(), attrUtilFactory.getInstance(AttributableType.ROLE));
+
+        actual = derSchemaDAO.find("rderiveddata", RDerSchema.class);
+        assertNull("delete did not work", actual);
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        UDerSchema schema = entityFactory.newEntity(UDerSchema.class);
+        schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+
+        try {
+            derSchemaDAO.save(schema);
+            fail();
+        } catch (InvalidEntityException e) {
+            assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/235f60fa/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/EntitlementTest.java
----------------------------------------------------------------------
diff --git a/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/EntitlementTest.java b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/EntitlementTest.java
new file mode 100644
index 0000000..23c67fd
--- /dev/null
+++ b/syncope620/server/persistence-jpa/src/test/java/org/apache/syncope/server/persistence/jpa/entity/EntitlementTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.server.persistence.jpa.entity;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.server.persistence.api.dao.EntitlementDAO;
+import org.apache.syncope.server.persistence.api.entity.Entitlement;
+import org.apache.syncope.server.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class EntitlementTest extends AbstractTest {
+
+    @Autowired
+    private EntitlementDAO entitlementDAO;
+
+    @Test
+    public void findAll() {
+        List<Entitlement> list = entitlementDAO.findAll();
+        assertEquals("did not get expected number of entitlements ", 86, list.size());
+    }
+
+    @Test
+    public void findByName() {
+        Entitlement entitlement = entitlementDAO.find("base");
+        assertNotNull("did not find expected entitlement", entitlement);
+    }
+
+    @Test
+    public void save() {
+        Entitlement entitlement = entityFactory.newEntity(Entitlement.class);
+        entitlement.setKey("another");
+
+        entitlementDAO.save(entitlement);
+
+        Entitlement actual = entitlementDAO.find("another");
+        assertNotNull("expected save to work", actual);
+        assertEquals(entitlement, actual);
+    }
+
+    @Test
+    public void delete() {
+        Entitlement entitlement = entitlementDAO.find("base");
+        assertNotNull("did not find expected entitlement", entitlement);
+
+        entitlementDAO.delete("base");
+
+        assertNull(entitlementDAO.find("base"));
+    }
+}