syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1607611 - in /syncope/trunk/core/src/test: java/org/apache/syncope/core/rest/TaskTestITCase.java resources/content.xml
Date Thu, 03 Jul 2014 12:38:37 GMT
Author: ilgrosso
Date: Thu Jul  3 12:38:37 2014
New Revision: 1607611

URL: http://svn.apache.org/r1607611
Log:
[SYNCOPE-313] Resolving IT conflicts

Modified:
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
    syncope/trunk/core/src/test/resources/content.xml

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=1607611&r1=1607610&r2=1607611&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 Thu
Jul  3 12:38:37 2014
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.core.rest;
 
+import static org.apache.syncope.core.rest.AbstractTest.userService;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -36,9 +37,7 @@ import java.util.concurrent.ExecutorServ
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
-
 import javax.ws.rs.core.Response;
-
 import org.apache.syncope.client.SyncopeClient;
 import org.apache.syncope.common.SyncopeClientException;
 import org.apache.syncope.common.mod.StatusMod;
@@ -71,19 +70,23 @@ import org.apache.syncope.common.types.C
 import org.apache.syncope.common.types.IntMappingType;
 import org.apache.syncope.common.types.MatchingRule;
 import org.apache.syncope.common.types.PropagationTaskExecStatus;
+import org.apache.syncope.common.types.ResourceDeassociationActionType;
 import org.apache.syncope.common.types.TaskType;
 import org.apache.syncope.common.types.TraceLevel;
 import org.apache.syncope.common.types.SubjectType;
 import org.apache.syncope.common.types.UnmatchingRule;
+import org.apache.syncope.common.util.CollectionWrapper;
 import org.apache.syncope.common.wrap.PushActionClass;
+import org.apache.syncope.common.wrap.ResourceName;
+import org.apache.syncope.core.sync.TestSyncActions;
 import org.apache.syncope.core.sync.TestSyncRule;
 import org.apache.syncope.core.sync.impl.DBPasswordSyncActions;
 import org.apache.syncope.core.sync.impl.LDAPPasswordSyncActions;
 import org.apache.syncope.core.sync.impl.SyncJob;
 import org.apache.syncope.core.util.Encryptor;
 import org.apache.syncope.core.workflow.ActivitiDetector;
-import org.identityconnectors.framework.common.objects.AttributeUtil;
 import org.identityconnectors.framework.common.objects.Name;
+import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
@@ -97,10 +100,17 @@ public class TaskTestITCase extends Abst
 
     private static final Long SYNC_TASK_ID = 4L;
 
+    @BeforeClass
+    public static void testSyncActionsSetup() {
+        SyncTaskTO syncTask = taskService.read(SYNC_TASK_ID);
+        syncTask.getActionsClassNames().add(TestSyncActions.class.getName());
+        taskService.update(SYNC_TASK_ID, syncTask);
+    }
+
     /**
      * Remove initial and synchronized users to make test re-runnable.
      */
-    public void removeTestUsers() {
+    private void removeTestUsers() {
         for (int i = 0; i < 10; i++) {
             String cUserName = "test" + i;
             try {
@@ -351,7 +361,7 @@ public class TaskTestITCase extends Abst
             assertTrue(Integer.valueOf(userTO.getAttrMap().get("fullname").getValues().get(0))
<= 10);
             assertTrue(userTO.getResources().contains(RESOURCE_NAME_TESTDB));
             assertTrue(userTO.getResources().contains(RESOURCE_NAME_WS2));
-            
+
             // Matching --> Update (no link)
             assertFalse(userTO.getResources().contains(RESOURCE_NAME_CSV));
 
@@ -394,7 +404,7 @@ public class TaskTestITCase extends Abst
             final Set<Long> pushTaskIds = new HashSet<Long>();
             pushTaskIds.add(25L);
             pushTaskIds.add(26L);
-            
+
             execSyncTasks(pushTaskIds, 50, false);
             // Matching --> UNLINK
             assertFalse(readUser("test9").getResources().contains(RESOURCE_NAME_CSV));
@@ -430,8 +440,37 @@ public class TaskTestITCase extends Abst
         assertEquals("active", userTO.getStatus());
     }
 
+    /**
+     * Clean Syncope and LDAP resource status.
+     */
+    private void ldapCleanup() {
+        PagedResult<RoleTO> matchingRoles = roleService.search(
+                SyncopeClient.getRoleSearchConditionBuilder().is("name").equalTo("testLDAPGroup").query());
+        if (matchingRoles.getSize() > 0) {
+            for (RoleTO role : matchingRoles.getResult()) {
+                roleService.bulkDeassociation(role.getId(),
+                        ResourceDeassociationActionType.UNLINK,
+                        CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class));
+                roleService.delete(role.getId());
+            }
+        }
+        PagedResult<UserTO> matchingUsers = userService.search(
+                SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("syncFromLDAP").query());
+        if (matchingUsers.getSize() > 0) {
+            for (UserTO user : matchingUsers.getResult()) {
+                userService.bulkDeassociation(user.getId(),
+                        ResourceDeassociationActionType.UNLINK,
+                        CollectionWrapper.wrap(RESOURCE_NAME_LDAP, ResourceName.class));
+                userService.delete(user.getId());
+            }
+        }
+    }
+
     @Test
     public void reconcileFromLDAP() {
+        // First of all, clear any potential conflict with existing user / role
+        ldapCleanup();
+
         // Update sync task
         TaskExecTO execution = execSyncTask(11L, 20, false);
 
@@ -1097,7 +1136,7 @@ public class TaskTestITCase extends Abst
             return test.execSyncTask(taskId, maxWaitSeconds, dryRun);
         }
     }
-    
+
     @Test
     public void issueSYNCOPE313DB() throws Exception {
         // 1. create user in DB
@@ -1117,7 +1156,7 @@ public class TaskTestITCase extends Abst
         // 3. Update the password in the DB
         String newPassword = Encryptor.getInstance().encode("new-security", CipherAlgorithm.SHA1);
         jdbcTemplate.execute(
-            "UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername()
+ "'");
+                "UPDATE test set PASSWORD='" + newPassword + "' where ID='" + user.getUsername()
+ "'");
 
         // 4. Sync the user from the resource
         SyncTaskTO syncTask = new SyncTaskTO();
@@ -1128,15 +1167,15 @@ public class TaskTestITCase extends Abst
         syncTask.setResource(RESOURCE_NAME_TESTDB);
         syncTask.getActionsClassNames().add(DBPasswordSyncActions.class.getName());
         Response taskResponse = taskService.create(syncTask);
-        
+
         SyncTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, SyncTaskTO.class);
         assertNotNull(actual);
-        
+
         syncTask = taskService.read(actual.getId());
         assertNotNull(syncTask);
         assertEquals(actual.getId(), syncTask.getId());
         assertEquals(actual.getJobClassName(), syncTask.getJobClassName());
-        
+
         TaskExecTO execution = execSyncTask(syncTask.getId(), 50, false);
         final String status = execution.getStatus();
         assertNotNull(status);
@@ -1145,16 +1184,17 @@ public class TaskTestITCase extends Abst
         // 5. Test the sync'd user
         UserTO updatedUser = userService.read(user.getId());
         assertEquals(newPassword, updatedUser.getPassword());
-        
+
         // 6. Delete SyncTask + user
         taskService.delete(syncTask.getId());
         deleteUser(user.getId());
     }
-    
-    // @Ignore'd for now as it is causing a failure in the 'reconcileFromLDAP' test
+
     @Test
-    @org.junit.Ignore
     public void issueSYNCOPE313LDAP() throws Exception {
+        // First of all, clear any potential conflict with existing user / role
+        ldapCleanup();
+
         // 1. create user in LDAP
         UserTO user = UserTestITCase.getUniqueSampleTO("syncope313-ldap@syncope.apache.org");
         user.setPassword("security");
@@ -1162,7 +1202,7 @@ public class TaskTestITCase extends Abst
         user = createUser(user);
         assertNotNull(user);
         assertFalse(user.getResources().isEmpty());
-        
+
         // 2. request to change password only on Syncope and not on LDAP
         UserMod userMod = new UserMod();
         userMod.setId(user.getId());
@@ -1172,31 +1212,29 @@ public class TaskTestITCase extends Abst
         pwdPropRequest.getResourceNames().clear();
         userMod.setPwdPropRequest(pwdPropRequest);
         updateUser(userMod);
-        
+
         // 3. Check that the Syncope user now has the changed password
         UserTO updatedUser = userService.read(user.getId());
-        String encodedNewPassword = 
-            Encryptor.getInstance().encode("new-security", CipherAlgorithm.SHA1);
+        String encodedNewPassword = Encryptor.getInstance().encode("new-security", CipherAlgorithm.SHA1);
         assertEquals(encodedNewPassword, updatedUser.getPassword());
 
         // 4. Check that the LDAP resource has the old password
-        ConnObjectTO connObject = 
+        ConnObjectTO connObject =
                 resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.USER,
user.getId());
-        
+
         assertNotNull(getLdapRemoteObject(
                 connObject.getAttrMap().get(Name.NAME).getValues().get(0),
                 "security",
                 connObject.getAttrMap().get(Name.NAME).getValues().get(0)));
-        
+
         // 5. Update the LDAP Connector to retrieve passwords
         ResourceTO ldapResource = resourceService.read(RESOURCE_NAME_LDAP);
         ConnInstanceTO resourceConnector = connectorService.read(ldapResource.getConnectorId());
-        ConnConfProperty property = 
-            resourceConnector.getConfigurationMap().get("retrievePasswordsWithSearch");
+        ConnConfProperty property = resourceConnector.getConfigurationMap().get("retrievePasswordsWithSearch");
         property.getValues().clear();
         property.getValues().add(Boolean.TRUE);
         connectorService.update(ldapResource.getConnectorId(), resourceConnector);
-        
+
         // 6. Sync the user from the resource
         SyncTaskTO syncTask = new SyncTaskTO();
         syncTask.setName("LDAP Sync Task");
@@ -1206,15 +1244,15 @@ public class TaskTestITCase extends Abst
         syncTask.setResource(RESOURCE_NAME_LDAP);
         syncTask.getActionsClassNames().add(LDAPPasswordSyncActions.class.getName());
         Response taskResponse = taskService.create(syncTask);
-        
+
         SyncTaskTO actual = getObject(taskResponse.getLocation(), TaskService.class, SyncTaskTO.class);
         assertNotNull(actual);
-        
+
         syncTask = taskService.read(actual.getId());
         assertNotNull(syncTask);
         assertEquals(actual.getId(), syncTask.getId());
         assertEquals(actual.getJobClassName(), syncTask.getJobClassName());
-        
+
         TaskExecTO execution = execSyncTask(syncTask.getId(), 50, false);
         final String status = execution.getStatus();
         assertNotNull(status);
@@ -1224,7 +1262,7 @@ public class TaskTestITCase extends Abst
         String syncedPassword = Encryptor.getInstance().encode("security", CipherAlgorithm.SHA1);
         updatedUser = userService.read(user.getId());
         assertEquals(syncedPassword, updatedUser.getPassword());
-        
+
         // 8. Delete SyncTask + user + reset the connector
         taskService.delete(syncTask.getId());
         property.getValues().clear();

Modified: syncope/trunk/core/src/test/resources/content.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/resources/content.xml?rev=1607611&r1=1607610&r2=1607611&view=diff
==============================================================================
--- syncope/trunk/core/src/test/resources/content.xml (original)
+++ syncope/trunk/core/src/test/resources/content.xml Thu Jul  3 12:38:37 2014
@@ -884,7 +884,6 @@ under the License.
         jobClassName="org.apache.syncope.core.sync.impl.SyncJob" unmatchingRule="ASSIGN"
matchingRule="UPDATE"
         userTemplate='{"creator":null,"creationDate":null,"lastModifier":null,"lastChangeDate":null,"id":0,"password":null,"status":null,"token":null,"tokenExpireTime":null,"username":null,"lastLoginDate":null,"changePwdDate":null,"failedLogins":null,"attributes":[{"schema":"type","readonly":false,"values":["email
== &apos;test8@syncope.apache.org&apos;? &apos;TYPE_8&apos;: &apos;TYPE_OTHER&apos;"]}],"derivedAttributes":[{"schema":"cn","readonly":false,"values":[null]}],"virtualAttributes":[],"resources":["resource-testdb"],"propagationStatuses":[],"memberships":[{"creator":null,"creationDate":null,"lastModifier":null,"lastChangeDate":null,"id":0,"roleId":8,"roleName":null,"attributes":[{"schema":"subscriptionDate","readonly":false,"values":["&apos;2009-08-18T16:33:12.203+0200&apos;"]}],"derivedAttributes":[],"virtualAttributes":[]}]}'
         roleTemplate='{"creator":null,"creationDate":null,"lastModifier":null,"lastChangeDate":null,"id":0,"name":null,"parent":0,"userOwner":null,"roleOwner":null,"inheritOwner":false,"inheritTemplates":false,"inheritAttrs":false,"inheritDerAttrs":false,"inheritVirAttrs":false,"inheritPasswordPolicy":false,"inheritAccountPolicy":false,"passwordPolicy":null,"accountPolicy":null,"attributes":[],"derivedAttributes":[],"virtualAttributes":[],"resources":[],"propagationStatuses":[],"entitlements":[],"rAttrTemplates":[],"rDerAttrTemplates":[],"rVirAttrTemplates":[],"mAttrTemplates":[],"mDerAttrTemplates":[],"mVirAttrTemplates":[]}'/>
-  <SyncTask_actionsClassNames SyncTask_id="4" element="org.apache.syncope.core.sync.TestSyncActions"/>
   <Task DTYPE="SchedTask" id="5" name="SampleJob Task" jobClassName="org.apache.syncope.core.quartz.SampleJob"
cronExpression="0 0 0 1 * ?"/>
   <Task DTYPE="PropagationTask" id="6" propagationMode="TWO_PHASES" propagationOperation="UPDATE"
         objectClassName="__ACCOUNT__" resource_name="ws-target-resource-nopropagation" subjectType="USER"
subjectId="1"



Mime
View raw message