Author: ilgrosso
Date: Fri Feb  8 08:05:44 2013
New Revision: 1443864

URL: http://svn.apache.org/r1443864
Log:
Making report testing more reliable

Modified:
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportExec.java
    
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java
    
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportExec.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportExec.java?rev=1443864&r1=1443863&r2=1443864&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportExec.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/persistence/beans/ReportExec.java
 Fri Feb  8 08:05:44 2013
@@ -24,7 +24,6 @@ import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.Lob;
 import javax.persistence.ManyToOne;
-
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.syncope.common.types.ReportExecStatus;
 

Modified: 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java?rev=1443864&r1=1443863&r2=1443864&view=diff
==============================================================================
--- 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java
 (original)
+++ 
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java
 Fri Feb  8 08:05:44 2013
@@ -39,6 +39,7 @@ import org.apache.cocoon.sax.SAXPipeline
 import org.apache.cocoon.sax.component.XMLGenerator;
 import org.apache.cocoon.sax.component.XMLSerializer;
 import org.apache.cocoon.sax.component.XSLTTransformer;
+import org.apache.commons.io.IOUtils;
 import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.report.ReportletConf;
 import org.apache.syncope.common.to.ReportExecTO;
@@ -348,12 +349,8 @@ public class ReportController extends Ab
         } catch (Exception e) {
             LOG.error("While exporting content", e);
         } finally {
-            try {
-                zis.close();
-                bais.close();
-            } catch (IOException e) {
-                LOG.error("While closing stream for execution result", e);
-            }
+            IOUtils.closeQuietly(zis);
+            IOUtils.closeQuietly(bais);
         }
 
         auditManager.audit(Category.report, 
ReportSubCategory.exportExecutionResult, Result.success,

Modified: 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java
URL: 
http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java?rev=1443864&r1=1443863&r2=1443864&view=diff
==============================================================================
--- 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java
 (original)
+++ 
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/ReportTestITCase.java
 Fri Feb  8 08:05:44 2013
@@ -175,10 +175,15 @@ public class ReportTestITCase extends Ab
         reportTO = createReport(reportTO);
         assertNotNull(reportTO);
 
+        int preExecs = reportTO.getExecutions().size();
+
         ReportExecTO execution = reportService.execute(reportTO.getId());
         assertNotNull(execution);
 
+        int i = 0;
         int maxit = 50;
+
+        // wait for report execution completion (executions incremented)
         do {
             try {
                 Thread.sleep(1000);
@@ -187,11 +192,18 @@ public class ReportTestITCase extends Ab
 
             reportTO = reportService.read(reportTO.getId());
 
-            maxit--;
-        } while (reportTO.getExecutions().isEmpty() && maxit > 0);
-        assertEquals(1, reportTO.getExecutions().size());
+            assertNotNull(reportTO);
+            assertNotNull(reportTO.getExecutions());
+
+            i++;
+        } while (preExecs == reportTO.getExecutions().size() && i < maxit);
+        if (i == maxit) {
+            throw new RuntimeException("Timeout when executing report " + 
reportTO.getId());
+        }
+
+        assertEquals(preExecs + 1, reportTO.getExecutions().size());
 
-        long execId = reportTO.getExecutions().iterator().next().getId();
+        long execId = reportTO.getExecutions().get(preExecs).getId();
 
         checkExport(execId, ReportExecExportFormat.XML);
         checkExport(execId, ReportExecExportFormat.HTML);


Reply via email to