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/06/11 16:17:57 UTC

[67/70] syncope git commit: [SYNCOPE-666] All done now

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ConnInstanceTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ConnInstanceTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ConnInstanceTest.java
new file mode 100644
index 0000000..70665ed
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/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.core.persistence.jpa.inner;
+
+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.core.persistence.api.dao.ConnInstanceDAO;
+import org.apache.syncope.core.persistence.api.entity.ConnInstance;
+import org.apache.syncope.core.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(60, actual.getConnRequestTimeout(), 0);
+
+        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/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerAttrTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerAttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerAttrTest.java
new file mode 100644
index 0000000..cd336ae
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerAttrTest.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.core.persistence.api.dao.AnyTypeClassDAO;
+import org.apache.syncope.core.persistence.api.dao.DerAttrDAO;
+import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
+import org.apache.syncope.core.persistence.api.dao.GroupDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
+import org.apache.syncope.core.persistence.api.entity.DerSchema;
+import org.apache.syncope.core.persistence.api.entity.group.GDerAttr;
+import org.apache.syncope.core.persistence.api.entity.group.GPlainAttrValue;
+import org.apache.syncope.core.persistence.api.entity.group.Group;
+import org.apache.syncope.core.persistence.api.entity.user.UDerAttr;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.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 GroupDAO groupDAO;
+
+    @Autowired
+    private DerSchemaDAO derSchemaDAO;
+
+    @Autowired
+    private AnyTypeClassDAO anyTypeClassDAO;
+
+    @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() {
+        DerSchema cnSchema = derSchemaDAO.find("cn");
+        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 saveGDerAttribute() {
+        DerSchema schema = derSchemaDAO.find("rderiveddata");
+        assertNotNull(schema);
+
+        Group owner = groupDAO.find(1L);
+        assertNotNull("did not get expected user", owner);
+
+        GDerAttr derAttr = entityFactory.newEntity(GDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setSchema(schema);
+
+        derAttr = derAttrDAO.save(derAttr);
+
+        GDerAttr actual = derAttrDAO.find(derAttr.getKey(), GDerAttr.class);
+        assertNotNull("expected save to work", actual);
+        assertEquals(derAttr, actual);
+
+        GPlainAttrValue sx = owner.getPlainAttr("rderived_sx").getValues().iterator().next();
+        GPlainAttrValue 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 schemaName = attribute.getSchema().getKey();
+
+        derAttrDAO.delete(attribute.getKey(), UDerAttr.class);
+
+        UDerAttr actual = derAttrDAO.find(100L, UDerAttr.class);
+        assertNull("delete did not work", actual);
+
+        DerSchema attributeSchema = derSchemaDAO.find(schemaName);
+        assertNotNull("user derived attribute schema deleted when deleting values", attributeSchema);
+    }
+
+    @Test
+    public void issueSYNCOPE134User() {
+        AnyTypeClass other = anyTypeClassDAO.find("other");
+
+        DerSchema sderived = entityFactory.newEntity(DerSchema.class);
+        sderived.setKey("sderived");
+        sderived.setExpression("status + ' - ' + username + ' - ' + creationDate + '[' + failedLogins + ']'");
+
+        sderived = derSchemaDAO.save(sderived);
+
+        derSchemaDAO.flush();
+
+        other.add(sderived);
+        sderived.setAnyTypeClass(other);
+
+        derSchemaDAO.flush();
+
+        sderived = derSchemaDAO.find("sderived");
+        assertNotNull("expected save to work", sderived);
+        assertEquals(other, sderived.getAnyTypeClass());
+
+        User owner = userDAO.find(3L);
+        assertNotNull("did not get expected user", owner);
+        owner.add(other);
+
+        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 issueSYNCOPE134Group() {
+        AnyTypeClass genericMembership = anyTypeClassDAO.find("generic membership");
+
+        DerSchema sderived = entityFactory.newEntity(DerSchema.class);
+        sderived.setKey("sderived");
+        sderived.setExpression("name");
+
+        sderived = derSchemaDAO.save(sderived);
+
+        derSchemaDAO.flush();
+
+        genericMembership.add(sderived);
+        sderived.setAnyTypeClass(genericMembership);
+
+        derSchemaDAO.flush();
+
+        sderived = derSchemaDAO.find("sderived");
+        assertNotNull("expected save to work", sderived);
+        assertEquals(genericMembership, sderived.getAnyTypeClass());
+
+        Group owner = groupDAO.find(7L);
+        assertNotNull("did not get expected group", owner);
+        owner.add(genericMembership);
+
+        GDerAttr derAttr = entityFactory.newEntity(GDerAttr.class);
+        derAttr.setOwner(owner);
+        derAttr.setSchema(sderived);
+
+        derAttr = derAttrDAO.save(derAttr);
+        derAttrDAO.flush();
+
+        derAttr = derAttrDAO.find(derAttr.getKey(), GDerAttr.class);
+        assertNotNull("expected save to work", derAttr);
+
+        String value = derAttr.getValue(owner.getPlainAttrs());
+        assertNotNull(value);
+        assertFalse(value.isEmpty());
+        assertTrue(value.startsWith("managingDirector"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerSchemaTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerSchemaTest.java
new file mode 100644
index 0000000..c62ab6e
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/DerSchemaTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.DerSchemaDAO;
+import org.apache.syncope.core.persistence.api.entity.DerSchema;
+import org.apache.syncope.core.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<DerSchema> list = derSchemaDAO.findAll();
+        assertEquals(9, list.size());
+    }
+
+    @Test
+    public void findByName() {
+        DerSchema attributeSchema = derSchemaDAO.find("cn");
+        assertNotNull("did not find expected derived attribute schema", attributeSchema);
+    }
+
+    @Test
+    public void save() {
+        DerSchema derivedAttributeSchema = entityFactory.newEntity(DerSchema.class);
+        derivedAttributeSchema.setKey("cn2");
+        derivedAttributeSchema.setExpression("firstname surname");
+
+        derSchemaDAO.save(derivedAttributeSchema);
+
+        DerSchema actual = derSchemaDAO.find("cn2");
+        assertNotNull("expected save to work", actual);
+        assertEquals(derivedAttributeSchema, actual);
+    }
+
+    @Test
+    public void delete() {
+        DerSchema cn = derSchemaDAO.find("cn");
+        assertNotNull(cn);
+
+        derSchemaDAO.delete(cn.getKey());
+
+        DerSchema actual = derSchemaDAO.find("cn");
+        assertNull("delete did not work", actual);
+
+        // ------------- //
+        DerSchema rderiveddata = derSchemaDAO.find("rderiveddata");
+        assertNotNull(rderiveddata);
+
+        derSchemaDAO.delete(rderiveddata.getKey());
+
+        actual = derSchemaDAO.find("rderiveddata");
+        assertNull("delete did not work", actual);
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        DerSchema schema = entityFactory.newEntity(DerSchema.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/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/GroupTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/GroupTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/GroupTest.java
new file mode 100644
index 0000000..c6a31ef
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/GroupTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.common.lib.SyncopeConstants;
+import org.apache.syncope.core.persistence.api.dao.GroupDAO;
+import org.apache.syncope.core.persistence.api.dao.RealmDAO;
+import org.apache.syncope.core.persistence.api.entity.group.Group;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class GroupTest extends AbstractTest {
+
+    @Autowired
+    private GroupDAO groupDAO;
+
+    @Autowired
+    private RealmDAO realmDAO;
+
+    @Test
+    public void findAll() {
+        List<Group> list = groupDAO.findAll(SyncopeConstants.FULL_ADMIN_REALMS, 1, 100);
+        assertEquals("did not get expected number of groups ", 14, list.size());
+    }
+
+    @Test
+    public void find() {
+        Group group = groupDAO.find("root");
+        assertNotNull("did not find expected group", group);
+    }
+
+    @Test
+    public void save() {
+        Group group = entityFactory.newEntity(Group.class);
+        group.setName("secondChild");
+        group.setRealm(realmDAO.find(SyncopeConstants.ROOT_REALM));
+
+        group = groupDAO.save(group);
+
+        Group actual = groupDAO.find(group.getKey());
+        assertNotNull("expected save to work", actual);
+    }
+
+    @Test
+    public void delete() {
+        Group group = groupDAO.find(4L);
+        groupDAO.delete(group.getKey());
+
+        Group actual = groupDAO.find(4L);
+        assertNull("delete did not work", actual);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/NotificationTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/NotificationTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/NotificationTest.java
new file mode 100644
index 0000000..150b924
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/NotificationTest.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.common.lib.types.IntMappingType;
+import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
+import org.apache.syncope.core.persistence.api.dao.NotificationDAO;
+import org.apache.syncope.core.persistence.api.entity.AnyAbout;
+import org.apache.syncope.core.persistence.api.entity.Notification;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class NotificationTest extends AbstractTest {
+
+    @Autowired
+    private AnyTypeDAO anyTypeDAO;
+
+    @Autowired
+    private NotificationDAO notificationDAO;
+
+    @Test
+    public void find() {
+        Notification notification = notificationDAO.find(10L);
+        assertNotNull(notification);
+        assertNotNull(notification.getEvents());
+        assertFalse(notification.getEvents().isEmpty());
+        assertNotNull(notification.getAbout(anyTypeDAO.findUser()));
+        assertNotNull(notification.getRecipients());
+
+    }
+
+    @Test
+    public void findAll() {
+        List<Notification> notifications = notificationDAO.findAll();
+        assertNotNull(notifications);
+        assertFalse(notifications.isEmpty());
+    }
+
+    @Test
+    public void save() {
+        Notification notification = entityFactory.newEntity(Notification.class);
+        notification.getEvents().add("save");
+
+        AnyAbout about = entityFactory.newEntity(AnyAbout.class);
+        about.setNotification(notification);
+        notification.add(about);
+        about.setAnyType(anyTypeDAO.findUser());
+        about.set("fake search condition");
+
+        notification.setRecipients("fake recipients");
+
+        notification.setRecipientAttrName("email");
+        notification.setRecipientAttrType(IntMappingType.UserPlainSchema);
+
+        notification.setSender("syncope@syncope.apache.org");
+        notification.setSubject("Test notification");
+        notification.setTemplate("test");
+
+        Notification actual = notificationDAO.save(notification);
+        assertNotNull(actual);
+        assertNotNull(actual.getKey());
+    }
+
+    @Test
+    public void delete() {
+        notificationDAO.delete(10L);
+        assertNull(notificationDAO.find(10L));
+    }
+
+    @Test
+    public void issueSYNCOPE445() {
+        Notification notification = entityFactory.newEntity(Notification.class);
+        notification.getEvents().add("save");
+
+        AnyAbout about = entityFactory.newEntity(AnyAbout.class);
+        about.setNotification(notification);
+        notification.add(about);
+        about.setAnyType(anyTypeDAO.findUser());
+        about.set("fake search condition");
+
+        notification.setRecipients("fake search condition");
+
+        notification.setRecipientAttrName("email");
+        notification.setRecipientAttrType(IntMappingType.UserPlainSchema);
+
+        notification.getStaticRecipients().add("syncope445@syncope.apache.org");
+
+        notification.setSender("syncope@syncope.apache.org");
+        notification.setSubject("Test notification");
+        notification.setTemplate("test");
+
+        Notification actual = notificationDAO.save(notification);
+        assertNotNull(actual);
+        assertNotNull(actual.getKey());
+        assertNotNull(actual.getStaticRecipients());
+        assertFalse(actual.getStaticRecipients().isEmpty());
+    }
+
+    @Test
+    public void issueSYNCOPE446() {
+        Notification notification = entityFactory.newEntity(Notification.class);
+        notification.getEvents().add("[REST]:[GroupLogic]:[]:[create]:[SUCCESS]");
+
+        AnyAbout about = entityFactory.newEntity(AnyAbout.class);
+        about.setNotification(notification);
+        notification.add(about);
+        about.setAnyType(anyTypeDAO.findUser());
+        about.set("fake search condition");
+
+        notification.setRecipientAttrName("email");
+        notification.setRecipientAttrType(IntMappingType.UserPlainSchema);
+
+        notification.getStaticRecipients().add("syncope446@syncope.apache.org");
+
+        notification.setSender("syncope@syncope.apache.org");
+        notification.setSubject("Test notification");
+        notification.setTemplate("test");
+
+        Notification actual = notificationDAO.save(notification);
+        assertNotNull(actual);
+        assertNotNull(actual.getKey());
+        assertNotNull(actual.getStaticRecipients());
+        assertFalse(actual.getStaticRecipients().isEmpty());
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainAttrTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainAttrTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainAttrTest.java
new file mode 100644
index 0000000..108e622
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainAttrTest.java
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.AnyTypeKind;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.dao.UserDAO;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
+import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrUniqueValue;
+import org.apache.syncope.core.persistence.api.entity.user.User;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.apache.syncope.core.misc.security.Encryptor;
+import org.apache.syncope.core.persistence.api.entity.PlainSchema;
+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 PlainAttrTest extends AbstractTest {
+
+    @Autowired
+    private UserDAO userDAO;
+
+    @Autowired
+    private PlainAttrDAO plainAttrDAO;
+
+    @Autowired
+    private PlainSchemaDAO plainSchemaDAO;
+
+    @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);
+
+        PlainSchema emailSchema = plainSchemaDAO.find("email");
+        assertNotNull(emailSchema);
+
+        UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
+        attr.setOwner(user);
+        attr.setSchema(emailSchema);
+
+        Exception thrown = null;
+        try {
+            attr.add("john.doe@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
+            attr.add("mario.rossi@gmail.com", anyUtilsFactory.getInstance(AnyTypeKind.USER));
+        } catch (ValidationException e) {
+            thrown = e;
+        }
+        assertNull("no validation exception expected here ", thrown);
+
+        try {
+            attr.add("http://www.apache.org", anyUtilsFactory.getInstance(AnyTypeKind.USER));
+        } catch (ValidationException e) {
+            thrown = e;
+        }
+        assertNotNull("validation exception expected here ", thrown);
+    }
+
+    @Test
+    public void saveWithEnum() throws ClassNotFoundException {
+        User user = userDAO.find(1L);
+        assertNotNull(user);
+
+        PlainSchema gender = plainSchemaDAO.find("gender");
+        assertNotNull(gender);
+        assertNotNull(gender.getType());
+        assertNotNull(gender.getEnumerationValues());
+
+        UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
+        attribute.setOwner(user);
+        attribute.setSchema(gender);
+        user.add(attribute);
+
+        Exception thrown = null;
+
+        try {
+            attribute.add("A", anyUtilsFactory.getInstance(AnyTypeKind.USER));
+        } catch (ValidationException e) {
+            thrown = e;
+        }
+        assertNotNull("validation exception expected here ", thrown);
+
+        attribute.add("M", anyUtilsFactory.getInstance(AnyTypeKind.USER));
+
+        InvalidEntityException iee = null;
+        try {
+            userDAO.save(user);
+        } catch (InvalidEntityException e) {
+            iee = e;
+        }
+        assertNull(iee);
+    }
+
+    @Test
+    public void validateAndSave() {
+        User user = userDAO.find(1L);
+
+        PlainSchema emailSchema = plainSchemaDAO.find("email");
+        assertNotNull(emailSchema);
+
+        PlainSchema fullnameSchema = plainSchemaDAO.find("fullname");
+        assertNotNull(fullnameSchema);
+
+        UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
+        attr.setOwner(user);
+        attr.setSchema(emailSchema);
+
+        UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class);
+        uauv.setAttr(attr);
+        uauv.setSchema(fullnameSchema);
+        uauv.setStringValue("a value");
+
+        attr.setUniqueValue(uauv);
+
+        user.add(attr);
+
+        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.InvalidPlainSchema));
+    }
+
+    @Test
+    public void saveWithEncrypted() throws Exception {
+        User user = userDAO.find(1L);
+
+        PlainSchema obscureSchema = plainSchemaDAO.find("obscure");
+        assertNotNull(obscureSchema);
+        assertNotNull(obscureSchema.getSecretKey());
+        assertNotNull(obscureSchema.getCipherAlgorithm());
+
+        UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
+        attr.setOwner(user);
+        attr.setSchema(obscureSchema);
+        attr.add("testvalue", anyUtilsFactory.getInstance(AnyTypeKind.USER));
+        user.add(attr);
+
+        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);
+
+        PlainSchema photoSchema = plainSchemaDAO.find("photo");
+        assertNotNull(photoSchema);
+        assertNotNull(photoSchema.getMimeType());
+
+        byte[] bytes = new byte[20];
+        new Random().nextBytes(bytes);
+        String photoB64Value = new String(Base64.encode(bytes), SyncopeConstants.DEFAULT_CHARSET);
+
+        UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
+        attr.setOwner(user);
+        attr.setSchema(photoSchema);
+        attr.add(photoB64Value, anyUtilsFactory.getInstance(AnyTypeKind.USER));
+        user.add(attr);
+
+        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);
+
+        PlainSchema schema = plainSchemaDAO.find(attrSchemaName);
+        assertNotNull("user attribute schema deleted when deleting values", schema);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainSchemaTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainSchemaTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainSchemaTest.java
new file mode 100644
index 0000000..119ae6d
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PlainSchemaTest.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
+import org.apache.syncope.core.persistence.api.entity.PlainSchema;
+import org.apache.syncope.core.persistence.api.entity.group.GPlainAttr;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class PlainSchemaTest extends AbstractTest {
+
+    @Autowired
+    private PlainSchemaDAO plainSchemaDAO;
+
+    @Test
+    public void findAll() {
+        List<PlainSchema> schemas = plainSchemaDAO.findAll();
+        assertEquals(42, schemas.size());
+    }
+
+    @Test
+    public void findByName() {
+        PlainSchema schema = plainSchemaDAO.find("fullname");
+        assertNotNull("did not find expected attribute schema", schema);
+    }
+
+    @Test
+    public void findAttrs() {
+        PlainSchema schema = plainSchemaDAO.find("icon");
+        assertNotNull(schema);
+
+        List<GPlainAttr> attrs = plainSchemaDAO.findAttrs(schema, GPlainAttr.class);
+        assertNotNull(attrs);
+        assertFalse(attrs.isEmpty());
+    }
+
+    @Test
+    public void save() {
+        PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
+        schema.setKey("secondaryEmail");
+        schema.setType(AttrSchemaType.String);
+        schema.setValidatorClass("org.apache.syncope.core.validation.EmailAddressValidator");
+        schema.setMandatoryCondition("false");
+        schema.setMultivalue(true);
+
+        plainSchemaDAO.save(schema);
+
+        PlainSchema actual = plainSchemaDAO.find("secondaryEmail");
+        assertNotNull("expected save to work", actual);
+        assertEquals(schema, actual);
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveNonValid() {
+        PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
+        schema.setKey("secondaryEmail");
+        schema.setType(AttrSchemaType.String);
+        schema.setValidatorClass("org.apache.syncope.core.validation.EmailAddressValidator");
+        schema.setMandatoryCondition("false");
+        schema.setMultivalue(true);
+        schema.setUniqueConstraint(true);
+
+        plainSchemaDAO.save(schema);
+    }
+
+    @Test
+    public void checkForEnumType() {
+        PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
+        schema.setType(AttrSchemaType.Enum);
+        schema.setKey("color");
+
+        Exception ex = null;
+        try {
+            plainSchemaDAO.save(schema);
+        } catch (Exception e) {
+            ex = e;
+        }
+        assertNotNull(ex);
+
+        schema.setEnumerationValues("red" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "yellow");
+        schema.setEnumerationKeys("1" + SyncopeConstants.ENUM_VALUES_SEPARATOR + "2");
+
+        plainSchemaDAO.save(schema);
+
+        PlainSchema actual = plainSchemaDAO.find(schema.getKey());
+        assertNotNull(actual);
+        assertNotNull(actual.getEnumerationKeys());
+        assertFalse(actual.getEnumerationKeys().isEmpty());
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveInvalidSchema() {
+        PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
+        schema.setKey("username");
+        plainSchemaDAO.save(schema);
+    }
+
+    @Test
+    public void delete() {
+        PlainSchema firstname = plainSchemaDAO.find("firstname");
+
+        plainSchemaDAO.delete(firstname.getKey());
+
+        PlainSchema actual = plainSchemaDAO.find("firstname");
+        assertNull("delete did not work", actual);
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        PlainSchema schema = entityFactory.newEntity(PlainSchema.class);
+        schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+
+        try {
+            plainSchemaDAO.save(schema);
+            fail();
+        } catch (InvalidEntityException e) {
+            assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
new file mode 100644
index 0000000..ed11445
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/PolicyTest.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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 java.util.List;
+import org.apache.syncope.common.lib.types.PasswordPolicySpec;
+import org.apache.syncope.common.lib.types.PolicyType;
+import org.apache.syncope.common.lib.types.SyncPolicySpec;
+import org.apache.syncope.common.lib.types.SyncPolicySpecItem;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
+import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
+import org.apache.syncope.core.persistence.api.entity.Policy;
+import org.apache.syncope.core.persistence.api.entity.SyncPolicy;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class PolicyTest extends AbstractTest {
+
+    @Autowired
+    private AnyTypeDAO anyTypeDAO;
+
+    @Autowired
+    private PolicyDAO policyDAO;
+
+    @Test
+    public void findAll() {
+        List<Policy> policies = policyDAO.findAll();
+        assertNotNull(policies);
+        assertFalse(policies.isEmpty());
+    }
+
+    @Test
+    public void findById() {
+        Policy policy = policyDAO.find(1L);
+        assertNotNull("findById did not work", policy);
+    }
+
+    @Test
+    public void findByType() {
+        List<? extends Policy> policies = policyDAO.find(PolicyType.SYNC);
+        assertNotNull("findById did not work", policies);
+        assertFalse(policies.isEmpty());
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveInvalidPolicy() {
+        PasswordPolicySpec passwordPolicy = new PasswordPolicySpec();
+        passwordPolicy.setMaxLength(8);
+        passwordPolicy.setMinLength(6);
+
+        SyncPolicy policy = entityFactory.newEntity(SyncPolicy.class);
+        policy.setSpecification(passwordPolicy);
+        policy.setDescription("sync policy");
+
+        policyDAO.save(policy);
+    }
+
+    @Test
+    public void create() {
+        SyncPolicy policy = entityFactory.newEntity(SyncPolicy.class);
+
+        final String syncURuleName = "net.tirasa.sync.correlation.TirasaURule";
+        final String syncGRuleName = "net.tirasa.sync.correlation.TirasaGRule";
+
+        SyncPolicySpec syncPolicySpec = new SyncPolicySpec();
+
+        SyncPolicySpecItem item = new SyncPolicySpecItem();
+        item.setAnyTypeKey(anyTypeDAO.findUser().getKey());
+        item.setJavaRule(syncURuleName);
+        syncPolicySpec.getItems().add(item);
+
+        item = new SyncPolicySpecItem();
+        item.setAnyTypeKey(anyTypeDAO.findGroup().getKey());
+        item.setJavaRule(syncGRuleName);
+        syncPolicySpec.getItems().add(item);
+
+        policy.setSpecification(syncPolicySpec);
+        policy.setDescription("Sync policy");
+
+        policy = policyDAO.save(policy);
+
+        assertNotNull(policy);
+        assertEquals(PolicyType.SYNC, policy.getType());
+        assertEquals(syncURuleName,
+                (policy.getSpecification(SyncPolicySpec.class)).getItem(anyTypeDAO.findUser().getKey()).getJavaRule());
+        assertEquals(syncGRuleName,
+                (policy.getSpecification(SyncPolicySpec.class)).getItem(anyTypeDAO.findGroup().getKey()).getJavaRule());
+    }
+
+    @Test
+    public void update() {
+        PasswordPolicySpec specification = new PasswordPolicySpec();
+        specification.setMaxLength(8);
+        specification.setMinLength(6);
+
+        Policy policy = policyDAO.find(2L);
+        assertNotNull(policy);
+        policy.setSpecification(specification);
+
+        policy = policyDAO.save(policy);
+
+        assertNotNull(policy);
+        assertEquals(PolicyType.PASSWORD, policy.getType());
+        assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMaxLength(), 8);
+        assertEquals((policy.getSpecification(PasswordPolicySpec.class)).getMinLength(), 6);
+    }
+
+    @Test
+    public void delete() {
+        Policy policy = policyDAO.find(1L);
+        assertNotNull("find to delete did not work", policy);
+
+        policyDAO.delete(policy);
+
+        Policy actual = policyDAO.find(1L);
+        assertNull("delete did not work", actual);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RealmTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RealmTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RealmTest.java
new file mode 100644
index 0000000..3fef2ce
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RealmTest.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.commons.collections4.CollectionUtils;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.MalformedPathException;
+import org.apache.syncope.core.persistence.api.dao.PolicyDAO;
+import org.apache.syncope.core.persistence.api.dao.RealmDAO;
+import org.apache.syncope.core.persistence.api.entity.AccountPolicy;
+import org.apache.syncope.core.persistence.api.entity.PasswordPolicy;
+import org.apache.syncope.core.persistence.api.entity.Realm;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class RealmTest extends AbstractTest {
+
+    @Autowired
+    private RealmDAO realmDAO;
+
+    @Autowired
+    private PolicyDAO policyDAO;
+
+    @Test
+    public void getRoot() {
+        assertNotNull(realmDAO.getRoot());
+    }
+
+    @Test
+    public void find() {
+        Realm realm = realmDAO.find(1L);
+        assertNotNull(realm);
+        assertEquals(SyncopeConstants.ROOT_REALM, realm.getName());
+        assertEquals(SyncopeConstants.ROOT_REALM, realm.getFullPath());
+
+        realm = realmDAO.find(3L);
+        assertNotNull(realm);
+        assertEquals("even", realm.getName());
+        assertEquals("/even", realm.getFullPath());
+        assertEquals(1, realm.getParent().getKey(), 0);
+        assertEquals(realmDAO.getRoot(), realm.getParent());
+
+        realm = realmDAO.find("/even/two");
+        assertNotNull(realm);
+        assertEquals(4, realm.getKey(), 0);
+        assertEquals("two", realm.getName());
+        assertEquals("/even/two", realm.getFullPath());
+    }
+
+    @Test(expected = MalformedPathException.class)
+    public void findInvalidPath() {
+        realmDAO.find("even/two");
+    }
+
+    @Test
+    public void findChildren() {
+        List<Realm> children = realmDAO.findChildren(realmDAO.find(SyncopeConstants.ROOT_REALM));
+        assertEquals(2, children.size());
+        assertTrue(children.contains(realmDAO.find("/odd")));
+        assertTrue(children.contains(realmDAO.find("/even")));
+
+        children = realmDAO.findChildren(realmDAO.find("/odd"));
+        assertTrue(children.isEmpty());
+    }
+
+    @Test
+    public void findDescendants() {
+        assertTrue(CollectionUtils.disjunction(realmDAO.findAll(), realmDAO.findDescendants(realmDAO.getRoot())).
+                isEmpty());
+    }
+
+    @Test
+    public void findAll() {
+        List<Realm> list = realmDAO.findAll();
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+        for (Realm realm : list) {
+            assertNotNull(realm);
+        }
+    }
+
+    @Test
+    public void save() {
+        Realm realm = entityFactory.newEntity(Realm.class);
+        realm.setName("last");
+        realm.setParent(realmDAO.find("/even/two"));
+        assertNull(realm.getKey());
+
+        Realm actual = realmDAO.save(realm);
+        assertNotNull(actual.getKey());
+        assertEquals("last", actual.getName());
+        assertEquals("/even/two/last", actual.getFullPath());
+        assertEquals(realmDAO.find("/even/two"), actual.getParent());
+        assertEquals(5L, realm.getAccountPolicy().getKey(), 0);
+        assertEquals(2L, realm.getPasswordPolicy().getKey(), 0);
+
+        realm = actual;
+        realm.setAccountPolicy((AccountPolicy) policyDAO.find(6L));
+        realm.setPasswordPolicy((PasswordPolicy) policyDAO.find(4L));
+
+        actual = realmDAO.save(realm);
+        assertEquals(6L, actual.getAccountPolicy().getKey(), 0);
+        assertEquals(4L, actual.getPasswordPolicy().getKey(), 0);
+    }
+
+    @Test
+    public void saveInvalidName() {
+        Realm realm = entityFactory.newEntity(Realm.class);
+        realm.setName(" a name");
+        realm.setParent(realmDAO.getRoot());
+
+        try {
+            realmDAO.save(realm);
+            fail();
+        } catch (InvalidEntityException e) {
+            assertTrue(e.hasViolation(EntityViolationType.InvalidRealm));
+        }
+    }
+
+    @Test
+    public void saveNullParent() {
+        Realm realm = entityFactory.newEntity(Realm.class);
+        realm.setName("name");
+        realm.setParent(null);
+
+        try {
+            realmDAO.save(realm);
+            fail();
+        } catch (InvalidEntityException e) {
+            assertTrue(e.hasViolation(EntityViolationType.InvalidRealm));
+        }
+    }
+
+    @Test
+    public void delete() {
+        Realm realm = entityFactory.newEntity(Realm.class);
+        realm.setName("name");
+        realm.setParent(realmDAO.getRoot());
+
+        Realm actual = realmDAO.save(realm);
+        assertNotNull(actual);
+
+        Long key = actual.getKey();
+        assertNotNull(realmDAO.find(key));
+
+        realmDAO.delete(key);
+        assertNull(realmDAO.find(key));
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RelationshipTypeTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RelationshipTypeTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RelationshipTypeTest.java
new file mode 100644
index 0000000..9aee7f1
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RelationshipTypeTest.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO;
+import org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO;
+import org.apache.syncope.core.persistence.api.entity.RelationshipType;
+import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class RelationshipTypeTest extends AbstractTest {
+
+    @Autowired
+    private RelationshipTypeDAO relationshipTypeDAO;
+
+    @Autowired
+    private AnyObjectDAO anyObjectDAO;
+
+    @Test
+    public void find() {
+        RelationshipType inclusion = relationshipTypeDAO.find("inclusion");
+        assertNotNull(inclusion);
+        assertEquals("inclusion", inclusion.getKey());
+    }
+
+    @Test
+    public void findAll() {
+        List<RelationshipType> list = relationshipTypeDAO.findAll();
+        assertFalse(list.isEmpty());
+    }
+
+    @Test
+    public void save() {
+        RelationshipType newType = entityFactory.newEntity(RelationshipType.class);
+        newType.setKey("new type");
+        newType.setDescription("description");
+
+        newType = relationshipTypeDAO.save(newType);
+        assertNotNull(newType);
+        assertEquals("description", newType.getDescription());
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveInvalidName() {
+        RelationshipType newType = entityFactory.newEntity(RelationshipType.class);
+        newType.setKey("membership");
+        relationshipTypeDAO.save(newType);
+    }
+
+    @Test
+    public void delete() {
+        RelationshipType type = relationshipTypeDAO.find("neighborhood");
+        assertNotNull(type);
+
+        relationshipTypeDAO.delete(type.getKey());
+        assertNull(relationshipTypeDAO.find("neighborhood"));
+    }
+
+    @Test
+    public void deleteOnAnyObject() {
+        RelationshipType neighborhood = relationshipTypeDAO.find("neighborhood");
+        assertNotNull(neighborhood);
+
+        AnyObject anyObject = anyObjectDAO.find(1L);
+        assertNotNull(anyObject);
+        assertNotNull(anyObject.getRelationship(neighborhood));
+
+        relationshipTypeDAO.delete("neighborhood");
+
+        relationshipTypeDAO.flush();
+
+        anyObject = anyObjectDAO.find(1L);
+        assertNotNull(anyObject);
+        assertTrue(anyObject.getRelationships().isEmpty());
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ReportTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ReportTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ReportTest.java
new file mode 100644
index 0000000..4318813
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ReportTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.common.lib.report.UserReportletConf;
+import org.apache.syncope.core.persistence.api.dao.ReportDAO;
+import org.apache.syncope.core.persistence.api.entity.Report;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ReportTest extends AbstractTest {
+
+    @Autowired
+    private ReportDAO reportDAO;
+
+    @Test
+    public void find() {
+        Report report = reportDAO.find(1L);
+        assertNotNull(report);
+
+        report = reportDAO.find(10L);
+        assertNull(report);
+    }
+
+    @Test
+    public void findAll() {
+        List<Report> reports = reportDAO.findAll();
+        assertNotNull(reports);
+        assertEquals(1, reports.size());
+    }
+
+    @Test
+    public void save() {
+        int beforeCount = reportDAO.count();
+
+        Report report = entityFactory.newEntity(Report.class);
+        report.setName("new report");
+        report.addReportletConf(new UserReportletConf("first"));
+        report.addReportletConf(new UserReportletConf("second"));
+
+        report = reportDAO.save(report);
+        assertNotNull(report);
+        assertNotNull(report.getKey());
+
+        int afterCount = reportDAO.count();
+        assertEquals(afterCount, beforeCount + 1);
+    }
+
+    @Test
+    public void delete() {
+        Report report = reportDAO.find(1L);
+        assertNotNull(report);
+
+        reportDAO.delete(1L);
+
+        report = reportDAO.find(1L);
+        assertNull(report);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ResourceTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ResourceTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ResourceTest.java
new file mode 100644
index 0000000..e5cee24
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/ResourceTest.java
@@ -0,0 +1,372 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.Predicate;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.common.lib.types.IntMappingType;
+import org.apache.syncope.common.lib.types.MappingPurpose;
+import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
+import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
+import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
+import org.apache.syncope.core.persistence.api.entity.ConnInstance;
+import org.apache.syncope.core.persistence.api.entity.resource.ExternalResource;
+import org.apache.syncope.core.persistence.api.entity.resource.Mapping;
+import org.apache.syncope.core.persistence.api.entity.resource.MappingItem;
+import org.apache.syncope.core.persistence.api.entity.resource.Provision;
+import org.apache.syncope.core.persistence.jpa.AbstractTest;
+import org.identityconnectors.framework.common.objects.ObjectClass;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class ResourceTest extends AbstractTest {
+
+    @Autowired
+    private ExternalResourceDAO resourceDAO;
+
+    @Autowired
+    private AnyTypeDAO anyTypeDAO;
+
+    @Test
+    public void findById() {
+        ExternalResource resource = resourceDAO.find("ws-target-resource-1");
+        assertNotNull("findById did not work", resource);
+
+        ConnInstance connector = resource.getConnector();
+        assertNotNull("connector not found", connector);
+        assertEquals("invalid connector name",
+                "net.tirasa.connid.bundles.soap.WebServiceConnector", connector.getConnectorName());
+        assertEquals("invalid bundle name", "net.tirasa.connid.bundles.soap", connector.getBundleName());
+
+        Mapping mapping = resource.getProvision(anyTypeDAO.findUser()).getMapping();
+        assertFalse("no mapping specified", mapping.getItems().isEmpty());
+
+        assertTrue(CollectionUtils.exists(mapping.getItems(), new Predicate<MappingItem>() {
+
+            @Override
+            public boolean evaluate(final MappingItem item) {
+                return 100 == item.getKey();
+            }
+        }));
+    }
+
+    @Test
+    public void findAll() {
+        List<ExternalResource> resources = resourceDAO.findAll();
+        assertNotNull(resources);
+        assertEquals(19, resources.size());
+    }
+
+    @Test
+    public void findAllByPriority() {
+        List<ExternalResource> resources = resourceDAO.findAllByPriority();
+        assertNotNull(resources);
+        assertFalse(resources.isEmpty());
+    }
+
+    @Test
+    public void getConnObjectKey() {
+        ExternalResource resource = resourceDAO.find("ws-target-resource-2");
+        assertNotNull(resource);
+        assertEquals("fullname",
+                resource.getProvision(anyTypeDAO.findUser()).getMapping().getConnObjectKeyItem().getIntAttrName());
+    }
+
+    @Test
+    public void save() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("ws-target-resource-basic-save");
+        resource.setPropagationPriority(2);
+        resource.setPropagationPrimary(true);
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
+        connObjectKey.setExtAttrName("username");
+        connObjectKey.setIntAttrName("fullname");
+        connObjectKey.setIntMappingType(IntMappingType.UserKey);
+        connObjectKey.setPurpose(MappingPurpose.BOTH);
+        mapping.setConnObjectKeyItem(connObjectKey);
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        // save the resource
+        ExternalResource actual = resourceDAO.save(resource);
+
+        assertNotNull(actual);
+        assertNotNull(actual.getConnector());
+        assertNotNull(actual.getProvision(anyTypeDAO.findUser()).getMapping());
+        assertFalse(actual.getProvision(anyTypeDAO.findUser()).getMapping().getItems().isEmpty());
+        assertEquals(Integer.valueOf(2), actual.getPropagationPriority());
+        assertTrue(actual.isPropagationPrimary());
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveInvalidMappingIntAttr() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("ws-target-resource-basic-save-invalid");
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
+        connObjectKey.setConnObjectKey(true);
+        connObjectKey.setIntMappingType(IntMappingType.UserPlainSchema);
+        mapping.add(connObjectKey);
+
+        // save the resource
+        resourceDAO.save(resource);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void saveInvalidConnObjectKeyMapping() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("ws-target-resource-basic-save-invalid");
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
+        connObjectKey.setConnObjectKey(true);
+        connObjectKey.setIntMappingType(IntMappingType.UserVirtualSchema);
+        mapping.setConnObjectKeyItem(connObjectKey);
+
+        // save the resource
+        resourceDAO.save(resource);
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveInvalidMappingExtAttr() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("ws-target-resource-basic-save-invalid");
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        MappingItem item = entityFactory.newEntity(MappingItem.class);
+        item.setConnObjectKey(true);
+        item.setIntAttrName("fullname");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        mapping.add(item);
+
+        item = entityFactory.newEntity(MappingItem.class);
+        item.setIntAttrName("userId");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        mapping.add(item);
+
+        resourceDAO.save(resource);
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void saveInvalidProvision() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("invalidProvision");
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        MappingItem connObjectKey = entityFactory.newEntity(MappingItem.class);
+        connObjectKey.setExtAttrName("username");
+        connObjectKey.setIntAttrName("fullname");
+        connObjectKey.setIntMappingType(IntMappingType.UserKey);
+        connObjectKey.setPurpose(MappingPurpose.BOTH);
+        mapping.setConnObjectKeyItem(connObjectKey);
+
+        provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findGroup());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        // save the resource
+        resourceDAO.save(resource);
+    }
+
+    @Test
+    public void saveWithGroupMappingType() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("ws-target-resource-basic-save-invalid");
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        MappingItem item = entityFactory.newEntity(MappingItem.class);
+        item.setIntAttrName("fullname");
+        item.setExtAttrName("fullname");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setConnObjectKeyItem(item);
+
+        item = entityFactory.newEntity(MappingItem.class);
+        item.setIntAttrName("icon");
+        item.setExtAttrName("icon");
+        item.setIntMappingType(IntMappingType.GroupPlainSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.add(item);
+
+        item = entityFactory.newEntity(MappingItem.class);
+        item.setIntAttrName("mderiveddata");
+        item.setExtAttrName("mderiveddata");
+        item.setIntMappingType(IntMappingType.AnyObjectDerivedSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.add(item);
+
+        // save the resource
+        ExternalResource actual = resourceDAO.save(resource);
+        assertNotNull(actual);
+
+        int items = 0;
+        for (MappingItem mapItem : actual.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) {
+            items++;
+
+            if ("icon".equals(mapItem.getIntAttrName())) {
+                assertTrue(IntMappingType.contains(AnyTypeKind.GROUP, mapItem.getIntMappingType().toString()));
+            }
+            if ("mderiveddata".equals(mapItem.getIntAttrName())) {
+                assertTrue(IntMappingType.contains(AnyTypeKind.ANY_OBJECT, mapItem.getIntMappingType().toString()));
+            }
+        }
+        assertEquals(3, items);
+    }
+
+    @Test
+    public void delete() {
+        ExternalResource resource = resourceDAO.find("ws-target-resource-2");
+        assertNotNull(resource);
+
+        resourceDAO.delete(resource.getKey());
+
+        ExternalResource actual = resourceDAO.find("ws-target-resource-2");
+        assertNull(actual);
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+
+        try {
+            resourceDAO.save(resource);
+            fail();
+        } catch (InvalidEntityException e) {
+            assertTrue(e.hasViolation(EntityViolationType.InvalidName));
+        }
+    }
+
+    @Test(expected = InvalidEntityException.class)
+    public void issueSYNCOPE645() {
+        ExternalResource resource = entityFactory.newEntity(ExternalResource.class);
+        resource.setKey("ws-target-resource-basic-save-invalid");
+
+        ConnInstance connector = resourceDAO.find("ws-target-resource-1").getConnector();
+        resource.setConnector(connector);
+
+        Provision provision = entityFactory.newEntity(Provision.class);
+        provision.setAnyType(anyTypeDAO.findUser());
+        provision.setObjectClass(ObjectClass.ACCOUNT);
+        provision.setResource(resource);
+        resource.add(provision);
+
+        Mapping mapping = entityFactory.newEntity(Mapping.class);
+        mapping.setProvision(provision);
+        provision.setMapping(mapping);
+
+        final MappingItem item = entityFactory.newEntity(MappingItem.class);
+        item.setIntAttrName("icon");
+        item.setExtAttrName("icon");
+        item.setIntMappingType(IntMappingType.GroupPlainSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setConnObjectKeyItem(item);
+
+        // save the resource
+        ExternalResource actual = resourceDAO.save(resource);
+        assertNotNull(actual);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RoleTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RoleTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RoleTest.java
new file mode 100644
index 0000000..bf2c012
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/RoleTest.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+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.common.lib.types.Entitlement;
+import org.apache.syncope.core.persistence.api.dao.RealmDAO;
+import org.apache.syncope.core.persistence.api.dao.RoleDAO;
+import org.apache.syncope.core.persistence.api.entity.Role;
+import org.apache.syncope.core.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 RoleDAO roleDAO;
+
+    @Autowired
+    private RealmDAO realmDAO;
+
+    @Test
+    public void find() {
+        Role role1 = roleDAO.find(2L);
+        assertNotNull(role1);
+        assertNotNull(role1.getName());
+        assertFalse(role1.getRealms().isEmpty());
+        assertFalse(role1.getEntitlements().isEmpty());
+        assertTrue(role1.getEntitlements().contains(Entitlement.USER_LIST));
+
+        Role role2 = roleDAO.find(role1.getName());
+        assertEquals(role1, role2);
+    }
+
+    @Test
+    public void findAll() {
+        List<Role> list = roleDAO.findAll();
+        assertNotNull(list);
+        assertFalse(list.isEmpty());
+        for (Role role : list) {
+            assertNotNull(role);
+        }
+    }
+
+    @Test
+    public void save() {
+        Role role = entityFactory.newEntity(Role.class);
+        role.setName("new");
+        role.addRealm(realmDAO.getRoot());
+        role.addRealm(realmDAO.find("/even/two"));
+        role.getEntitlements().add(Entitlement.LOG_LIST);
+        role.getEntitlements().add(Entitlement.LOG_SET_LEVEL);
+
+        Role actual = roleDAO.save(role);
+        assertNotNull(actual);
+    }
+
+    @Test
+    public void delete() {
+        assertNotNull(roleDAO.find(3L));
+
+        roleDAO.delete(3L);
+        assertNull(roleDAO.find(3L));
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d8927ef4/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SecurityQuestionTest.java
----------------------------------------------------------------------
diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SecurityQuestionTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SecurityQuestionTest.java
new file mode 100644
index 0000000..f17146e
--- /dev/null
+++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/inner/SecurityQuestionTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.persistence.jpa.inner;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.List;
+import org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO;
+import org.apache.syncope.core.persistence.api.entity.user.SecurityQuestion;
+import org.apache.syncope.core.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;
+
+    @Test
+    public void find() {
+        SecurityQuestion securityQuestion = securityQuestionDAO.find(1L);
+        assertNotNull(securityQuestion);
+        assertNotNull(securityQuestion.getContent());
+    }
+
+    @Test
+    public void findAll() {
+        List<SecurityQuestion> securityQuestions = securityQuestionDAO.findAll();
+        assertNotNull(securityQuestions);
+        assertFalse(securityQuestions.isEmpty());
+    }
+
+    @Test
+    public void save() {
+        SecurityQuestion securityQuestion = entityFactory.newEntity(SecurityQuestion.class);
+        securityQuestion.setContent("What is your favorite pet's name?");
+
+        SecurityQuestion actual = securityQuestionDAO.save(securityQuestion);
+        assertNotNull(actual);
+        assertNotNull(actual.getKey());
+    }
+
+    @Test
+    public void delete() {
+        securityQuestionDAO.delete(1L);
+        assertNull(securityQuestionDAO.find(1L));
+    }
+}