You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by fm...@apache.org on 2012/05/04 12:29:15 UTC

svn commit: r1333862 - in /incubator/syncope/trunk/core/src: main/java/org/apache/syncope/core/notification/NotificationManager.java test/java/org/apache/syncope/core/rest/TaskTestITCase.java test/resources/content.xml

Author: fmartelli
Date: Fri May  4 10:29:14 2012
New Revision: 1333862

URL: http://svn.apache.org/viewvc?rev=1333862&view=rev
Log:
SYNCOPE-81 #comment task execution used to be saved twice

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

Modified: incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java?rev=1333862&r1=1333861&r2=1333862&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java (original)
+++ incubator/syncope/trunk/core/src/main/java/org/apache/syncope/core/notification/NotificationManager.java Fri May  4 10:29:14 2012
@@ -25,13 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import javassist.NotFoundException;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.exception.VelocityException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.ui.velocity.VelocityEngineUtils;
 import org.apache.syncope.core.persistence.beans.Notification;
 import org.apache.syncope.core.persistence.beans.NotificationTask;
 import org.apache.syncope.core.persistence.beans.TaskExec;
@@ -52,6 +45,13 @@ import org.apache.syncope.core.util.Conn
 import org.apache.syncope.core.util.EntitlementUtil;
 import org.apache.syncope.core.workflow.WorkflowResult;
 import org.apache.syncope.types.IntMappingType;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.VelocityException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.ui.velocity.VelocityEngineUtils;
 
 /**
  * Create notification tasks that will be executed by NotificationJob.
@@ -253,7 +253,7 @@ public class NotificationManager {
      */
     public TaskExec storeExecution(final TaskExec execution) {
         NotificationTask task = taskDAO.find(execution.getTask().getId());
-        task.addExec(execution);
+        execution.setTask(task);
         return taskExecDAO.save(execution);
     }
 

Modified: incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1333862&r1=1333861&r2=1333862&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java (original)
+++ incubator/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java Fri May  4 10:29:14 2012
@@ -28,6 +28,7 @@ import org.springframework.http.HttpStat
 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.NotificationTaskTO;
 import org.apache.syncope.client.to.TaskExecTO;
 import org.apache.syncope.client.to.PropagationTaskTO;
 import org.apache.syncope.client.to.SchedTaskTO;
@@ -171,8 +172,7 @@ public class TaskTestITCase extends Abst
         } catch (HttpStatusCodeException e) {
             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
         }
-        TaskExecTO execution = restTemplate
-                .postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, 1);
+        TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, 1);
         assertEquals(PropagationTaskExecStatus.SUBMITTED.name(), execution.getStatus());
 
         execution = restTemplate.getForObject(BASE_URL + "task/execution/report/{executionId}"
@@ -182,8 +182,8 @@ public class TaskTestITCase extends Abst
 
         restTemplate.getForObject(BASE_URL + "task/delete/{taskId}", PropagationTaskTO.class, 1);
         try {
-            restTemplate.getForObject(BASE_URL + "task/execution/read/{executionId}", TaskExecTO.class, execution
-                    .getId());
+            restTemplate.getForObject(BASE_URL + "task/execution/read/{executionId}", TaskExecTO.class,
+                    execution.getId());
         } catch (HttpStatusCodeException e) {
             assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());
         }
@@ -317,8 +317,7 @@ public class TaskTestITCase extends Abst
         assertTrue(Integer.valueOf(userTO.getAttributeMap().get("fullname").getValues().get(0)) <= 10);
 
         // check for user template
-        userTO = 
-            restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test7");
+        userTO = restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test7");
         assertNotNull(userTO);
         assertEquals("TYPE_OTHER", userTO.getAttributeMap().get("type").getValues().get(0));
         assertEquals(2, userTO.getResources().size());
@@ -327,8 +326,7 @@ public class TaskTestITCase extends Abst
         assertEquals(1, userTO.getMemberships().size());
         assertTrue(userTO.getMemberships().get(0).getAttributeMap().containsKey("subscriptionDate"));
 
-        userTO = 
-            restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test8");
+        userTO = restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test8");
         assertNotNull(userTO);
         assertEquals("TYPE_8", userTO.getAttributeMap().get("type").getValues().get(0));
 
@@ -341,13 +339,11 @@ public class TaskTestITCase extends Abst
         // * expected disabled user test1
         // * expected enabled user test2
 
-        userTO = 
-            restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test1");
+        userTO = restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test1");
         assertNotNull(userTO);
         assertEquals("suspended", userTO.getStatus());
 
-        userTO = 
-            restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test3");
+        userTO = restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "test3");
         assertNotNull(userTO);
         assertEquals("active", userTO.getStatus());
     }
@@ -419,8 +415,8 @@ public class TaskTestITCase extends Abst
         assertNotNull(status);
         assertTrue(PropagationTaskExecStatus.valueOf(status).isSuccessful());
 
-        final UserTO userTO = 
-            restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "testuser1");
+        final UserTO userTO =
+                restTemplate.getForObject(BASE_URL + "user/readByUsername/{username}.json", UserTO.class, "testuser1");
 
         assertNotNull(userTO);
         assertEquals("reconciled@syncope.apache.org", userTO.getAttributeMap().get("userId").getValues().get(0));
@@ -428,8 +424,7 @@ public class TaskTestITCase extends Abst
 
     @Test
     public void issue196() {
-        TaskExecTO execution = restTemplate
-                .postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, 6);
+        TaskExecTO execution = restTemplate.postForObject(BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, 6);
         assertNotNull(execution);
         assertEquals(0, execution.getId());
         assertNotNull(execution.getTask());
@@ -464,4 +459,41 @@ public class TaskTestITCase extends Abst
 
         assertEquals("SUCCESS", taskTO.getExecutions().get(0).getStatus());
     }
+
+    @Test
+    public void issueSYNCOPE81() {
+        NotificationTaskTO taskTO = restTemplate.getForObject(
+                BASE_URL + "task/read/{taskId}", NotificationTaskTO.class, 8L);
+
+        assertNotNull(taskTO);
+        assertTrue(taskTO.getExecutions().isEmpty());
+
+        TaskExecTO execution = restTemplate.postForObject(
+                BASE_URL + "task/execute/{taskId}", null, TaskExecTO.class, taskTO.getId());
+        assertEquals("NOT_SENT", execution.getStatus());
+
+        int i = 0;
+        int maxit = 50;
+
+        // wait for sync completion (executions incremented)
+        do {
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+            }
+
+            taskTO = restTemplate.getForObject(
+                    BASE_URL + "task/read/{taskId}", NotificationTaskTO.class, taskTO.getId());
+
+            assertNotNull(taskTO);
+            assertNotNull(taskTO.getExecutions());
+
+            i++;
+        } while (taskTO.getExecutions().isEmpty() && i < maxit);
+
+        assertFalse(taskTO.getExecutions().isEmpty());
+
+        taskTO = restTemplate.getForObject(BASE_URL + "task/delete/{taskId}", NotificationTaskTO.class, taskTO.getId());
+        assertNotNull(taskTO);
+    }
 }

Modified: incubator/syncope/trunk/core/src/test/resources/content.xml
URL: http://svn.apache.org/viewvc/incubator/syncope/trunk/core/src/test/resources/content.xml?rev=1333862&r1=1333861&r2=1333862&view=diff
==============================================================================
--- incubator/syncope/trunk/core/src/test/resources/content.xml (original)
+++ incubator/syncope/trunk/core/src/test/resources/content.xml Fri May  4 10:29:14 2012
@@ -493,6 +493,9 @@ under the License.
         performCreate="1" performUpdate="1" performDelete="0" syncStatus="1" fullReconciliation="1"
         jobClassName="org.apache.syncope.core.scheduling.SyncJob"/>
 
+  <Task DTYPE="NotificationTask" id="8" sender="admin@prova.org" subject="notification" textBody="" htmlBody="" traceLevel="ALL"/>
+  <NotificationTask_Recipients notificationtask_id="8" element="recipient@prova.org"/>
+
     <!-- Authentication and authorization -->
   <Entitlement name="base"/>
   <Entitlement name="advanced" description="Advanced entitlement"/>