syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1419262 - in /syncope/branches/DEV_ROLE_PROVISIONING: ./ core/src/test/java/org/apache/syncope/core/rest/
Date Mon, 10 Dec 2012 08:41:52 GMT
Author: ilgrosso
Date: Mon Dec 10 08:41:50 2012
New Revision: 1419262

URL: http://svn.apache.org/viewvc?rev=1419262&view=rev
Log:
Merge from trunk

Modified:
    syncope/branches/DEV_ROLE_PROVISIONING/   (props changed)
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
    syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java

Propchange: syncope/branches/DEV_ROLE_PROVISIONING/
------------------------------------------------------------------------------
  Merged /syncope/trunk:r1418259-1419259

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1419262&r1=1419261&r2=1419262&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
(original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
Mon Dec 10 08:41:50 2012
@@ -22,6 +22,8 @@ import javax.sql.DataSource;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
+import org.apache.syncope.client.mod.AttributeMod;
+import org.apache.syncope.client.to.AttributeTO;
 import org.junit.Before;
 import org.junit.runner.RunWith;
 import org.slf4j.Logger;
@@ -35,6 +37,20 @@ import org.springframework.web.client.Re
 @ContextConfiguration(locations = {"classpath:restClientContext.xml", "classpath:testJDBCContext.xml"})
 public abstract class AbstractTest {
 
+    protected static AttributeTO attributeTO(final String schema, final String value) {
+        AttributeTO attr = new AttributeTO();
+        attr.setSchema(schema);
+        attr.addValue(value);
+        return attr;
+    }
+
+    protected static AttributeMod attributeMod(final String schema, final String valueToBeAdded)
{
+        AttributeMod attr = new AttributeMod();
+        attr.setSchema(schema);
+        attr.addValueToBeAdded(valueToBeAdded);
+        return attr;
+    }
+
     /**
      * Logger.
      */

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1419262&r1=1419261&r2=1419262&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
(original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
Mon Dec 10 08:41:50 2012
@@ -22,37 +22,30 @@ import static org.junit.Assert.*;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.ArrayList;
 import java.util.List;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
-import org.apache.syncope.client.mod.AttributeMod;
 import org.apache.syncope.client.mod.RoleMod;
-import org.apache.syncope.client.to.AttributeTO;
 import org.apache.syncope.client.to.ConnObjectTO;
 import org.apache.syncope.client.to.RoleTO;
 import org.apache.syncope.client.to.UserTO;
 import org.apache.syncope.client.validation.SyncopeClientCompositeErrorException;
 import org.apache.syncope.client.validation.SyncopeClientException;
 import org.apache.syncope.types.SyncopeClientExceptionType;
+import org.junit.FixMethodOrder;
 import org.junit.Test;
+import org.junit.runners.MethodSorters;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.client.HttpStatusCodeException;
-import org.junit.FixMethodOrder;
-import org.junit.runners.MethodSorters;
 
 @FixMethodOrder(MethodSorters.JVM)
 public class RoleTestITCase extends AbstractTest {
 
     @Test
     public void createWithException() {
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("attr1");
-        attributeTO.addValue("value1");
-
         RoleTO newRoleTO = new RoleTO();
-        newRoleTO.addAttribute(attributeTO);
+        newRoleTO.addAttribute(attributeTO("attr1", "value1"));
 
         Throwable t = null;
         try {
@@ -79,19 +72,11 @@ public class RoleTestITCase extends Abst
         // inherited so setter execution should be ignored
         roleTO.setPasswordPolicy(2L);
 
-        AttributeTO icon = new AttributeTO();
-        icon.setSchema("icon");
-        icon.addValue("anIcon");
-        roleTO.addAttribute(icon);
-
-        AttributeTO ownerDN = new AttributeTO();
-        ownerDN.setSchema("ownerDN");
-        roleTO.addDerivedAttribute(ownerDN);
-
-        AttributeTO rvirtualdata = new AttributeTO();
-        rvirtualdata.setSchema("rvirtualdata");
-        rvirtualdata.addValue("rvirtualvalue");
-        roleTO.addVirtualAttribute(rvirtualdata);
+        roleTO.addAttribute(attributeTO("icon", "anIcon"));
+
+        roleTO.addDerivedAttribute(attributeTO("ownerDN", null));
+
+        roleTO.addVirtualAttribute(attributeTO("rvirtualdata", "rvirtualvalue"));
 
         roleTO.setRoleOwner(8L);
 
@@ -235,10 +220,7 @@ public class RoleTestITCase extends Abst
         // inherited so setter execution should be ignored
         roleTO.setPasswordPolicy(2L);
 
-        AttributeTO icon = new AttributeTO();
-        icon.setSchema("icon");
-        icon.addValue("anIcon");
-        roleTO.addAttribute(icon);
+        roleTO.addAttribute(attributeTO("icon", "anIcon"));
 
         roleTO.addResource("resource-ldap");
 
@@ -252,14 +234,10 @@ public class RoleTestITCase extends Abst
         assertNotNull(roleTO.getPasswordPolicy());
         assertEquals(Long.valueOf(4), roleTO.getPasswordPolicy());
 
-        AttributeMod attributeMod = new AttributeMod();
-        attributeMod.setSchema("show");
-        attributeMod.addValueToBeAdded("FALSE");
-
         RoleMod roleMod = new RoleMod();
         roleMod.setId(roleTO.getId());
         roleMod.setName("finalRole");
-        roleMod.addAttributeToBeUpdated(attributeMod);
+        roleMod.addAttributeToBeUpdated(attributeMod("show", "FALSE"));
 
         // change password policy inheritance
         roleMod.setInheritPasswordPolicy(Boolean.FALSE);
@@ -282,10 +260,7 @@ public class RoleTestITCase extends Abst
         RoleTO roleTO = new RoleTO();
         roleTO.setName("withvirtual");
         roleTO.setParent(8L);
-
-        final AttributeTO rvirtualdata = new AttributeTO();
-        rvirtualdata.setSchema("rvirtualdata");
-        roleTO.addVirtualAttribute(rvirtualdata);
+        roleTO.addVirtualAttribute(attributeTO("rvirtualdata", null));
 
         roleTO = restTemplate.postForObject(BASE_URL + "role/create", roleTO, RoleTO.class);
 
@@ -307,10 +282,7 @@ public class RoleTestITCase extends Abst
         RoleTO roleTO = new RoleTO();
         roleTO.setName("withderived");
         roleTO.setParent(8L);
-
-        final AttributeTO deriveddata = new AttributeTO();
-        deriveddata.setSchema("rderivedschema");
-        roleTO.addDerivedAttribute(deriveddata);
+        roleTO.addDerivedAttribute(attributeTO("rderivedschema", null));
 
         roleTO = restTemplate.postForObject(BASE_URL + "role/create", roleTO, RoleTO.class);
 
@@ -397,12 +369,7 @@ public class RoleTestITCase extends Abst
         roleTO.setAccountPolicy(6L);
         roleTO.setInheritPasswordPolicy(true);
         roleTO.setPasswordPolicy(2L);
-
-        AttributeTO icon = new AttributeTO();
-        icon.setSchema("icon");
-        icon.addValue("anIcon");
-        roleTO.addAttribute(icon);
-
+        roleTO.addAttribute(attributeTO("icon", "anIcon"));
         roleTO.addEntitlement("USER_READ");
         roleTO.addEntitlement("SCHEMA_READ");
 

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java?rev=1419262&r1=1419261&r2=1419262&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
(original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
Mon Dec 10 08:41:50 2012
@@ -18,12 +18,9 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
-
 import java.util.Arrays;
 import java.util.List;
 import org.apache.syncope.client.mod.UserMod;
-import org.apache.syncope.client.to.AttributeTO;
 import org.apache.syncope.client.to.MembershipTO;
 import org.apache.syncope.client.to.SchemaTO;
 import org.apache.syncope.client.to.UserTO;
@@ -33,6 +30,12 @@ import org.apache.syncope.client.validat
 import org.apache.syncope.types.EntityViolationType;
 import org.apache.syncope.types.SchemaType;
 import org.apache.syncope.types.SyncopeClientExceptionType;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
@@ -178,10 +181,7 @@ public class SchemaTestITCase extends Ab
         assertNotNull(schemaTO);
 
         UserTO userTO = UserTestITCase.getSampleTO("issue258@syncope.apache.org");
-        AttributeTO attrTO = new AttributeTO();
-        attrTO.setSchema(schemaTO.getName());
-        attrTO.addValue("1.2");
-        userTO.addAttribute(attrTO);
+        userTO.addAttribute(attributeTO(schemaTO.getName(), "1.2"));
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
@@ -207,11 +207,7 @@ public class SchemaTestITCase extends Ab
         assertNotNull(schemaTO);
 
         UserTO userTO = UserTestITCase.getSampleTO("issue259@syncope.apache.org");
-        AttributeTO attrTO = new AttributeTO();
-        attrTO.setSchema(schemaTO.getName());
-        attrTO.addValue("1");
-        userTO.addAttribute(attrTO);
-
+        userTO.addAttribute(attributeTO(schemaTO.getName(), "1"));
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
 
@@ -237,11 +233,7 @@ public class SchemaTestITCase extends Ab
         assertNotNull(schemaTO);
 
         UserTO userTO = UserTestITCase.getSampleTO("issue260@syncope.apache.org");
-        AttributeTO attrTO = new AttributeTO();
-        attrTO.setSchema(schemaTO.getName());
-        attrTO.addValue("1.2");
-        userTO.addAttribute(attrTO);
-
+        userTO.addAttribute(attributeTO(schemaTO.getName(), "1.2"));
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
 

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1419262&r1=1419261&r2=1419262&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
(original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
Mon Dec 10 08:41:50 2012
@@ -18,41 +18,44 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
-
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import org.apache.syncope.client.search.MembershipCond;
 import org.apache.syncope.client.search.NodeCond;
-import org.junit.Test;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.client.HttpStatusCodeException;
-import org.apache.syncope.client.to.AttributeTO;
 import org.apache.syncope.client.to.MembershipTO;
 import org.apache.syncope.client.to.NotificationTO;
 import org.apache.syncope.client.to.NotificationTaskTO;
-import org.apache.syncope.client.to.TaskExecTO;
 import org.apache.syncope.client.to.PropagationTaskTO;
 import org.apache.syncope.client.to.RoleTO;
 import org.apache.syncope.client.to.SchedTaskTO;
 import org.apache.syncope.client.to.SyncTaskTO;
+import org.apache.syncope.client.to.TaskExecTO;
 import org.apache.syncope.client.to.TaskTO;
 import org.apache.syncope.client.to.UserTO;
-import org.apache.syncope.core.sync.SyncJob;
 import org.apache.syncope.core.init.SpringContextInitializer;
-import org.apache.syncope.types.PropagationTaskExecStatus;
 import org.apache.syncope.core.quartz.TestSyncActions;
+import org.apache.syncope.core.sync.SyncJob;
 import org.apache.syncope.types.IntMappingType;
+import org.apache.syncope.types.PropagationTaskExecStatus;
 import org.apache.syncope.types.TraceLevel;
+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 org.junit.FixMethodOrder;
+import org.junit.Test;
 import org.junit.runners.MethodSorters;
+import org.springframework.http.HttpStatus;
 import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.web.client.HttpStatusCodeException;
 
 @FixMethodOrder(MethodSorters.JVM)
 public class TaskTestITCase extends AbstractTest {
 
     @Test
+    @SuppressWarnings("unchecked")
     public void getJobClasses() {
         Set<String> jobClasses = restTemplate.getForObject(BASE_URL + "task/jobClasses.json",
Set.class);
         assertNotNull(jobClasses);
@@ -60,6 +63,7 @@ public class TaskTestITCase extends Abst
     }
 
     @Test
+    @SuppressWarnings("unchecked")
     public void getSyncActionsClasses() {
         Set<String> actions = restTemplate.getForObject(BASE_URL + "task/syncActionsClasses.json",
Set.class);
         assertNotNull(actions);
@@ -216,41 +220,13 @@ public class TaskTestITCase extends Abst
         UserTO userTO = new UserTO();
         userTO.setPassword("password123");
         userTO.setUsername("test9");
-
-        AttributeTO firstnameTO = new AttributeTO();
-        firstnameTO.setSchema("firstname");
-        firstnameTO.addValue("nome9");
-        userTO.addAttribute(firstnameTO);
-
-        AttributeTO surnameTO = new AttributeTO();
-        surnameTO.setSchema("surname");
-        surnameTO.addValue("cognome");
-        userTO.addAttribute(surnameTO);
-
-        AttributeTO typeTO = new AttributeTO();
-        typeTO.setSchema("type");
-        typeTO.addValue("a type");
-        userTO.addAttribute(typeTO);
-
-        AttributeTO fullnameTO = new AttributeTO();
-        fullnameTO.setSchema("fullname");
-        fullnameTO.addValue("nome cognome");
-        userTO.addAttribute(fullnameTO);
-
-        AttributeTO userIdTO = new AttributeTO();
-        userIdTO.setSchema("userId");
-        userIdTO.addValue("user5@syncope.apache.org");
-        userTO.addAttribute(userIdTO);
-
-        AttributeTO emailTO = new AttributeTO();
-        emailTO.setSchema("email");
-        emailTO.addValue("user5@syncope.apache.org");
-        userTO.addAttribute(emailTO);
-
-        // add a derived attribute (accountId for csvdir)
-        AttributeTO csvuseridTO = new AttributeTO();
-        csvuseridTO.setSchema("csvuserid");
-        userTO.addDerivedAttribute(csvuseridTO);
+        userTO.addAttribute(attributeTO("firstname", "nome9"));
+        userTO.addAttribute(attributeTO("surname", "cognome"));
+        userTO.addAttribute(attributeTO("type", "a type"));
+        userTO.addAttribute(attributeTO("fullname", "nome cognome"));
+        userTO.addAttribute(attributeTO("userId", "user5@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("email", "user5@syncope.apache.org"));
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
@@ -268,24 +244,13 @@ public class TaskTestITCase extends Abst
 
         //  add user template
         UserTO template = new UserTO();
-
-        AttributeTO attrTO = new AttributeTO();
-        attrTO.setSchema("type");
-        attrTO.addValue("email == 'test8@syncope.apache.org'? 'TYPE_8': 'TYPE_OTHER'");
-        template.addAttribute(attrTO);
-
-        attrTO = new AttributeTO();
-        attrTO.setSchema("cn");
-        template.addDerivedAttribute(attrTO);
-
+        template.addAttribute(attributeTO("type", "email == 'test8@syncope.apache.org'? 'TYPE_8':
'TYPE_OTHER'"));
+        template.addDerivedAttribute(attributeTO("cn", null));
         template.addResource("resource-testdb");
 
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(8L);
-        AttributeTO membershipAttr = new AttributeTO();
-        membershipAttr.setSchema("subscriptionDate");
-        membershipAttr.addValue("'2009-08-18T16:33:12.203+0200'");
-        membershipTO.addAttribute(membershipAttr);
+        membershipTO.addAttribute(attributeTO("subscriptionDate", "'2009-08-18T16:33:12.203+0200'"));
         template.addMembership(membershipTO);
 
         task.setUserTemplate(template);
@@ -296,7 +261,6 @@ public class TaskTestITCase extends Abst
         assertEquals(TestSyncActions.class.getName(), actual.getActionsClassName());
 
         SyncTaskTO taskTO = restTemplate.getForObject(BASE_URL + "task/read/{taskId}", SyncTaskTO.class,
4L);
-
         assertNotNull(taskTO);
         assertNotNull(taskTO.getExecutions());
 
@@ -375,26 +339,10 @@ public class TaskTestITCase extends Abst
 
         //  add user template
         UserTO template = new UserTO();
-
-        AttributeTO attrTO = new AttributeTO();
-        attrTO.setSchema("type");
-        attrTO.addValue("'type a'");
-        template.addAttribute(attrTO);
-
-        attrTO = new AttributeTO();
-        attrTO.setSchema("userId");
-        attrTO.addValue("'reconciled@syncope.apache.org'");
-        template.addAttribute(attrTO);
-
-        attrTO = new AttributeTO();
-        attrTO.setSchema("fullname");
-        attrTO.addValue("'reconciled fullname'");
-        template.addAttribute(attrTO);
-
-        attrTO = new AttributeTO();
-        attrTO.setSchema("surname");
-        attrTO.addValue("'surname'");
-        template.addAttribute(attrTO);
+        template.addAttribute(attributeTO("type", "'type a'"));
+        template.addAttribute(attributeTO("userId", "'reconciled@syncope.apache.org'"));
+        template.addAttribute(attributeTO("fullname", "'reconciled fullname'"));
+        template.addAttribute(attributeTO("surname", "'surname'"));
 
         task.setUserTemplate(template);
 
@@ -595,35 +543,12 @@ public class TaskTestITCase extends Abst
         userTO.setPassword("password123");
         userTO.setUsername("testuser2");
 
-        AttributeTO firstnameTO = new AttributeTO();
-        firstnameTO.setSchema("firstname");
-        firstnameTO.addValue("testuser2");
-        userTO.addAttribute(firstnameTO);
-
-        AttributeTO surnameTO = new AttributeTO();
-        surnameTO.setSchema("surname");
-        surnameTO.addValue("testuser2");
-        userTO.addAttribute(surnameTO);
-
-        AttributeTO typeTO = new AttributeTO();
-        typeTO.setSchema("type");
-        typeTO.addValue("a type");
-        userTO.addAttribute(typeTO);
-
-        AttributeTO fullnameTO = new AttributeTO();
-        fullnameTO.setSchema("fullname");
-        fullnameTO.addValue("testuser2");
-        userTO.addAttribute(fullnameTO);
-
-        AttributeTO userIdTO = new AttributeTO();
-        userIdTO.setSchema("userId");
-        userIdTO.addValue("testuser2@syncope.apache.org");
-        userTO.addAttribute(userIdTO);
-
-        AttributeTO emailTO = new AttributeTO();
-        emailTO.setSchema("email");
-        emailTO.addValue("testuser2@syncope.apache.org");
-        userTO.addAttribute(emailTO);
+        userTO.addAttribute(attributeTO("firstname", "testuser2"));
+        userTO.addAttribute(attributeTO("surname", "testuser2"));
+        userTO.addAttribute(attributeTO("type", "a type"));
+        userTO.addAttribute(attributeTO("fullname", "a type"));
+        userTO.addAttribute(attributeTO("userId", "testuser2@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("email", "testuser2@syncope.apache.org"));
 
         userTO.addResource("ws-target-resource-nopropagation2");
         userTO.addResource("ws-target-resource-nopropagation4");

Modified: syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1419262&r1=1419261&r2=1419262&view=diff
==============================================================================
--- syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
(original)
+++ syncope/branches/DEV_ROLE_PROVISIONING/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
Mon Dec 10 08:41:50 2012
@@ -29,20 +29,14 @@ import java.util.List;
 import java.util.Map;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.impl.client.DefaultHttpClient;
-import org.identityconnectors.framework.common.objects.OperationalAttributes;
-import org.junit.Test;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.http.HttpStatus;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.web.client.HttpStatusCodeException;
 import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
 import org.apache.syncope.client.mod.AttributeMod;
 import org.apache.syncope.client.mod.MembershipMod;
 import org.apache.syncope.client.mod.UserMod;
 import org.apache.syncope.client.to.AttributeTO;
-import org.apache.syncope.client.to.MembershipTO;
 import org.apache.syncope.client.to.ConfigurationTO;
 import org.apache.syncope.client.to.ConnObjectTO;
+import org.apache.syncope.client.to.MembershipTO;
 import org.apache.syncope.client.to.PasswordPolicyTO;
 import org.apache.syncope.client.to.PolicyTO;
 import org.apache.syncope.client.to.PropagationTO;
@@ -59,11 +53,17 @@ import org.apache.syncope.core.persisten
 import org.apache.syncope.types.CipherAlgorithm;
 import org.apache.syncope.types.PropagationTaskExecStatus;
 import org.apache.syncope.types.SyncopeClientExceptionType;
+import org.identityconnectors.framework.common.objects.OperationalAttributes;
 import org.junit.Assume;
 import org.junit.FixMethodOrder;
+import org.junit.Test;
 import org.junit.runners.MethodSorters;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.http.HttpStatus;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.util.StringUtils;
 import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpStatusCodeException;
 
 @FixMethodOrder(MethodSorters.JVM)
 public class UserTestITCase extends AbstractTest {
@@ -73,53 +73,16 @@ public class UserTestITCase extends Abst
         userTO.setPassword("password123");
         userTO.setUsername(email);
 
-        AttributeTO fullnameTO = new AttributeTO();
-        fullnameTO.setSchema("fullname");
-        fullnameTO.addValue(email);
-        userTO.addAttribute(fullnameTO);
-
-        AttributeTO firstnameTO = new AttributeTO();
-        firstnameTO.setSchema("firstname");
-        firstnameTO.addValue(email);
-        userTO.addAttribute(firstnameTO);
-
-        AttributeTO surnameTO = new AttributeTO();
-        surnameTO.setSchema("surname");
-        surnameTO.addValue("Surname");
-        userTO.addAttribute(surnameTO);
-
-        AttributeTO typeTO = new AttributeTO();
-        typeTO.setSchema("type");
-        typeTO.addValue("a type");
-        userTO.addAttribute(typeTO);
-
-        AttributeTO userIdTO = new AttributeTO();
-        userIdTO.setSchema("userId");
-        userIdTO.addValue(email);
-        userTO.addAttribute(userIdTO);
-
-        AttributeTO emailTO = new AttributeTO();
-        emailTO.setSchema("email");
-        emailTO.addValue(email);
-        userTO.addAttribute(emailTO);
-
-        AttributeTO loginDateTO = new AttributeTO();
-        loginDateTO.setSchema("loginDate");
+        userTO.addAttribute(attributeTO("fullname", email));
+        userTO.addAttribute(attributeTO("firstname", email));
+        userTO.addAttribute(attributeTO("surname", "surname"));
+        userTO.addAttribute(attributeTO("type", "a type"));
+        userTO.addAttribute(attributeTO("userId", email));
+        userTO.addAttribute(attributeTO("email", email));
         DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        loginDateTO.addValue(sdf.format(new Date()));
-        userTO.addAttribute(loginDateTO);
-
-        // add a derived attribute
-        AttributeTO cnTO = new AttributeTO();
-        cnTO.setSchema("cn");
-        userTO.addDerivedAttribute(cnTO);
-
-        // add a virtual attribute
-        AttributeTO virtualdata = new AttributeTO();
-        virtualdata.setSchema("virtualdata");
-        virtualdata.addValue("virtualvalue");
-        userTO.addVirtualAttribute(virtualdata);
-
+        userTO.addAttribute(attributeTO("loginDate", sdf.format(new Date())));
+        userTO.addDerivedAttribute(attributeTO("cn", null));
+        userTO.addVirtualAttribute(attributeTO("virtualdata", "virtualvalue"));
         return userTO;
     }
 
@@ -162,25 +125,10 @@ public class UserTestITCase extends Abst
         UserTO userTO = new UserTO();
         userTO.setUsername("xxx@xxx.xxx");
 
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("firstname");
-        attributeTO.addValue("xxx");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("surname");
-        attributeTO.addValue("xxx");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("xxx@xxx.xxx");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("fullname");
-        attributeTO.addValue("xxx");
-        userTO.addAttribute(attributeTO);
+        userTO.addAttribute(attributeTO("firstname", "xxx"));
+        userTO.addAttribute(attributeTO("surname", "xxx"));
+        userTO.addAttribute(attributeTO("userId", "xxx@xxx.xxx"));
+        userTO.addAttribute(attributeTO("fullname", "xxx"));
 
         userTO.setPassword("password123");
         userTO.addResource("ws-target-resource-nopropagation");
@@ -189,7 +137,6 @@ public class UserTestITCase extends Abst
 
         // get the new task list
         tasks = Arrays.asList(restTemplate.getForObject(BASE_URL + "task/propagation/list",
PropagationTaskTO[].class));
-
         assertNotNull(tasks);
         assertFalse(tasks.isEmpty());
 
@@ -229,25 +176,10 @@ public class UserTestITCase extends Abst
         userTO.setUsername("issue172@syncope.apache.org");
         userTO.setPassword("password");
 
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("firstname");
-        attributeTO.addValue("issue172");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("surname");
-        attributeTO.addValue("issue172");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("issue172@syncope.apache.org");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("fullname");
-        attributeTO.addValue("issue172");
-        userTO.addAttribute(attributeTO);
+        userTO.addAttribute(attributeTO("firstname", "issue172"));
+        userTO.addAttribute(attributeTO("surname", "issue172"));
+        userTO.addAttribute(attributeTO("userId", "issue172@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("fullname", "issue172"));
 
         restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
 
@@ -263,20 +195,9 @@ public class UserTestITCase extends Abst
         userTO.setUsername("issue186@syncope.apache.org");
         userTO.setPassword("password");
 
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("issue186@syncope.apache.org");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("fullname");
-        attributeTO.addValue("issue186");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("surname");
-        attributeTO.addValue("issue186");
-        userTO.addAttribute(attributeTO);
+        userTO.addAttribute(attributeTO("userId", "issue186@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("fullname", "issue186"));
+        userTO.addAttribute(attributeTO("surname", "issue186"));
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
@@ -379,9 +300,7 @@ public class UserTestITCase extends Abst
         }
         assertNotNull(sce);
 
-        AttributeTO derAttTO = new AttributeTO();
-        derAttTO.setSchema("csvuserid");
-        userTO.addDerivedAttribute(derAttTO);
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
@@ -422,29 +341,11 @@ public class UserTestITCase extends Abst
         UserTO userTO = new UserTO();
         userTO.setPassword("password");
         userTO.setUsername("yyy@yyy.yyy");
-
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("firstname");
-        attributeTO.addValue("yyy");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("surname");
-        attributeTO.addValue("yyy");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("yyy@yyy.yyy");
-        userTO.addAttribute(attributeTO);
-
-        attributeTO = new AttributeTO();
-        attributeTO.setSchema("fullname");
-        attributeTO.addValue("yyy");
-        userTO.addAttribute(attributeTO);
-
+        userTO.addAttribute(attributeTO("firstname", "yyy"));
+        userTO.addAttribute(attributeTO("surname", "yyy"));
+        userTO.addAttribute(attributeTO("userId", "yyy@yyy.yyy"));
+        userTO.addAttribute(attributeTO("fullname", "yyy"));
         userTO.addResource("resource-testdb");
-
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
         assertNotNull(userTO);
         assertEquals(1, userTO.getPropagationTOs().size());
@@ -501,13 +402,8 @@ public class UserTestITCase extends Abst
 
     @Test(expected = SyncopeClientCompositeErrorException.class)
     public void createWithException() {
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("userId@nowhere.org");
-
         UserTO newUserTO = new UserTO();
-        newUserTO.addAttribute(attributeTO);
-
+        newUserTO.addAttribute(attributeTO("userId", "userId@nowhere.org"));
         restTemplate.postForObject(BASE_URL + "user/create", newUserTO, UserTO.class);
     }
 
@@ -541,22 +437,14 @@ public class UserTestITCase extends Abst
         userTO.addMembership(membershipTO);
 
         // add an attribute with no values: must be ignored
-        AttributeTO nullValueAttrTO = new AttributeTO();
-        nullValueAttrTO.setSchema("subscriptionDate");
-        nullValueAttrTO.setValues(null);
-        membershipTO.addAttribute(nullValueAttrTO);
+        membershipTO.addAttribute(attributeTO("subscriptionDate", null));
 
         // add an attribute with a non-existing schema: must be ignored
-        AttributeTO attrWithInvalidSchemaTO = new AttributeTO();
-        attrWithInvalidSchemaTO.setSchema("invalid schema");
-        attrWithInvalidSchemaTO.addValue("a value");
+        AttributeTO attrWithInvalidSchemaTO = attributeTO("invalid schema", "a value");
         userTO.addAttribute(attrWithInvalidSchemaTO);
 
         // add an attribute with null value: must be ignored
-        nullValueAttrTO = new AttributeTO();
-        nullValueAttrTO.setSchema("activationDate");
-        nullValueAttrTO.addValue(null);
-        userTO.addAttribute(nullValueAttrTO);
+        userTO.addAttribute(attributeTO("activationDate", null));
 
         // 1. create user
         UserTO newUserTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
@@ -657,10 +545,7 @@ public class UserTestITCase extends Abst
         assertNotNull(ex);
         assertNotNull(ex.getException(SyncopeClientExceptionType.RequiredValuesMissing));
 
-        AttributeTO fType = new AttributeTO();
-        fType.setSchema("type");
-        fType.addValue("F");
-        userTO.addAttribute(fType);
+        userTO.addAttribute(attributeTO("type", "F"));
 
         AttributeTO surname = null;
         for (AttributeTO attributeTO : userTO.getAttributes()) {
@@ -992,10 +877,7 @@ public class UserTestITCase extends Abst
 
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(8L);
-        AttributeTO membershipAttr = new AttributeTO();
-        membershipAttr.setSchema("subscriptionDate");
-        membershipAttr.addValue("2009-08-18T16:33:12.203+0200");
-        membershipTO.addAttribute(membershipAttr);
+        membershipTO.addAttribute(attributeTO("subscriptionDate", "2009-08-18T16:33:12.203+0200"));
         userTO.addMembership(membershipTO);
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
@@ -1003,29 +885,19 @@ public class UserTestITCase extends Abst
         assertFalse(userTO.getDerivedAttributes().isEmpty());
         assertEquals(1, userTO.getMemberships().size());
 
-        AttributeMod attributeMod = new AttributeMod();
-        attributeMod.setSchema("subscriptionDate");
-        attributeMod.addValueToBeAdded("2010-08-18T16:33:12.203+0200");
-
         MembershipMod membershipMod = new MembershipMod();
         membershipMod.setRole(8L);
-        membershipMod.addAttributeToBeUpdated(attributeMod);
+        membershipMod.addAttributeToBeUpdated(attributeMod("subscriptionDate", "2010-08-18T16:33:12.203+0200"));
 
         UserMod userMod = new UserMod();
         userMod.setId(userTO.getId());
         userMod.setPassword("new2Password");
 
         userMod.addAttributeToBeRemoved("userId");
-        attributeMod = new AttributeMod();
-        attributeMod.setSchema("userId");
-        attributeMod.addValueToBeAdded("t.w@spre.net");
-        userMod.addAttributeToBeUpdated(attributeMod);
+        userMod.addAttributeToBeUpdated(attributeMod("userId", "t.w@spre.net"));
 
         userMod.addAttributeToBeRemoved("fullname");
-        attributeMod = new AttributeMod();
-        attributeMod.setSchema("fullname");
-        attributeMod.addValueToBeAdded("g.h@t.com");
-        userMod.addAttributeToBeUpdated(attributeMod);
+        userMod.addAttributeToBeUpdated(attributeMod("fullname", "g.h@t.com"));
 
         userMod.addDerivedAttributeToBeAdded("cn");
         userMod.addMembershipToBeAdded(membershipMod);
@@ -1069,10 +941,7 @@ public class UserTestITCase extends Abst
         UserTO userTO = getSampleTO("pwdonly@t.com");
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(8L);
-        AttributeTO membershipAttr = new AttributeTO();
-        membershipAttr.setSchema("subscriptionDate");
-        membershipAttr.addValue("2009-08-18T16:33:12.203+0200");
-        membershipTO.addAttribute(membershipAttr);
+        membershipTO.addAttribute(attributeTO("subscriptionDate", "2009-08-18T16:33:12.203+0200"));
         userTO.addMembership(membershipTO);
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
@@ -1155,10 +1024,7 @@ public class UserTestITCase extends Abst
         UserMod userMod = new UserMod();
         userMod.setId(userTO.getId());
 
-        AttributeMod attributeMod = new AttributeMod();
-        attributeMod.setSchema("surname");
-        attributeMod.addValueToBeAdded("surname");
-        userMod.addAttributeToBeUpdated(attributeMod);
+        userMod.addAttributeToBeUpdated(attributeMod("surname", "surname"));
 
         userTO = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
 
@@ -1471,7 +1337,7 @@ public class UserTestITCase extends Abst
         // 1. create a new user without virtual attributes
         UserTO original = getSampleTO("issue270@syncope.apache.org");
         // be sure to remove all virtual attributes
-        original.setVirtualAttributes(Collections.EMPTY_LIST);
+        original.setVirtualAttributes(Collections.<AttributeTO>emptyList());
 
         original = restTemplate.postForObject(BASE_URL + "user/create", original, UserTO.class);
 
@@ -1482,11 +1348,7 @@ public class UserTestITCase extends Abst
         UserTO toBeUpdated = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json",
UserTO.class, original.
                 getId());
 
-        AttributeTO virtual = new AttributeTO();
-
-        virtual.setSchema("virtualdata");
-        virtual.addValue("virtualvalue");
-
+        AttributeTO virtual = attributeTO("virtualdata", "virtualvalue");
         toBeUpdated.addVirtualAttribute(virtual);
 
         // 2. try to update by adding a resource, but no password: must fail
@@ -1562,11 +1424,7 @@ public class UserTestITCase extends Abst
     @Test
     public void issue288() {
         UserTO userTO = getSampleTO("issue288@syncope.apache.org");
-
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("aLong");
-        attributeTO.addValue("STRING");
-        userTO.addAttribute(attributeTO);
+        userTO.addAttribute(attributeTO("aLong", "STRING"));
 
         try {
             restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
@@ -1584,9 +1442,7 @@ public class UserTestITCase extends Abst
         userTO.getDerivedAttributes().clear();
         userTO.getVirtualAttributes().clear();
 
-        AttributeTO csvuserid = new AttributeTO();
-        csvuserid.setSchema("csvuserid");
-        userTO.addDerivedAttribute(csvuserid);
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(1L);
@@ -1614,28 +1470,13 @@ public class UserTestITCase extends Abst
         userTO.getMemberships().clear();
         userTO.getDerivedAttributes().clear();
         userTO.getVirtualAttributes().clear();
-
-        AttributeTO csvuserid = new AttributeTO();
-        csvuserid.setSchema("csvuserid");
-        userTO.addDerivedAttribute(csvuserid);
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(1L);
-
-        AttributeTO mderived_sx = new AttributeTO();
-        mderived_sx.setSchema("mderived_sx");
-        mderived_sx.setValues(Collections.singletonList("sx"));
-        membershipTO.addAttribute(mderived_sx);
-
-        AttributeTO mderived_dx = new AttributeTO();
-        mderived_dx.setSchema("mderived_dx");
-        mderived_dx.setValues(Collections.singletonList("dx"));
-        membershipTO.addAttribute(mderived_dx);
-
-        AttributeTO mderiveddata = new AttributeTO();
-        mderiveddata.setSchema("mderToBePropagated");
-        membershipTO.addDerivedAttribute(mderiveddata);
-
+        membershipTO.addAttribute(attributeTO("mderived_sx", "sx"));
+        membershipTO.addAttribute(attributeTO("mderived_dx", "dx"));
+        membershipTO.addDerivedAttribute(attributeTO("mderToBePropagated", null));
         userTO.addMembership(membershipTO);
 
         userTO.addResource("resource-csv");
@@ -1671,13 +1512,8 @@ public class UserTestITCase extends Abst
 
         UserMod userMod = new UserMod();
         userMod.setId(actual.getId());
-
-        AttributeMod virtualdata = new AttributeMod();
-        virtualdata.setSchema("virtualdata");
-        virtualdata.addValueToBeAdded("virtualupdated");
-
         userMod.addVirtualAttributeToBeRemoved("virtualdata");
-        userMod.addVirtualAttributeToBeUpdated(virtualdata);
+        userMod.addVirtualAttributeToBeUpdated(attributeMod("virtualdata", "virtualupdated"));
 
         // 3. update virtual attribute
         actual = restTemplate.postForObject(BASE_URL + "user/update", userMod, UserTO.class);
@@ -1696,10 +1532,7 @@ public class UserTestITCase extends Abst
         userTO.getMemberships().clear();
         userTO.getDerivedAttributes().clear();
         userTO.getVirtualAttributes().clear();
-
-        AttributeTO csvuserid = new AttributeTO();
-        csvuserid.setSchema("csvuserid");
-        userTO.addDerivedAttribute(csvuserid);
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         MembershipTO memb12 = new MembershipTO();
         memb12.setRoleId(12L);
@@ -1796,25 +1629,15 @@ public class UserTestITCase extends Abst
         userTO.getMemberships().clear();
         userTO.getDerivedAttributes().clear();
         userTO.getVirtualAttributes().clear();
-
-        AttributeTO csvuserid = new AttributeTO();
-        csvuserid.setSchema("csvuserid");
-        userTO.addDerivedAttribute(csvuserid);
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         MembershipTO memb12 = new MembershipTO();
         memb12.setRoleId(12L);
-
-        AttributeTO postalAddress = new AttributeTO();
-        postalAddress.setSchema("postalAddress");
-        postalAddress.addValue("postalAddress");
-
-        memb12.addAttribute(postalAddress);
-
+        memb12.addAttribute(attributeTO("postalAddress", "postalAddress"));
         userTO.addMembership(memb12);
 
         MembershipTO memb13 = new MembershipTO();
         memb13.setRoleId(13L);
-
         userTO.addMembership(memb13);
 
         userTO.addResource("resource-ldap");
@@ -1830,7 +1653,7 @@ public class UserTestITCase extends Abst
                 userTO.getUsername());
         assertNotNull(connObjectTO);
 
-        postalAddress = connObjectTO.getAttributeMap().get("postalAddress");
+        AttributeTO postalAddress = connObjectTO.getAttributeMap().get("postalAddress");
         assertNotNull(postalAddress);
         assertEquals(1, postalAddress.getValues().size());
         assertEquals("postalAddress", postalAddress.getValues().get(0));



Mime
View raw message