Author: ilgrosso
Date: Mon Dec 10 08:28:43 2012
New Revision: 1419259

URL: http://svn.apache.org/viewvc?rev=1419259&view=rev
Log:
[SYNCOPE-245] Applying provided patch

Modified:
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java

Modified: 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1419259&r1=1419258&r2=1419259&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java 
(original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java 
Mon Dec 10 08:28:43 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/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1419259&r1=1419258&r2=1419259&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
 (original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
 Mon Dec 10 08:28:43 2012
@@ -18,39 +18,37 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
 import java.util.ArrayList;
+import java.util.Arrays;
 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.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 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;
 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 {
@@ -77,10 +75,6 @@ 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 actual = restTemplate.postForObject(BASE_URL + "role/create", 
roleTO, RoleTO.class);
 
         roleTO.setId(actual.getId());
@@ -204,10 +198,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 = restTemplate.postForObject(BASE_URL + "role/create", roleTO, 
RoleTO.class);
 
@@ -219,14 +210,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);
@@ -249,10 +236,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);
 
@@ -274,10 +258,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);
 
@@ -364,12 +345,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/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java?rev=1419259&r1=1419258&r2=1419259&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
 (original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/SchemaTestITCase.java
 Mon Dec 10 08:28:43 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("issue...@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("issue...@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("issue...@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/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1419259&r1=1419258&r2=1419259&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
 (original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
 Mon Dec 10 08:28:43 2012
@@ -18,40 +18,43 @@
  */
 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.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);
@@ -59,6 +62,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);
@@ -209,41 +213,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("us...@syncope.apache.org");
-        userTO.addAttribute(userIdTO);
-
-        AttributeTO emailTO = new AttributeTO();
-        emailTO.setSchema("email");
-        emailTO.addValue("us...@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", "us...@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("email", "us...@syncope.apache.org"));
+        userTO.addDerivedAttribute(attributeTO("csvuserid", null));
 
         userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, 
UserTO.class);
         assertNotNull(userTO);
@@ -261,24 +237,13 @@ public class TaskTestITCase extends Abst
 
         //  add user template
         UserTO template = new UserTO();
-
-        AttributeTO attrTO = new AttributeTO();
-        attrTO.setSchema("type");
-        attrTO.addValue("email == 'te...@syncope.apache.org'? 'TYPE_8': 
'TYPE_OTHER'");
-        template.addAttribute(attrTO);
-
-        attrTO = new AttributeTO();
-        attrTO.setSchema("cn");
-        template.addDerivedAttribute(attrTO);
-
+        template.addAttribute(attributeTO("type", "email == 
'te...@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);
@@ -289,7 +254,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());
 
@@ -368,26 +332,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("'reconci...@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", 
"'reconci...@syncope.apache.org'"));
+        template.addAttribute(attributeTO("fullname", "'reconciled 
fullname'"));
+        template.addAttribute(attributeTO("surname", "'surname'"));
 
         task.setUserTemplate(template);
 
@@ -587,35 +535,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("testus...@syncope.apache.org");
-        userTO.addAttribute(userIdTO);
-
-        AttributeTO emailTO = new AttributeTO();
-        emailTO.setSchema("email");
-        emailTO.addValue("testus...@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", 
"testus...@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("email", 
"testus...@syncope.apache.org"));
 
         userTO.addResource("ws-target-resource-nopropagation2");
         userTO.addResource("ws-target-resource-nopropagation4");

Modified: 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1419259&r1=1419258&r2=1419259&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
 (original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java
 Mon Dec 10 08:28:43 2012
@@ -18,8 +18,6 @@
  */
 package org.apache.syncope.core.rest;
 
-import static org.junit.Assert.*;
-
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
@@ -31,24 +29,18 @@ import java.util.Map;
 import java.util.Set;
 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.search.AttributeCond;
-import org.apache.syncope.client.search.SyncopeUserCond;
-import org.apache.syncope.client.to.MembershipTO;
 import org.apache.syncope.client.search.NodeCond;
 import org.apache.syncope.client.search.ResourceCond;
+import org.apache.syncope.client.search.SyncopeUserCond;
+import org.apache.syncope.client.to.AttributeTO;
 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;
@@ -65,11 +57,18 @@ 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 static org.junit.Assert.*;
 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 {
@@ -79,53 +78,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;
     }
 
@@ -168,25 +130,10 @@ public class UserTestITCase extends Abst
         UserTO userTO = new UserTO();
         userTO.setUsername("x...@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("x...@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", "x...@xxx.xxx"));
+        userTO.addAttribute(attributeTO("fullname", "xxx"));
 
         userTO.setPassword("password123");
         userTO.addResource("ws-target-resource-nopropagation");
@@ -195,7 +142,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());
 
@@ -235,25 +181,10 @@ public class UserTestITCase extends Abst
         userTO.setUsername("issue...@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("issue...@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", 
"issue...@syncope.apache.org"));
+        userTO.addAttribute(attributeTO("fullname", "issue172"));
 
         restTemplate.postForObject(BASE_URL + "user/create", userTO, 
UserTO.class);
 
@@ -269,20 +200,9 @@ public class UserTestITCase extends Abst
         userTO.setUsername("issue...@syncope.apache.org");
         userTO.setPassword("password");
 
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("issue...@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", 
"issue...@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);
@@ -385,9 +305,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);
@@ -428,29 +346,11 @@ public class UserTestITCase extends Abst
         UserTO userTO = new UserTO();
         userTO.setPassword("password");
         userTO.setUsername("y...@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("y...@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", "y...@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());
@@ -507,13 +407,8 @@ public class UserTestITCase extends Abst
 
     @Test(expected = SyncopeClientCompositeErrorException.class)
     public void createWithException() {
-        AttributeTO attributeTO = new AttributeTO();
-        attributeTO.setSchema("userId");
-        attributeTO.addValue("use...@nowhere.org");
-
         UserTO newUserTO = new UserTO();
-        newUserTO.addAttribute(attributeTO);
-
+        newUserTO.addAttribute(attributeTO("userId", "use...@nowhere.org"));
         restTemplate.postForObject(BASE_URL + "user/create", newUserTO, 
UserTO.class);
     }
 
@@ -553,16 +448,11 @@ public class UserTestITCase extends Abst
         membershipTO.addAttribute(nullValueAttrTO);
 
         // 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);
@@ -663,10 +553,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()) {
@@ -1143,10 +1030,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);
@@ -1154,29 +1038,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...@spre.net");
-        userMod.addAttributeToBeUpdated(attributeMod);
+        userMod.addAttributeToBeUpdated(attributeMod("userId", 
"t...@spre.net"));
 
         userMod.addAttributeToBeRemoved("fullname");
-        attributeMod = new AttributeMod();
-        attributeMod.setSchema("fullname");
-        attributeMod.addValueToBeAdded("g...@t.com");
-        userMod.addAttributeToBeUpdated(attributeMod);
+        userMod.addAttributeToBeUpdated(attributeMod("fullname", 
"g...@t.com"));
 
         userMod.addDerivedAttributeToBeAdded("cn");
         userMod.addMembershipToBeAdded(membershipMod);
@@ -1220,10 +1094,7 @@ public class UserTestITCase extends Abst
         UserTO userTO = getSampleTO("pwdo...@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);
@@ -1306,10 +1177,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);
 
@@ -1628,7 +1496,7 @@ public class UserTestITCase extends Abst
         // 1. create a new user without virtual attributes
         UserTO original = getSampleTO("issue...@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);
 
@@ -1639,11 +1507,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
@@ -1719,11 +1583,7 @@ public class UserTestITCase extends Abst
     @Test
     public void issue288() {
         UserTO userTO = getSampleTO("issue...@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);
@@ -1741,9 +1601,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);
@@ -1773,10 +1631,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 membershipTO = new MembershipTO();
         membershipTO.setRoleId(1L);
@@ -1790,13 +1645,8 @@ public class UserTestITCase extends Abst
         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.addDerivedAttribute(attributeTO("mderToBePropagated", 
null));
         userTO.addMembership(membershipTO);
-
         userTO.addResource("resource-csv");
 
         UserTO actual = restTemplate.postForObject(BASE_URL + "user/create", 
userTO, UserTO.class);
@@ -1832,13 +1682,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);
@@ -1857,10 +1702,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);
@@ -1960,25 +1802,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");
@@ -1995,7 +1827,7 @@ public class UserTestITCase extends Abst
 
         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));
@@ -2058,7 +1890,7 @@ public class UserTestITCase extends Abst
         // 3. try (and fail) to find this user on the external LDAP resource
         SyncopeClientException sce = null;
         try {
-            ConnObjectTO connObjectTO = restTemplate.getForObject(
+            restTemplate.getForObject(
                     BASE_URL + "/resource/{resourceName}/read/{objectId}.json",
                     ConnObjectTO.class, "resource-ldap", userTO.getUsername());
             fail("This entry should not be present on this resource");


Reply via email to