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/23 17:41:34 UTC

[12/15] syncope git commit: FIT server integration tests

http://git-wip-us.apache.org/repos/asf/syncope/blob/80589a1b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PlainSchemaITCase.java
----------------------------------------------------------------------
diff --git a/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PlainSchemaITCase.java b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PlainSchemaITCase.java
new file mode 100644
index 0000000..448d1fa
--- /dev/null
+++ b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PlainSchemaITCase.java
@@ -0,0 +1,317 @@
+/*
+ * 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.fit.server.reference;
+
+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.security.AccessControlException;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.SerializationUtils;
+import org.apache.syncope.common.lib.AttributableOperations;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.mod.UserMod;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.EntityViolationType;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.rest.api.service.SchemaService;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class PlainSchemaITCase extends AbstractITCase {
+
+    private PlainSchemaTO buildPlainSchemaTO(final String name, final AttrSchemaType type) {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey(name + getUUIDString());
+        schemaTO.setType(type);
+        return schemaTO;
+    }
+
+    @Test
+    public void create() {
+        PlainSchemaTO schemaTO = buildPlainSchemaTO("testAttribute", AttrSchemaType.String);
+        schemaTO.setMandatoryCondition("false");
+
+        PlainSchemaTO newPlainSchemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+        assertEquals(schemaTO, newPlainSchemaTO);
+
+        newPlainSchemaTO = createSchema(AttributableType.MEMBERSHIP, SchemaType.PLAIN, schemaTO);
+        assertEquals(schemaTO, newPlainSchemaTO);
+    }
+
+    @Test
+    public void createWithNotPermittedName() {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey("failedLogins");
+        schemaTO.setType(AttrSchemaType.String);
+
+        try {
+            createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+            fail("This should not be reacheable");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+
+            assertTrue(e.getElements().iterator().next().toString().
+                    contains(EntityViolationType.InvalidName.name()));
+        }
+    }
+
+    @Test
+    public void createREnumWithoutEnumeration() {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey("enumcheck");
+        schemaTO.setType(AttrSchemaType.Enum);
+
+        try {
+            createSchema(AttributableType.ROLE, SchemaType.PLAIN, schemaTO);
+            fail("This should not be reacheable");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+
+            assertTrue(e.getElements().iterator().next().toString().
+                    contains(EntityViolationType.InvalidSchemaEnum.name()));
+        }
+    }
+
+    @Test
+    public void createUEnumWithoutEnumeration() {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey("enumcheck");
+        schemaTO.setType(AttrSchemaType.Enum);
+
+        try {
+            createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+            fail("This should not be reacheable");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+
+            assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidSchemaEnum.name()));
+        }
+    }
+
+    @Test
+    public void createEncrypted() {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey("encrypted");
+        schemaTO.setType(AttrSchemaType.Encrypted);
+        schemaTO.setCipherAlgorithm(CipherAlgorithm.AES);
+        schemaTO.setSecretKey("huhadfhsjfsfsdkj!####");
+
+        createSchema(AttributableType.MEMBERSHIP, SchemaType.PLAIN, schemaTO);
+    }
+
+    @Test
+    public void createBinary() {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey("x509certificate");
+        schemaTO.setType(AttrSchemaType.Binary);
+        schemaTO.setMimeType("application/x-x509-ca-cert");
+
+        createSchema(AttributableType.ROLE, SchemaType.PLAIN, schemaTO);
+    }
+
+    @Test
+    public void delete() {
+        PlainSchemaTO schemaTO = buildPlainSchemaTO("todelete", AttrSchemaType.String);
+        schemaTO.setMandatoryCondition("false");
+        createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+
+        schemaService.delete(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey());
+        PlainSchemaTO firstname = null;
+        try {
+            firstname = schemaService.read(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey());
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+        assertNull(firstname);
+    }
+
+    @Test
+    public void list() {
+        List<PlainSchemaTO> userSchemas = schemaService.list(AttributableType.USER, SchemaType.PLAIN);
+        assertFalse(userSchemas.isEmpty());
+        for (PlainSchemaTO schemaTO : userSchemas) {
+            assertNotNull(schemaTO);
+        }
+
+        List<PlainSchemaTO> roleSchemas = schemaService.list(AttributableType.ROLE, SchemaType.PLAIN);
+        assertFalse(roleSchemas.isEmpty());
+        for (PlainSchemaTO schemaTO : roleSchemas) {
+            assertNotNull(schemaTO);
+        }
+
+        List<PlainSchemaTO> membershipSchemas = schemaService.list(AttributableType.MEMBERSHIP, SchemaType.PLAIN);
+        assertFalse(membershipSchemas.isEmpty());
+        for (PlainSchemaTO schemaTO : membershipSchemas) {
+            assertNotNull(schemaTO);
+        }
+    }
+
+    @Test
+    public void update() {
+        PlainSchemaTO schemaTO = schemaService.read(AttributableType.ROLE, SchemaType.PLAIN, "icon");
+        assertNotNull(schemaTO);
+
+        schemaService.update(AttributableType.ROLE, SchemaType.PLAIN, schemaTO.getKey(), schemaTO);
+        PlainSchemaTO updatedTO = schemaService.read(AttributableType.ROLE, SchemaType.PLAIN, "icon");
+        assertEquals(schemaTO, updatedTO);
+
+        updatedTO.setType(AttrSchemaType.Date);
+        try {
+            schemaService.update(AttributableType.ROLE, SchemaType.PLAIN, schemaTO.getKey(), updatedTO);
+            fail("This should not be reacheable");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+        }
+    }
+
+    @Test
+    public void issue258() {
+        PlainSchemaTO schemaTO = new PlainSchemaTO();
+        schemaTO.setKey("schema_issue258");
+        schemaTO.setType(AttrSchemaType.Double);
+
+        schemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+        assertNotNull(schemaTO);
+
+        UserTO userTO = UserITCase.getUniqueSampleTO("issue258@syncope.apache.org");
+        userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1.2"));
+
+        userTO = createUser(userTO);
+        assertNotNull(userTO);
+
+        schemaTO.setType(AttrSchemaType.Long);
+        try {
+            schemaService.update(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey(), schemaTO);
+            fail("This should not be reacheable");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+        }
+    }
+
+    @Test
+    public void issue259() {
+        PlainSchemaTO schemaTO = buildPlainSchemaTO("schema_issue259", AttrSchemaType.Double);
+        schemaTO.setUniqueConstraint(true);
+
+        schemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+        assertNotNull(schemaTO);
+
+        UserTO userTO = UserITCase.getUniqueSampleTO("issue259@syncope.apache.org");
+        userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1"));
+        userTO = createUser(userTO);
+        assertNotNull(userTO);
+
+        UserTO newUserTO = SerializationUtils.clone(userTO);
+        MembershipTO membership = new MembershipTO();
+        membership.setRoleId(2L);
+        newUserTO.getMemberships().add(membership);
+
+        UserMod userMod = AttributableOperations.diff(newUserTO, userTO);
+
+        userTO = userService.update(userMod.getKey(), userMod).readEntity(UserTO.class);
+        assertNotNull(userTO);
+    }
+
+    @Test
+    public void issue260() {
+        PlainSchemaTO schemaTO = buildPlainSchemaTO("schema_issue260", AttrSchemaType.Double);
+        schemaTO.setUniqueConstraint(true);
+
+        schemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO);
+        assertNotNull(schemaTO);
+
+        UserTO userTO = UserITCase.getUniqueSampleTO("issue260@syncope.apache.org");
+        userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1.2"));
+        userTO = createUser(userTO);
+        assertNotNull(userTO);
+
+        schemaTO.setUniqueConstraint(false);
+        try {
+            schemaService.update(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey(), schemaTO);
+            fail("This should not be reacheable");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+        }
+    }
+
+    @Test
+    public void issueSYNCOPE323() {
+        PlainSchemaTO actual = schemaService.read(AttributableType.ROLE, SchemaType.PLAIN, "icon");
+        assertNotNull(actual);
+
+        try {
+            createSchema(AttributableType.ROLE, SchemaType.PLAIN, actual);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
+            assertEquals(ClientExceptionType.EntityExists, e.getType());
+        }
+
+        actual.setKey(null);
+        try {
+            createSchema(AttributableType.ROLE, SchemaType.PLAIN, actual);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
+            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
+        }
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        PlainSchemaTO schema = buildPlainSchemaTO("http://schemas.examples.org/security/authorization/organizationUnit",
+                AttrSchemaType.Double);
+
+        try {
+            createSchema(AttributableType.ROLE, SchemaType.PLAIN, schema);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+            assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidName.name()));
+        }
+    }
+
+    @Test
+    public void anonymous() {
+        SchemaService unauthenticated = clientFactory.createAnonymous().getService(SchemaService.class);
+        try {
+            unauthenticated.list(AttributableType.USER, SchemaType.VIRTUAL);
+            fail();
+        } catch (AccessControlException e) {
+            assertNotNull(e);
+        }
+
+        SchemaService anonymous = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(SchemaService.class);
+        assertFalse(anonymous.list(AttributableType.USER, SchemaType.VIRTUAL).isEmpty());
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/80589a1b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PolicyITCase.java
----------------------------------------------------------------------
diff --git a/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PolicyITCase.java b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PolicyITCase.java
new file mode 100644
index 0000000..075cdd9
--- /dev/null
+++ b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/PolicyITCase.java
@@ -0,0 +1,238 @@
+/*
+ * 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.fit.server.reference;
+
+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 static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AccountPolicyTO;
+import org.apache.syncope.common.lib.to.PasswordPolicyTO;
+import org.apache.syncope.common.lib.to.SyncPolicyTO;
+import org.apache.syncope.common.lib.types.AccountPolicySpec;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+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.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class PolicyITCase extends AbstractITCase {
+
+    private SyncPolicyTO buildSyncPolicyTO() {
+        SyncPolicyTO policy = new SyncPolicyTO();
+
+        SyncPolicySpec spec = new SyncPolicySpec();
+        spec.setUserJavaRule(TestSyncRule.class.getName());
+
+        policy.setSpecification(spec);
+        policy.setDescription("Sync policy");
+
+        return policy;
+    }
+
+    @Test
+    public void listByType() {
+        List<SyncPolicyTO> policyTOs = policyService.list(PolicyType.SYNC);
+
+        assertNotNull(policyTOs);
+        assertFalse(policyTOs.isEmpty());
+    }
+
+    @Test
+    public void getAccountPolicy() {
+        AccountPolicyTO policyTO = policyService.read(6L);
+
+        assertNotNull(policyTO);
+        assertTrue(policyTO.getUsedByResources().isEmpty());
+        assertEquals(Arrays.asList(6L, 7L, 10L, 14L), policyTO.getUsedByRoles());
+    }
+
+    @Test
+    public void getPasswordPolicy() {
+        PasswordPolicyTO policyTO = policyService.read(4L);
+
+        assertNotNull(policyTO);
+        assertTrue(policyTO.getUsedByResources().contains(RESOURCE_NAME_NOPROPAGATION));
+        assertEquals(Arrays.asList(6L, 7L, 10L, 8L), policyTO.getUsedByRoles());
+    }
+
+    @Test
+    public void getSyncPolicy() {
+        SyncPolicyTO policyTO = policyService.read(1L);
+
+        assertNotNull(policyTO);
+        assertTrue(policyTO.getUsedByRoles().isEmpty());
+    }
+
+    @Test
+    public void getGlobalAccountPolicy() {
+        AccountPolicyTO policyTO = policyService.readGlobal(PolicyType.ACCOUNT);
+
+        assertNotNull(policyTO);
+        assertEquals(PolicyType.GLOBAL_ACCOUNT, policyTO.getType());
+    }
+
+    @Test
+    public void getGlobalPasswordPolicy() {
+        PasswordPolicyTO policyTO = policyService.readGlobal(PolicyType.PASSWORD);
+
+        assertNotNull(policyTO);
+        assertEquals(PolicyType.GLOBAL_PASSWORD, policyTO.getType());
+        assertEquals(8, policyTO.getSpecification().getMinLength());
+        assertFalse(policyTO.getUsedByResources().contains(RESOURCE_NAME_NOPROPAGATION));
+    }
+
+    @Test
+    public void getGlobalSyncPolicy() {
+        SyncPolicyTO policyTO = policyService.readGlobal(PolicyType.SYNC);
+
+        assertNotNull(policyTO);
+        assertEquals(PolicyType.GLOBAL_SYNC, policyTO.getType());
+        assertFalse(policyTO.getUsedByResources().contains(RESOURCE_NAME_CSV));
+        assertFalse(policyTO.getUsedByResources().contains(RESOURCE_NAME_WS2));
+        assertTrue(policyTO.getUsedByRoles().isEmpty());
+    }
+
+    @Test
+    public void createWithException() {
+        PasswordPolicyTO policy = new PasswordPolicyTO(true);
+        policy.setSpecification(new PasswordPolicySpec());
+        policy.setDescription("global password policy");
+
+        try {
+            createPolicy(policy);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPolicy, e.getType());
+        }
+    }
+
+    @Test
+    public void createMissingDescription() {
+        SyncPolicyTO policy = new SyncPolicyTO();
+        policy.setSpecification(new SyncPolicySpec());
+
+        try {
+            createPolicy(policy);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPolicy, e.getType());
+        }
+    }
+
+    @Test
+    public void create() {
+        SyncPolicyTO policy = buildSyncPolicyTO();
+
+        SyncPolicyTO policyTO = createPolicy(policy);
+
+        assertNotNull(policyTO);
+        assertEquals(PolicyType.SYNC, policyTO.getType());
+        assertEquals(TestSyncRule.class.getName(), policyTO.getSpecification().getUserJavaRule());
+    }
+
+    @Test
+    public void update() {
+        // get global password
+        PasswordPolicyTO globalPolicy = policyService.read(2L);
+
+        PasswordPolicyTO policy = new PasswordPolicyTO();
+        policy.setDescription("A simple password policy");
+        policy.setSpecification(globalPolicy.getSpecification());
+
+        // create a new password policy using global password as a template
+        policy = createPolicy(policy);
+
+        // read new password policy
+        policy = policyService.read(policy.getKey());
+
+        assertNotNull("find to update did not work", policy);
+
+        PasswordPolicySpec policySpec = policy.getSpecification();
+        policySpec.setMaxLength(22);
+        policy.setSpecification(policySpec);
+
+        // update new password policy
+        policyService.update(policy.getKey(), policy);
+        policy = policyService.read(policy.getKey());
+
+        assertNotNull(policy);
+        assertEquals(PolicyType.PASSWORD, policy.getType());
+        assertEquals(22, policy.getSpecification().getMaxLength());
+        assertEquals(8, policy.getSpecification().getMinLength());
+    }
+
+    @Test
+    public void delete() {
+        SyncPolicyTO policy = buildSyncPolicyTO();
+
+        SyncPolicyTO policyTO = createPolicy(policy);
+        assertNotNull(policyTO);
+
+        policyService.delete(policyTO.getKey());
+
+        try {
+            policyService.read(policyTO.getKey());
+            fail();
+        } catch (SyncopeClientException e) {
+            assertNotNull(e);
+        }
+    }
+
+    @Test
+    public void getCorrelationRules() {
+        assertEquals(1, policyService.getSyncCorrelationRuleClasses().size());
+    }
+
+    @Test
+    public void issueSYNCOPE466() {
+        PasswordPolicyTO policy = policyService.read(4L);
+        assertEquals(PolicyType.PASSWORD, policy.getType());
+
+        policy.setType(PolicyType.GLOBAL_PASSWORD);
+        try {
+            policyService.update(policy.getKey(), policy);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidPolicy, e.getType());
+        }
+    }
+
+    @Test
+    public void issueSYNCOPE553() {
+        AccountPolicyTO policy = new AccountPolicyTO(false);
+        policy.setDescription("SYNCOPE553");
+
+        final AccountPolicySpec accountPolicySpec = new AccountPolicySpec();
+        accountPolicySpec.setMinLength(3);
+        accountPolicySpec.setMaxLength(8);
+        policy.setSpecification(accountPolicySpec);
+
+        policy = createPolicy(policy);
+        assertNotNull(policy);
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/80589a1b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ReportITCase.java
----------------------------------------------------------------------
diff --git a/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ReportITCase.java b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ReportITCase.java
new file mode 100644
index 0000000..8102fe0
--- /dev/null
+++ b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ReportITCase.java
@@ -0,0 +1,252 @@
+/*
+ * 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.fit.server.reference;
+
+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 static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import org.apache.commons.io.IOUtils;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.report.UserReportletConf;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.ReportExecTO;
+import org.apache.syncope.common.lib.to.ReportTO;
+import org.apache.syncope.common.lib.types.ReportExecExportFormat;
+import org.apache.syncope.common.lib.types.ReportExecStatus;
+import org.apache.syncope.common.lib.wrap.ReportletConfClass;
+import org.apache.syncope.common.rest.api.service.ReportService;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class ReportITCase extends AbstractITCase {
+
+    private ReportTO createReport(final ReportTO report) {
+        Response response = reportService.create(report);
+        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+        return getObject(response.getLocation(), ReportService.class, ReportTO.class);
+    }
+
+    @Test
+    public void getReportletClasses() {
+        List<ReportletConfClass> reportletClasses = reportService.getReportletConfClasses();
+        assertNotNull(reportletClasses);
+        assertFalse(reportletClasses.isEmpty());
+    }
+
+    @Test
+    public void list() {
+        PagedResult<ReportTO> reports = reportService.list();
+        assertNotNull(reports);
+        assertFalse(reports.getResult().isEmpty());
+        for (ReportTO report : reports.getResult()) {
+            assertNotNull(report);
+        }
+    }
+
+    @Test
+    public void read() {
+        ReportTO reportTO = reportService.read(1L);
+
+        assertNotNull(reportTO);
+        assertNotNull(reportTO.getExecutions());
+        assertFalse(reportTO.getExecutions().isEmpty());
+    }
+
+    @Test
+    public void readExecution() {
+        ReportExecTO reportExecTO = reportService.readExecution(1L);
+        assertNotNull(reportExecTO);
+    }
+
+    @Test
+    public void create() {
+        ReportTO report = new ReportTO();
+        report.setName("testReportForCreate" + getUUIDString());
+        report.getReportletConfs().add(new UserReportletConf("first"));
+        report.getReportletConfs().add(new UserReportletConf("second"));
+
+        report = createReport(report);
+        assertNotNull(report);
+
+        ReportTO actual = reportService.read(report.getKey());
+        assertNotNull(actual);
+
+        assertEquals(actual, report);
+    }
+
+    @Test
+    public void update() {
+        ReportTO report = new ReportTO();
+        report.setName("testReportForUpdate" + getUUIDString());
+
+        report.getReportletConfs().add(new UserReportletConf("first"));
+        report.getReportletConfs().add(new UserReportletConf("second"));
+
+        report = createReport(report);
+        assertNotNull(report);
+        assertEquals(2, report.getReportletConfs().size());
+
+        report.getReportletConfs().add(new UserReportletConf("last"));
+
+        reportService.update(report.getKey(), report);
+        ReportTO updated = reportService.read(report.getKey());
+        assertNotNull(updated);
+        assertEquals(3, updated.getReportletConfs().size());
+    }
+
+    @Test
+    public void delete() {
+        ReportTO report = new ReportTO();
+        report.setName("testReportForDelete" + getUUIDString());
+        report.getReportletConfs().add(new UserReportletConf("first"));
+        report.getReportletConfs().add(new UserReportletConf("second"));
+
+        report = createReport(report);
+        assertNotNull(report);
+
+        reportService.delete(report.getKey());
+
+        try {
+            reportService.read(report.getKey());
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+    }
+
+    private void checkExport(final Long execId, final ReportExecExportFormat fmt) throws IOException {
+        final Response response = reportService.exportExecutionResult(execId, fmt);
+        assertNotNull(response);
+        assertEquals(Response.Status.OK.getStatusCode(), response.getStatusInfo().getStatusCode());
+        assertNotNull(response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION));
+        assertTrue(response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION).
+                endsWith("." + fmt.name().toLowerCase()));
+
+        Object entity = response.getEntity();
+        assertTrue(entity instanceof InputStream);
+        assertFalse(IOUtils.toString((InputStream) entity, SyncopeConstants.DEFAULT_ENCODING).isEmpty());
+    }
+
+    @Test
+    public void executeAndExport() throws IOException {
+        ReportTO reportTO = reportService.read(1L);
+        reportTO.setKey(0);
+        reportTO.setName("executeAndExport" + getUUIDString());
+        reportTO.getExecutions().clear();
+        reportTO = createReport(reportTO);
+        assertNotNull(reportTO);
+
+        ReportExecTO execution = reportService.execute(reportTO.getKey());
+        assertNotNull(execution);
+
+        int i = 0;
+        int maxit = 50;
+
+        // wait for report execution completion (executions incremented)
+        do {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+            }
+
+            reportTO = reportService.read(reportTO.getKey());
+
+            assertNotNull(reportTO);
+            assertNotNull(reportTO.getExecutions());
+
+            i++;
+        } while (reportTO.getExecutions().isEmpty()
+                || (!ReportExecStatus.SUCCESS.name().equals(reportTO.getExecutions().get(0).getStatus()) && i < maxit));
+        assertEquals(ReportExecStatus.SUCCESS.name(), reportTO.getExecutions().get(0).getStatus());
+
+        long execId = reportTO.getExecutions().get(0).getKey();
+
+        checkExport(execId, ReportExecExportFormat.XML);
+        checkExport(execId, ReportExecExportFormat.HTML);
+        checkExport(execId, ReportExecExportFormat.PDF);
+        checkExport(execId, ReportExecExportFormat.RTF);
+        checkExport(execId, ReportExecExportFormat.CSV);
+    }
+
+    @Test
+    public void issueSYNCOPE43() {
+        ReportTO reportTO = new ReportTO();
+        reportTO.setName("issueSYNCOPE43" + getUUIDString());
+        reportTO = createReport(reportTO);
+        assertNotNull(reportTO);
+
+        ReportExecTO execution = reportService.execute(reportTO.getKey());
+        assertNotNull(execution);
+
+        int maxit = 50;
+        do {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+            }
+
+            reportTO = reportService.read(reportTO.getKey());
+
+            maxit--;
+        } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+
+        assertEquals(1, reportTO.getExecutions().size());
+    }
+
+    @Test
+    public void issueSYNCOPE102() throws IOException {
+        // Create
+        ReportTO reportTO = reportService.read(1L);
+        reportTO.setKey(0);
+        reportTO.setName("issueSYNCOPE102" + getUUIDString());
+        reportTO = createReport(reportTO);
+        assertNotNull(reportTO);
+
+        // Execute (multiple requests)
+        for (int i = 0; i < 10; i++) {
+            ReportExecTO execution = reportService.execute(reportTO.getKey());
+            assertNotNull(execution);
+        }
+
+        // Wait for one execution
+        int maxit = 50;
+        do {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+            }
+
+            reportTO = reportService.read(reportTO.getKey());
+
+            maxit--;
+        } while (reportTO.getExecutions().isEmpty() && maxit > 0);
+        assertFalse(reportTO.getExecutions().isEmpty());
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/80589a1b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ResourceITCase.java
----------------------------------------------------------------------
diff --git a/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ResourceITCase.java b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ResourceITCase.java
new file mode 100644
index 0000000..6cb624a
--- /dev/null
+++ b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/ResourceITCase.java
@@ -0,0 +1,590 @@
+/*
+ * 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.fit.server.reference;
+
+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.security.AccessControlException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import javax.ws.rs.core.Response;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.BulkAction;
+import org.apache.syncope.common.lib.to.MappingItemTO;
+import org.apache.syncope.common.lib.to.MappingTO;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.ConnConfPropSchema;
+import org.apache.syncope.common.lib.types.ConnConfProperty;
+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.common.lib.wrap.PropagationActionClass;
+import org.apache.syncope.common.rest.api.service.ResourceService;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class ResourceITCase extends AbstractITCase {
+
+    private ResourceTO buildResourceTO(final String resourceName) {
+        ResourceTO resourceTO = new ResourceTO();
+
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setExtAttrName("userId");
+        item.setIntAttrName("userId");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.addItem(item);
+
+        item = new MappingItemTO();
+        item.setExtAttrName("username");
+        item.setIntAttrName("fullname");
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setAccountIdItem(item);
+
+        item = new MappingItemTO();
+        item.setExtAttrName("fullname");
+        item.setIntAttrName("cn");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setAccountid(false);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.addItem(item);
+
+        resourceTO.setUmapping(mapping);
+        return resourceTO;
+    }
+
+    @Test
+    public void getPropagationActionsClasses() {
+        List<PropagationActionClass> actions = resourceService.getPropagationActionsClasses();
+        assertNotNull(actions);
+        assertFalse(actions.isEmpty());
+    }
+
+    @Test
+    public void create() {
+        String resourceName = RESOURCE_NAME_CREATE;
+        ResourceTO resourceTO = buildResourceTO(resourceName);
+
+        Response response = resourceService.create(resourceTO);
+        ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+        assertNotNull(actual);
+
+        // check for existence
+        actual = resourceService.read(resourceName);
+        assertNotNull(actual);
+    }
+
+    @Test
+    public void createOverridingProps() {
+        String resourceName = "overriding-conn-conf-target-resource-create";
+        ResourceTO resourceTO = new ResourceTO();
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setExtAttrName("uid");
+        item.setIntAttrName("userId");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.addItem(item);
+
+        item = new MappingItemTO();
+        item.setExtAttrName("username");
+        item.setIntAttrName("fullname");
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setAccountid(true);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setAccountIdItem(item);
+
+        item = new MappingItemTO();
+        item.setExtAttrName("fullname");
+        item.setIntAttrName("cn");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setAccountid(false);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.addItem(item);
+
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+
+        resourceTO.setUmapping(mapping);
+
+        ConnConfProperty p = new ConnConfProperty();
+        ConnConfPropSchema schema = new ConnConfPropSchema();
+        schema.setType("java.lang.String");
+        schema.setName("endpoint");
+        schema.setRequired(true);
+        p.setSchema(schema);
+        p.getValues().add("http://invalidurl/");
+
+        Set<ConnConfProperty> connectorConfigurationProperties = new HashSet<ConnConfProperty>(Arrays.asList(p));
+        resourceTO.getConnConfProperties().addAll(connectorConfigurationProperties);
+
+        Response response = resourceService.create(resourceTO);
+        ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+        assertNotNull(actual);
+
+        // check the existence
+        actual = resourceService.read(resourceName);
+        assertNotNull(actual);
+    }
+
+    @Test
+    public void createWithSingleMappingItem() {
+        String resourceName = RESOURCE_NAME_CREATE_SINGLE;
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+
+        MappingTO umapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setExtAttrName("userId");
+        item.setAccountid(true);
+        item.setPurpose(MappingPurpose.PROPAGATION);
+        umapping.setAccountIdItem(item);
+
+        resourceTO.setUmapping(umapping);
+
+        MappingTO rmapping = new MappingTO();
+
+        item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.RoleId);
+        item.setExtAttrName("roleId");
+        item.setAccountid(true);
+        item.setPurpose(MappingPurpose.SYNCHRONIZATION);
+        rmapping.setAccountIdItem(item);
+
+        resourceTO.setRmapping(rmapping);
+
+        Response response = resourceService.create(resourceTO);
+        ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+
+        assertNotNull(actual);
+        assertNotNull(actual.getUmapping());
+        assertNotNull(actual.getUmapping().getItems());
+        assertNotNull(actual.getRmapping());
+        assertNotNull(actual.getRmapping().getItems());
+        assertEquals(MappingPurpose.SYNCHRONIZATION, actual.getRmapping().getAccountIdItem().getPurpose());
+        assertEquals(MappingPurpose.PROPAGATION, actual.getUmapping().getAccountIdItem().getPurpose());
+    }
+
+    @Test
+    public void createWithInvalidMapping() {
+        String resourceName = RESOURCE_NAME_CREATE_WRONG;
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setExtAttrName("userId");
+        item.setAccountid(true);
+        mapping.setAccountIdItem(item);
+
+        item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setExtAttrName("email");
+        // missing intAttrName ...
+        mapping.addItem(item);
+
+        resourceTO.setUmapping(mapping);
+
+        try {
+            createResource(resourceTO);
+            fail("Create should not have worked");
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
+            assertEquals("intAttrName", e.getElements().iterator().next());
+        }
+    }
+
+    @Test(expected = SyncopeClientException.class)
+    public void createWithoutExtAttr() {
+        String resourceName = RESOURCE_NAME_CREATE_WRONG;
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setExtAttrName("userId");
+        item.setAccountid(true);
+        mapping.setAccountIdItem(item);
+
+        item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setIntAttrName("usernane");
+        // missing extAttrName ...
+        mapping.addItem(item);
+
+        resourceTO.setUmapping(mapping);
+
+        createResource(resourceTO);
+    }
+
+    @Test
+    public void createWithPasswordPolicy() {
+        String resourceName = "res-with-password-policy";
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+        resourceTO.setPasswordPolicy(4L);
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setExtAttrName("userId");
+        item.setIntAttrName("userId");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setAccountid(true);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setAccountIdItem(item);
+
+        resourceTO.setUmapping(mapping);
+
+        Response response = resourceService.create(resourceTO);
+        ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+        assertNotNull(actual);
+
+        // check the existence
+        actual = resourceService.read(resourceName);
+        assertNotNull(actual);
+        assertNotNull(actual.getPasswordPolicy());
+        assertEquals(4L, (long) actual.getPasswordPolicy());
+    }
+
+    @Test
+    public void updateWithException() {
+        try {
+            ResourceTO resourceTO = new ResourceTO();
+            resourceTO.setKey("resourcenotfound");
+
+            resourceService.update(resourceTO.getKey(), resourceTO);
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+    }
+
+    @Test
+    public void update() {
+        String resourceName = RESOURCE_NAME_UPDATE;
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(101L);
+
+        MappingTO mapping = new MappingTO();
+
+        // Update with an existing and already assigned mapping
+        MappingItemTO item = new MappingItemTO();
+        item.setKey(112L);
+        item.setExtAttrName("test3");
+        item.setIntAttrName("fullname");
+        item.setIntMappingType(IntMappingType.UserPlainSchema);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.addItem(item);
+
+        // Update defining new mappings
+        for (int i = 4; i < 6; i++) {
+            item = new MappingItemTO();
+            item.setExtAttrName("test" + i);
+            item.setIntAttrName("fullname");
+            item.setIntMappingType(IntMappingType.UserPlainSchema);
+            item.setPurpose(MappingPurpose.BOTH);
+            mapping.addItem(item);
+        }
+        item = new MappingItemTO();
+        item.setExtAttrName("username");
+        item.setIntAttrName("fullname");
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setAccountid(true);
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setAccountIdItem(item);
+
+        resourceTO.setUmapping(mapping);
+
+        resourceService.update(resourceTO.getKey(), resourceTO);
+        ResourceTO actual = resourceService.read(resourceTO.getKey());
+        assertNotNull(actual);
+
+        // check for existence
+        Collection<MappingItemTO> mapItems = actual.getUmapping().getItems();
+        assertNotNull(mapItems);
+        assertEquals(4, mapItems.size());
+    }
+
+    @Test
+    public void deleteWithException() {
+        try {
+            resourceService.delete("resourcenotfound");
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+    }
+
+    @Test
+    public void updateResetSyncToken() {
+        // create resource with sync token
+        String resourceName = RESOURCE_NAME_RESETSYNCTOKEN + getUUIDString();
+        ResourceTO pre = buildResourceTO(resourceName);
+        pre.setUsyncToken("test");
+        resourceService.create(pre);
+
+        pre.setUsyncToken(null);
+        resourceService.update(pre.getKey(), pre);
+        ResourceTO actual = resourceService.read(pre.getKey());
+        // check that the synctoken has been reset
+        assertNull(actual.getUsyncToken());
+    }
+
+    @Test
+    public void delete() {
+        String resourceName = "tobedeleted";
+
+        ResourceTO resource = buildResourceTO(resourceName);
+        Response response = resourceService.create(resource);
+        ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+        assertNotNull(actual);
+
+        resourceService.delete(resourceName);
+
+        try {
+            resourceService.read(resourceName);
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+    }
+
+    @Test
+    public void list() {
+        List<ResourceTO> actuals = resourceService.list();
+        assertNotNull(actuals);
+        assertFalse(actuals.isEmpty());
+        for (ResourceTO resourceTO : actuals) {
+            assertNotNull(resourceTO);
+        }
+    }
+
+    @Test
+    public void listByType() {
+        List<ResourceTO> actuals = resourceService.list(105L);
+        assertNotNull(actuals);
+
+        for (ResourceTO resourceTO : actuals) {
+            assertNotNull(resourceTO);
+            assertEquals(105L, resourceTO.getConnectorId().longValue());
+        }
+    }
+
+    @Test
+    public void read() {
+        ResourceTO actual = resourceService.read(RESOURCE_NAME_TESTDB);
+        assertNotNull(actual);
+    }
+
+    @Test
+    public void issueSYNCOPE323() {
+        ResourceTO actual = resourceService.read(RESOURCE_NAME_TESTDB);
+        assertNotNull(actual);
+
+        try {
+            createResource(actual);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus());
+            assertEquals(ClientExceptionType.EntityExists, e.getType());
+        }
+
+        actual.setKey(null);
+        try {
+            createResource(actual);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus());
+            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
+        }
+    }
+
+    @Test
+    public void bulkAction() {
+        resourceService.create(buildResourceTO("forBulk1"));
+        resourceService.create(buildResourceTO("forBulk2"));
+
+        assertNotNull(resourceService.read("forBulk1"));
+        assertNotNull(resourceService.read("forBulk2"));
+
+        final BulkAction bulkAction = new BulkAction();
+        bulkAction.setOperation(BulkAction.Type.DELETE);
+
+        bulkAction.getTargets().add(String.valueOf("forBulk1"));
+        bulkAction.getTargets().add(String.valueOf("forBulk2"));
+
+        resourceService.bulk(bulkAction);
+
+        try {
+            resourceService.read("forBulk1");
+            fail();
+        } catch (SyncopeClientException e) {
+        }
+
+        try {
+            resourceService.read("forBulk2");
+            fail();
+        } catch (SyncopeClientException e) {
+        }
+    }
+
+    @Test
+    public void issueSYNCOPE360() {
+        final String name = "SYNCOPE360-" + getUUIDString();
+        resourceService.create(buildResourceTO(name));
+
+        ResourceTO resource = resourceService.read(name);
+        assertNotNull(resource);
+        assertNotNull(resource.getUmapping());
+
+        resource.setUmapping(new MappingTO());
+        resourceService.update(name, resource);
+
+        resource = resourceService.read(name);
+        assertNotNull(resource);
+        assertNull(resource.getUmapping());
+    }
+
+    @Test
+    public void issueSYNCOPE368() {
+        final String name = "SYNCOPE368-" + getUUIDString();
+
+        ResourceTO resourceTO = new ResourceTO();
+
+        resourceTO.setKey(name);
+        resourceTO.setConnectorId(105L);
+
+        MappingTO mapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.RoleName);
+        item.setExtAttrName("cn");
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.setAccountIdItem(item);
+
+        item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.RoleOwnerSchema);
+        item.setExtAttrName("owner");
+        item.setPurpose(MappingPurpose.BOTH);
+        mapping.addItem(item);
+
+        resourceTO.setRmapping(mapping);
+
+        resourceTO = createResource(resourceTO);
+        assertNotNull(resourceTO);
+        assertEquals(2, resourceTO.getRmapping().getItems().size());
+    }
+
+    @Test
+    public void issueSYNCOPE418() {
+        try {
+            resourceService.create(
+                    buildResourceTO("http://schemas.examples.org/security/authorization/organizationUnit"));
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidExternalResource, e.getType());
+
+            assertTrue(e.getElements().iterator().next().toString().contains(EntityViolationType.InvalidName.name()));
+        }
+    }
+
+    @Test
+    public void anonymous() {
+        ResourceService unauthenticated = clientFactory.createAnonymous().getService(ResourceService.class);
+        try {
+            unauthenticated.list();
+            fail();
+        } catch (AccessControlException e) {
+            assertNotNull(e);
+        }
+
+        ResourceService anonymous = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).
+                getService(ResourceService.class);
+        assertFalse(anonymous.list().isEmpty());
+    }
+
+    @Test
+    public void issueSYNCOPE493() {
+        // create resource with attribute mapping set to NONE and check its propagation
+        String resourceName = RESOURCE_NAME_CREATE_NONE;
+        ResourceTO resourceTO = new ResourceTO();
+        resourceTO.setKey(resourceName);
+        resourceTO.setConnectorId(102L);
+
+        MappingTO umapping = new MappingTO();
+
+        MappingItemTO item = new MappingItemTO();
+        item.setIntMappingType(IntMappingType.UserId);
+        item.setExtAttrName("userId");
+        item.setAccountid(true);
+        item.setPurpose(MappingPurpose.PROPAGATION);
+        umapping.setAccountIdItem(item);
+
+        MappingItemTO item2 = new MappingItemTO();
+        item2.setIntMappingType(IntMappingType.UserPlainSchema);
+        item2.setAccountid(false);
+        item2.setIntAttrName("gender");
+        item2.setExtAttrName("gender");
+        item2.setPurpose(MappingPurpose.NONE);
+        umapping.addItem(item2);
+
+        resourceTO.setUmapping(umapping);
+
+        Response response = resourceService.create(resourceTO);
+        ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
+
+        assertNotNull(actual);
+        assertNotNull(actual.getUmapping());
+        assertNotNull(actual.getUmapping().getItems());
+        assertEquals(MappingPurpose.PROPAGATION, actual.getUmapping().getAccountIdItem().getPurpose());
+        for (MappingItemTO itemTO : actual.getUmapping().getItems()) {
+            if ("gender".equals(itemTO.getIntAttrName())) {
+                assertEquals(MappingPurpose.NONE, itemTO.getPurpose());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/80589a1b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/RoleITCase.java
----------------------------------------------------------------------
diff --git a/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/RoleITCase.java b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/RoleITCase.java
new file mode 100644
index 0000000..dbd9532
--- /dev/null
+++ b/syncope620/fit/reference/src/test/java/org/apache/syncope/fit/server/reference/RoleITCase.java
@@ -0,0 +1,797 @@
+/*
+ * 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.fit.server.reference;
+
+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.io.IOException;
+import java.io.InputStream;
+import java.security.AccessControlException;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.mod.ReferenceMod;
+import org.apache.syncope.common.lib.mod.RoleMod;
+import org.apache.syncope.common.lib.to.BulkActionResult;
+import org.apache.syncope.common.lib.to.ConnObjectTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.RoleTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AttributableType;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.ResourceAssociationActionType;
+import org.apache.syncope.common.lib.types.ResourceDeassociationActionType;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.lib.types.SubjectType;
+import org.apache.syncope.common.lib.wrap.ResourceName;
+import org.apache.syncope.common.rest.api.CollectionWrapper;
+import org.apache.syncope.common.rest.api.Preference;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.service.RoleService;
+import org.identityconnectors.framework.common.objects.Name;
+import org.junit.FixMethodOrder;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class RoleITCase extends AbstractITCase {
+
+    private RoleTO buildBasicRoleTO(final String name) {
+        RoleTO roleTO = new RoleTO();
+        roleTO.setName(name + getUUIDString());
+        roleTO.setParent(8L);
+        return roleTO;
+    }
+
+    private RoleTO buildRoleTO(final String name) {
+        RoleTO roleTO = buildBasicRoleTO(name);
+
+        // verify inheritance password and account policies
+        roleTO.setInheritAccountPolicy(false);
+        // not inherited so setter execution shouldn't be ignored
+        roleTO.setAccountPolicy(6L);
+
+        roleTO.setInheritPasswordPolicy(true);
+        // inherited so setter execution should be ignored
+        roleTO.setPasswordPolicy(2L);
+
+        roleTO.getRAttrTemplates().add("icon");
+        roleTO.getPlainAttrs().add(attrTO("icon", "anIcon"));
+
+        roleTO.getResources().add(RESOURCE_NAME_LDAP);
+        return roleTO;
+    }
+
+    @Test
+    public void createWithException() {
+        RoleTO newRoleTO = new RoleTO();
+        newRoleTO.getPlainAttrs().add(attrTO("attr1", "value1"));
+
+        try {
+            createRole(newRoleTO);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.InvalidRole, e.getType());
+        }
+    }
+
+    @Test
+    @Ignore
+    public void create() {
+        RoleTO roleTO = buildRoleTO("lastRole");
+        roleTO.getRVirAttrTemplates().add("rvirtualdata");
+        roleTO.getVirAttrs().add(attrTO("rvirtualdata", "rvirtualvalue"));
+        roleTO.setRoleOwner(8L);
+
+        roleTO = createRole(roleTO);
+        assertNotNull(roleTO);
+
+        assertNotNull(roleTO.getVirAttrMap());
+        assertNotNull(roleTO.getVirAttrMap().get("rvirtualdata").getValues());
+        assertFalse(roleTO.getVirAttrMap().get("rvirtualdata").getValues().isEmpty());
+        assertEquals("rvirtualvalue", roleTO.getVirAttrMap().get("rvirtualdata").getValues().get(0));
+
+        assertNotNull(roleTO.getAccountPolicy());
+        assertEquals(6L, (long) roleTO.getAccountPolicy());
+
+        assertNotNull(roleTO.getPasswordPolicy());
+        assertEquals(4L, (long) roleTO.getPasswordPolicy());
+
+        assertTrue(roleTO.getResources().contains(RESOURCE_NAME_LDAP));
+
+        ConnObjectTO connObjectTO =
+                resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, roleTO.getKey());
+        assertNotNull(connObjectTO);
+        assertNotNull(connObjectTO.getPlainAttrMap().get("owner"));
+
+        // SYNCOPE-515: remove ownership
+        final RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.setRoleOwner(new ReferenceMod());
+
+        assertNull(updateRole(roleMod).getRoleOwner());
+    }
+
+    @Test
+    public void createWithPasswordPolicy() {
+        RoleTO roleTO = new RoleTO();
+        roleTO.setName("roleWithPassword" + getUUIDString());
+        roleTO.setParent(8L);
+        roleTO.setPasswordPolicy(4L);
+
+        RoleTO actual = createRole(roleTO);
+        assertNotNull(actual);
+
+        actual = roleService.read(actual.getKey());
+        assertNotNull(actual);
+        assertNotNull(actual.getPasswordPolicy());
+        assertEquals(4L, (long) actual.getPasswordPolicy());
+    }
+
+    @Test
+    public void delete() {
+        try {
+            roleService.delete(0L);
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+
+        RoleTO roleTO = new RoleTO();
+        roleTO.setName("toBeDeleted" + getUUIDString());
+        roleTO.setParent(8L);
+
+        roleTO.getResources().add(RESOURCE_NAME_LDAP);
+
+        roleTO = createRole(roleTO);
+        assertNotNull(roleTO);
+
+        RoleTO deletedRole = deleteRole(roleTO.getKey());
+        assertNotNull(deletedRole);
+
+        try {
+            roleService.read(deletedRole.getKey());
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+        }
+    }
+
+    @Test
+    public void list() {
+        PagedResult<RoleTO> roleTOs = roleService.list();
+        assertNotNull(roleTOs);
+        assertTrue(roleTOs.getResult().size() >= 8);
+        for (RoleTO roleTO : roleTOs.getResult()) {
+            assertNotNull(roleTO);
+        }
+    }
+
+    @Test
+    public void parent() {
+        RoleTO roleTO = roleService.parent(7L);
+
+        assertNotNull(roleTO);
+        assertEquals(roleTO.getKey(), 6L);
+    }
+
+    @Test
+    public void read() {
+        RoleTO roleTO = roleService.read(1L);
+
+        assertNotNull(roleTO);
+        assertNotNull(roleTO.getPlainAttrs());
+        assertFalse(roleTO.getPlainAttrs().isEmpty());
+    }
+
+    @Test
+    public void selfRead() {
+        UserTO userTO = userService.read(1L);
+        assertNotNull(userTO);
+
+        assertTrue(userTO.getMembershipMap().containsKey(1L));
+        assertFalse(userTO.getMembershipMap().containsKey(3L));
+
+        RoleService roleService2 = clientFactory.create("rossini", ADMIN_PWD).getService(RoleService.class);
+
+        try {
+            roleService2.readSelf(3L);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.UnauthorizedRole, e.getType());
+        }
+
+        RoleTO roleTO = roleService2.readSelf(1L);
+        assertNotNull(roleTO);
+        assertNotNull(roleTO.getPlainAttrs());
+        assertFalse(roleTO.getPlainAttrs().isEmpty());
+    }
+
+    @Test
+    public void update() {
+        RoleTO roleTO = buildRoleTO("latestRole" + getUUIDString());
+        roleTO.getRAttrTemplates().add("show");
+        roleTO = createRole(roleTO);
+
+        assertEquals(1, roleTO.getPlainAttrs().size());
+
+        assertNotNull(roleTO.getAccountPolicy());
+        assertEquals(6L, (long) roleTO.getAccountPolicy());
+
+        assertNotNull(roleTO.getPasswordPolicy());
+        assertEquals(4L, (long) roleTO.getPasswordPolicy());
+
+        RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        String modName = "finalRole" + getUUIDString();
+        roleMod.setName(modName);
+        roleMod.getPlainAttrsToUpdate().add(attrMod("show", "FALSE"));
+
+        // change password policy inheritance
+        roleMod.setInheritPasswordPolicy(Boolean.FALSE);
+
+        roleTO = updateRole(roleMod);
+
+        assertEquals(modName, roleTO.getName());
+        assertEquals(2, roleTO.getPlainAttrs().size());
+
+        // changes ignored because not requested (null ReferenceMod)
+        assertNotNull(roleTO.getAccountPolicy());
+        assertEquals(6L, (long) roleTO.getAccountPolicy());
+
+        // password policy null because not inherited
+        assertNull(roleTO.getPasswordPolicy());
+    }
+
+    @Test
+    public void updateRemovingVirAttribute() {
+        RoleTO roleTO = buildBasicRoleTO("withvirtual" + getUUIDString());
+        roleTO.getRVirAttrTemplates().add("rvirtualdata");
+        roleTO.getVirAttrs().add(attrTO("rvirtualdata", null));
+
+        roleTO = createRole(roleTO);
+
+        assertNotNull(roleTO);
+        assertEquals(1, roleTO.getVirAttrs().size());
+
+        final RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.getVirAttrsToRemove().add("rvirtualdata");
+
+        roleTO = updateRole(roleMod);
+        assertNotNull(roleTO);
+        assertTrue(roleTO.getVirAttrs().isEmpty());
+    }
+
+    @Test
+    public void updateRemovingDerAttribute() {
+        RoleTO roleTO = buildBasicRoleTO("withderived" + getUUIDString());
+        roleTO.getRDerAttrTemplates().add("rderivedschema");
+        roleTO.getDerAttrs().add(attrTO("rderivedschema", null));
+
+        roleTO = createRole(roleTO);
+
+        assertNotNull(roleTO);
+        assertEquals(1, roleTO.getDerAttrs().size());
+
+        final RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.getDerAttrsToRemove().add("rderivedschema");
+
+        roleTO = updateRole(roleMod);
+        assertNotNull(roleTO);
+        assertTrue(roleTO.getDerAttrs().isEmpty());
+    }
+
+    @Test
+    public void updateAsRoleOwner() {
+        // 1. read role as admin
+        RoleTO roleTO = roleService.read(7L);
+
+        // issue SYNCOPE-15
+        assertNotNull(roleTO.getCreationDate());
+        assertNotNull(roleTO.getLastChangeDate());
+        assertEquals("admin", roleTO.getCreator());
+        assertEquals("admin", roleTO.getLastModifier());
+
+        // 2. prepare update
+        RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.setName("Managing Director");
+
+        // 3. try to update as verdi, not owner of role 7 - fail
+        RoleService roleService2 = clientFactory.create("verdi", ADMIN_PWD).getService(RoleService.class);
+
+        try {
+            roleService2.update(roleMod.getKey(), roleMod);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(Response.Status.UNAUTHORIZED, e.getType().getResponseStatus());
+        } catch (AccessControlException e) {
+            assertNotNull(e);
+        }
+
+        // 4. update as puccini, owner of role 7 because owner of role 6 with inheritance - success
+        RoleService roleService3 = clientFactory.create("puccini", ADMIN_PWD).getService(RoleService.class);
+
+        roleTO = roleService3.update(roleMod.getKey(), roleMod).readEntity(RoleTO.class);
+        assertEquals("Managing Director", roleTO.getName());
+
+        // issue SYNCOPE-15
+        assertNotNull(roleTO.getCreationDate());
+        assertNotNull(roleTO.getLastChangeDate());
+        assertEquals("admin", roleTO.getCreator());
+        assertEquals("puccini", roleTO.getLastModifier());
+        assertTrue(roleTO.getCreationDate().before(roleTO.getLastChangeDate()));
+    }
+
+    /**
+     * Role rename used to fail in case of parent null.
+     *
+     * http://code.google.com/p/syncope/issues/detail?id=178
+     */
+    @Test
+    public void issue178() {
+        RoleTO roleTO = new RoleTO();
+        String roleName = "torename" + getUUIDString();
+        roleTO.setName(roleName);
+
+        RoleTO actual = createRole(roleTO);
+
+        assertNotNull(actual);
+        assertEquals(roleName, actual.getName());
+        assertEquals(0L, actual.getParent());
+
+        RoleMod roleMod = new RoleMod();
+        roleMod.setKey(actual.getKey());
+        String renamedRole = "renamed" + getUUIDString();
+        roleMod.setName(renamedRole);
+
+        actual = updateRole(roleMod);
+        assertNotNull(actual);
+        assertEquals(renamedRole, actual.getName());
+        assertEquals(0L, actual.getParent());
+    }
+
+    @Test
+    public void issueSYNCOPE228() {
+        RoleTO roleTO = buildRoleTO("issueSYNCOPE228");
+        roleTO.getEntitlements().add("USER_READ");
+        roleTO.getEntitlements().add("SCHEMA_READ");
+
+        roleTO = createRole(roleTO);
+        assertNotNull(roleTO);
+        assertNotNull(roleTO.getEntitlements());
+        assertFalse(roleTO.getEntitlements().isEmpty());
+
+        List<String> entitlements = roleTO.getEntitlements();
+
+        RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.setInheritDerAttrs(Boolean.TRUE);
+
+        roleTO = updateRole(roleMod);
+        assertNotNull(roleTO);
+        assertEquals(entitlements, roleTO.getEntitlements());
+
+        roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.setModEntitlements(true);
+        roleMod.getEntitlements().clear();
+
+        roleTO = updateRole(roleMod);
+        assertNotNull(roleTO);
+        assertTrue(roleTO.getEntitlements().isEmpty());
+    }
+
+    @Test
+    public void unlink() {
+        RoleTO actual = createRole(buildRoleTO("unlink"));
+        assertNotNull(actual);
+
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+
+        assertNotNull(roleService.bulkDeassociation(actual.getKey(),
+                ResourceDeassociationActionType.UNLINK,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertNotNull(actual);
+        assertTrue(actual.getResources().isEmpty());
+
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+    }
+
+    @Test
+    public void link() {
+        RoleTO roleTO = buildRoleTO("link");
+        roleTO.getResources().clear();
+
+        RoleTO actual = createRole(roleTO);
+        assertNotNull(actual);
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+
+        assertNotNull(roleService.bulkAssociation(actual.getKey(),
+                ResourceAssociationActionType.LINK,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertFalse(actual.getResources().isEmpty());
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+    }
+
+    @Test
+    public void unassign() {
+        RoleTO actual = createRole(buildRoleTO("unassign"));
+        assertNotNull(actual);
+
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+
+        assertNotNull(roleService.bulkDeassociation(actual.getKey(),
+                ResourceDeassociationActionType.UNASSIGN,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertNotNull(actual);
+        assertTrue(actual.getResources().isEmpty());
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+    }
+
+    @Test
+    public void assign() {
+        RoleTO roleTO = buildRoleTO("assign");
+        roleTO.getResources().clear();
+
+        RoleTO actual = createRole(roleTO);
+        assertNotNull(actual);
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+
+        assertNotNull(roleService.bulkAssociation(actual.getKey(),
+                ResourceAssociationActionType.ASSIGN,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertFalse(actual.getResources().isEmpty());
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+    }
+
+    @Test
+    public void deprovision() {
+        RoleTO actual = createRole(buildRoleTO("deprovision"));
+        assertNotNull(actual);
+
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+
+        assertNotNull(roleService.bulkDeassociation(actual.getKey(),
+                ResourceDeassociationActionType.DEPROVISION,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertNotNull(actual);
+        assertFalse(actual.getResources().isEmpty());
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+    }
+
+    @Test
+    public void provision() {
+        RoleTO roleTO = buildRoleTO("assign");
+        roleTO.getResources().clear();
+
+        RoleTO actual = createRole(roleTO);
+        assertNotNull(actual);
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+
+        assertNotNull(roleService.bulkAssociation(actual.getKey(),
+                ResourceAssociationActionType.PROVISION,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertTrue(actual.getResources().isEmpty());
+
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+    }
+
+    @Test
+    public void deprovisionUnlinked() {
+        RoleTO roleTO = buildRoleTO("assign");
+        roleTO.getResources().clear();
+
+        RoleTO actual = createRole(roleTO);
+        assertNotNull(actual);
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+
+        assertNotNull(roleService.bulkAssociation(actual.getKey(),
+                ResourceAssociationActionType.PROVISION,
+                CollectionWrapper.wrap("resource-ldap", ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertTrue(actual.getResources().isEmpty());
+
+        assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey()));
+
+        assertNotNull(roleService.bulkDeassociation(actual.getKey(),
+                ResourceDeassociationActionType.DEPROVISION,
+                CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class)).
+                readEntity(BulkActionResult.class));
+
+        actual = roleService.read(actual.getKey());
+        assertNotNull(actual);
+        assertTrue(actual.getResources().isEmpty());
+
+        try {
+            resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, actual.getKey());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
+        }
+    }
+
+    @Test
+    public void createWithMandatorySchemaNotTemplate() {
+        // 1. create a role mandatory schema
+        PlainSchemaTO badge = new PlainSchemaTO();
+        badge.setKey("badge");
+        badge.setMandatoryCondition("true");
+        schemaService.create(AttributableType.ROLE, SchemaType.PLAIN, badge);
+
+        // 2. create a role *without* an attribute for that schema: it works
+        RoleTO roleTO = buildRoleTO("lastRole");
+        assertFalse(roleTO.getPlainAttrMap().containsKey(badge.getKey()));
+        roleTO = createRole(roleTO);
+        assertNotNull(roleTO);
+        assertFalse(roleTO.getPlainAttrMap().containsKey(badge.getKey()));
+
+        // 3. add a template for badge to the role just created - 
+        // failure since no values are provided and it is mandatory
+        RoleMod roleMod = new RoleMod();
+        roleMod.setKey(roleTO.getKey());
+        roleMod.setModRAttrTemplates(true);
+        roleMod.getRPlainAttrTemplates().add("badge");
+
+        try {
+            updateRole(roleMod);
+            fail();
+        } catch (SyncopeClientException e) {
+            assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
+        }
+
+        // 4. also add an actual attribute for badge - it will work        
+        roleMod.getPlainAttrsToUpdate().add(attrMod(badge.getKey(), "xxxxxxxxxx"));
+
+        roleTO = updateRole(roleMod);
+        assertNotNull(roleTO);
+        assertTrue(roleTO.getPlainAttrMap().containsKey(badge.getKey()));
+    }
+
+    @Test
+    public void anonymous() {
+        RoleService unauthenticated = clientFactory.createAnonymous().getService(RoleService.class);
+        try {
+            unauthenticated.list();
+            fail();
+        } catch (AccessControlException e) {
+            assertNotNull(e);
+        }
+
+        RoleService anonymous = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(RoleService.class);
+        assertFalse(anonymous.list().getResult().isEmpty());
+    }
+
+    @Test
+    public void noContent() throws IOException {
+        SyncopeClient noContentclient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
+        RoleService noContentService = noContentclient.prefer(RoleService.class, Preference.RETURN_NO_CONTENT);
+
+        RoleTO role = buildRoleTO("noContent");
+
+        Response response = noContentService.create(role);
+        assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
+        assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
+        assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity()));
+
+        role = getObject(response.getLocation(), RoleService.class, RoleTO.class);
+        assertNotNull(role);
+
+        RoleMod roleMod = new RoleMod();
+        roleMod.getPlainAttrsToUpdate().add(attrMod("badge", "xxxxxxxxxx"));
+
+        response = noContentService.update(role.getKey(), roleMod);
+        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
+        assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
+        assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity()));
+
+        response = noContentService.delete(role.getKey());
+        assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
+        assertEquals(Preference.RETURN_NO_CONTENT.toString(), response.getHeaderString(RESTHeaders.PREFERENCE_APPLIED));
+        assertEquals(StringUtils.EMPTY, IOUtils.toString((InputStream) response.getEntity()));
+    }
+
+    @Test
+    public void issueSYNCOPE455() {
+        final String parentName = "issueSYNCOPE455-PRole";
+        final String childName = "issueSYNCOPE455-CRole";
+
+        // 1. create parent role
+        RoleTO parent = buildBasicRoleTO(parentName);
+        parent.getResources().add(RESOURCE_NAME_LDAP);
+
+        parent = createRole(parent);
+        assertTrue(parent.getResources().contains(RESOURCE_NAME_LDAP));
+
+        final ConnObjectTO parentRemoteObject =
+                resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, parent.getKey());
+        assertNotNull(parentRemoteObject);
+        assertNotNull(getLdapRemoteObject(parentRemoteObject.getPlainAttrMap().get(Name.NAME).getValues().get(0)));
+
+        // 2. create child role
+        RoleTO child = buildBasicRoleTO(childName);
+        child.getResources().add(RESOURCE_NAME_LDAP);
+        child.setParent(parent.getKey());
+
+        child = createRole(child);
+        assertTrue(child.getResources().contains(RESOURCE_NAME_LDAP));
+
+        final ConnObjectTO childRemoteObject =
+                resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, child.getKey());
+        assertNotNull(childRemoteObject);
+        assertNotNull(getLdapRemoteObject(childRemoteObject.getPlainAttrMap().get(Name.NAME).getValues().get(0)));
+
+        // 3. remove parent role
+        roleService.delete(parent.getKey());
+
+        // 4. asserts for issue 455
+        try {
+            roleService.read(parent.getKey());
+            fail();
+        } catch (SyncopeClientException scce) {
+            assertNotNull(scce);
+        }
+
+        try {
+            roleService.read(child.getKey());
+            fail();
+        } catch (SyncopeClientException scce) {
+            assertNotNull(scce);
+        }
+
+        assertNull(getLdapRemoteObject(parentRemoteObject.getPlainAttrMap().get(Name.NAME).getValues().get(0)));
+        assertNull(getLdapRemoteObject(childRemoteObject.getPlainAttrMap().get(Name.NAME).getValues().get(0)));
+    }
+
+    @Test
+    public void issueSYNCOPE543() {
+        final String ancestorName = "issueSYNCOPE543-ARole";
+        final String parentName = "issueSYNCOPE543-PRole";
+        final String childName = "issueSYNCOPE543-CRole";
+
+        // 1. create ancestor role
+        RoleTO ancestor = buildBasicRoleTO(ancestorName);
+        ancestor.setParent(0L);
+        ancestor.getRAttrTemplates().add("icon");
+        ancestor.getPlainAttrs().add(attrTO("icon", "ancestorIcon"));
+        ancestor = createRole(ancestor);
+        assertEquals("ancestorIcon", ancestor.getPlainAttrMap().get("icon").getValues().get(0));
+
+        // 2. create parent role
+        RoleTO parent = buildBasicRoleTO(parentName);
+        parent.setParent(ancestor.getKey());
+        parent.getRAttrTemplates().add("icon");
+        parent.getPlainAttrs().add(attrTO("icon", "parentIcon"));
+        parent = createRole(parent);
+        assertEquals("parentIcon", parent.getPlainAttrMap().get("icon").getValues().get(0));
+
+        // 3. create child role
+        RoleTO child = buildBasicRoleTO(childName);
+        child.setParent(parent.getKey());
+        child.getRAttrTemplates().add("icon");
+        child.getPlainAttrs().add(attrTO("icon", "childIcon"));
+        child = createRole(child);
+        assertEquals("childIcon", child.getPlainAttrMap().get("icon").getValues().get(0));
+
+        final RoleMod roleChildMod = new RoleMod();
+        roleChildMod.setKey(child.getKey());
+        roleChildMod.setInheritPlainAttrs(Boolean.TRUE);
+        updateRole(roleChildMod);
+
+        child = roleService.read(child.getKey());
+        assertNotNull(child);
+        assertNotNull(child.getPlainAttrMap().get("icon").getValues());
+        assertEquals("parentIcon", child.getPlainAttrMap().get("icon").getValues().get(0));
+
+        final RoleMod roleParentMod = new RoleMod();
+        roleParentMod.setKey(parent.getKey());
+        roleParentMod.setInheritPlainAttrs(Boolean.TRUE);
+        updateRole(roleParentMod);
+
+        child = roleService.read(child.getKey());
+        assertNotNull(child);
+        assertNotNull(child.getPlainAttrMap().get("icon").getValues());
+        assertEquals("ancestorIcon", child.getPlainAttrMap().get("icon").getValues().get(0));
+
+        parent = roleService.read(parent.getKey());
+        assertNotNull(parent);
+        assertNotNull(parent.getPlainAttrMap().get("icon").getValues());
+        assertEquals("ancestorIcon", parent.getPlainAttrMap().get("icon").getValues().get(0));
+
+        roleParentMod.setInheritPlainAttrs(Boolean.FALSE);
+        updateRole(roleParentMod);
+
+        child = roleService.read(child.getKey());
+        assertNotNull(child);
+        assertNotNull(child.getPlainAttrMap().get("icon").getValues());
+        assertEquals("parentIcon", child.getPlainAttrMap().get("icon").getValues().get(0));
+    }
+}