Author: piergiorgio
Date: Sun Sep 24 15:20:41 2017
New Revision: 1809522

URL: http://svn.apache.org/viewvc?rev=1809522&view=rev
Log:
second iteration dedicated to integration tests of the CMIS Output Connector 
(CONNECTORS-1356)

Modified:
    
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
    
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/APISanityHSQLDBIT.java
    
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseHSQLDB.java
    
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseITHSQLDB.java
    
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BasePostgresql.java

Modified: 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java?rev=1809522&r1=1809521&r2=1809522&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/agents/output/cmisoutput/CmisOutputConnector.java
 Sun Sep 24 15:20:41 2017
@@ -32,7 +32,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.chemistry.opencmis.client.api.Document;
 import org.apache.chemistry.opencmis.client.api.Folder;
 import org.apache.chemistry.opencmis.client.api.ItemIterable;
 import org.apache.chemistry.opencmis.client.api.ObjectId;
@@ -54,6 +53,7 @@ import org.apache.chemistry.opencmis.com
 import 
org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import 
org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException;
 import 
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumBaseObjectTypeIds;
 import org.apache.commons.lang.StringUtils;
 import org.apache.manifoldcf.agents.interfaces.IOutputAddActivity;
 import org.apache.manifoldcf.agents.interfaces.IOutputRemoveActivity;
@@ -79,8 +79,6 @@ public class CmisOutputConnector extends
        protected final static String ACTIVITY_READ = "read document";
        protected static final String RELATIONSHIP_CHILD = "child";
 
-       private static final String CMIS_FOLDER_BASE_TYPE = "cmis:folder";
-
        // Tab name properties
 
        private static final String CMIS_SERVER_TAB_PROPERTY = 
"CmisOutputConnector.Server";
@@ -141,8 +139,6 @@ public class CmisOutputConnector extends
 
        private static final String CMIS_PROPERTY_PREFIX = "cmis:";
 
-       private static final String CMIS_DOCUMENT_TYPE = "cmis:document";
-
        /** Document accepted */
        private final static int DOCUMENT_STATUS_ACCEPTED = 0;
 
@@ -162,8 +158,6 @@ public class CmisOutputConnector extends
        /** The standard Path property for ManifoldCF used for migrate contents 
**/
   private static final String CONTENT_MIGRATION_PATH_PROPERTY = 
"manifoldcf:path";
 
-  private static final char CMIS_PATH_SEP = '/';
-
        /**
         * Constructor
         */
@@ -859,7 +853,7 @@ public class CmisOutputConnector extends
 
                        // check if it is a base folder content type
                        baseTypeId = 
dropZoneResult.getPropertyByQueryName(PropertyIds.BASE_TYPE_ID).getFirstValue().toString();
-                       if (StringUtils.isNotEmpty(baseTypeId) && 
StringUtils.equals(baseTypeId, CMIS_FOLDER_BASE_TYPE)) {
+                       if (StringUtils.isNotEmpty(baseTypeId) && 
StringUtils.equals(baseTypeId, EnumBaseObjectTypeIds.CMIS_FOLDER.value())) {
                                String objectId = 
dropZoneResult.getPropertyValueById(PropertyIds.OBJECT_ID);
                                parentDropZoneFolder = (Folder) 
session.getObject(objectId);
                                isDropZoneFolder = true;
@@ -888,7 +882,6 @@ public class CmisOutputConnector extends
                
                boolean isDropZoneFolder = isDropZoneFolder(cmisQuery);
                long startTime = System.currentTimeMillis();
-               Document injectedDocument = null;
                String resultDescription = StringUtils.EMPTY;
                Folder leafParent = null;
                String fileName = StringUtils.EMPTY;
@@ -937,7 +930,7 @@ public class CmisOutputConnector extends
                                }
 
                                //Agnostic metadata
-                               properties.put(PropertyIds.OBJECT_TYPE_ID, 
CMIS_DOCUMENT_TYPE);
+                               properties.put(PropertyIds.OBJECT_TYPE_ID, 
EnumBaseObjectTypeIds.CMIS_DOCUMENT.value());
                                properties.put(PropertyIds.NAME, fileName);
                                properties.put(PropertyIds.CREATION_DATE, 
creationDate);
                                
properties.put(PropertyIds.LAST_MODIFICATION_DATE, lastModificationDate);
@@ -955,7 +948,7 @@ public class CmisOutputConnector extends
 
                                // create a major version
                                leafParent = 
getOrCreateLeafParent(parentDropZoneFolder, creationDate, 
Boolean.valueOf(createTimestampTree), primaryPath);
-                               injectedDocument = 
leafParent.createDocument(properties, contentStream, VersioningState.MAJOR);
+                               leafParent.createDocument(properties, 
contentStream, VersioningState.NONE);
                                resultDescription = 
DOCUMENT_STATUS_ACCEPTED_DESC;
                                return DOCUMENT_STATUS_ACCEPTED;
 
@@ -1007,7 +1000,7 @@ public class CmisOutputConnector extends
                        leafParent = dayFolder;
                        
                } else if(StringUtils.isNotEmpty(primaryPath)) {
-                       String[] primaryPathArray = 
StringUtils.split(primaryPath, CMIS_PATH_SEP);
+                       String[] primaryPathArray = 
StringUtils.split(primaryPath, CmisOutputConnectorUtils.SLASH);
                        leafParent = folder;
                        for (int i = 0; i < primaryPathArray.length - 1; i++) {
                                String pathSegment = primaryPathArray[i];
@@ -1051,13 +1044,18 @@ public class CmisOutputConnector extends
                String result = StringUtils.EMPTY;
                
                //append the prefix for the relative path in the target repo
-               String parentDropZonePath = parentDropZoneFolder.getPath();
-               String fullDocumentURIinTargetRepo = parentDropZonePath + 
documentURI;
                try {
-                       if(session.existsPath(fullDocumentURIinTargetRepo)) {
-                               
session.deleteByPath(fullDocumentURIinTargetRepo);
-                               result = DOCUMENT_DELETION_STATUS_ACCEPTED;
-                       } else {
+                       if(parentDropZoneFolder != null && 
StringUtils.isNotEmpty(documentURI)) {
+                               String parentDropZonePath = 
parentDropZoneFolder.getPath();
+                               String fullDocumentURIinTargetRepo = 
parentDropZonePath + documentURI;
+                               
+                                       
if(session.existsPath(fullDocumentURIinTargetRepo)) {
+                                               
session.deleteByPath(fullDocumentURIinTargetRepo);
+                                               result = 
DOCUMENT_DELETION_STATUS_ACCEPTED;
+                                       } else {
+                                               result = 
DOCUMENT_DELETION_STATUS_REJECTED;
+                                       }
+                       } else { 
                                result = DOCUMENT_DELETION_STATUS_REJECTED;
                        }
                } catch (Exception e) {
@@ -1067,7 +1065,6 @@ public class CmisOutputConnector extends
                        activities.recordActivity(startTime, ACTIVITY_DELETE, 
null, documentURI, null, result);
                }
        }
-
        
        
 }
\ No newline at end of file

Modified: 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/APISanityHSQLDBIT.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/APISanityHSQLDBIT.java?rev=1809522&r1=1809521&r2=1809522&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/APISanityHSQLDBIT.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/APISanityHSQLDBIT.java
 Sun Sep 24 15:20:41 2017
@@ -29,6 +29,7 @@ import java.util.Map;
 import org.apache.chemistry.opencmis.client.api.Document;
 import org.apache.chemistry.opencmis.client.api.Folder;
 import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
 import org.apache.chemistry.opencmis.client.api.QueryResult;
 import org.apache.chemistry.opencmis.client.api.Session;
 import org.apache.chemistry.opencmis.client.api.SessionFactory;
@@ -38,6 +39,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.enums.BindingType;
 import 
org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumBaseObjectTypeIds;
 import org.apache.chemistry.opencmis.commons.spi.ObjectService;
 import org.apache.commons.lang.StringUtils;
 import org.apache.manifoldcf.agents.output.cmisoutput.CmisOutputConfig;
@@ -62,6 +64,8 @@ public class APISanityHSQLDBIT extends B
   private Session cmisSourceClientSession = null;
   private Session cmisTargetClientSession = null;
   
+  private static final String CMIS_QUERY_TARGET_DEFAULT_VALUE = "SELECT * FROM 
cmis:folder WHERE cmis:name='Target'";
+  
   private Session getCmisSourceClientSession(){
     // default factory implementation
     SessionFactory factory = SessionFactoryImpl.newInstance();
@@ -153,7 +157,7 @@ public class APISanityHSQLDBIT extends B
       
       //creating a new folder
       
-      Folder newSourceRepoFolder = createTestFolder(cmisSourceClientSession);
+      Folder newSourceRepoFolder = 
createTestFolderInTheSource(cmisSourceClientSession);
       String name = StringUtils.EMPTY;
       for(int i=1; i<=2; i++){
        name = "testdata" + String.valueOf(i) + ".txt";
@@ -161,7 +165,7 @@ public class APISanityHSQLDBIT extends B
       }
       
       //Creating the target folder in the target repo
-      createTestFolder(cmisTargetClientSession);
+      createTestFolderInTheTarget(cmisTargetClientSession);
 
     }
     catch (Exception e)
@@ -170,8 +174,8 @@ public class APISanityHSQLDBIT extends B
       throw e;
     }
   }
-
-       private Folder createTestFolder(Session session) {
+  
+  private Folder createTestFolderInTheSource(Session session) {
                Folder root = session.getRootFolder();
                ItemIterable<QueryResult> results = 
session.query(CmisOutputConfig.CMIS_QUERY_DEFAULT_VALUE, false);
                for (QueryResult result : results) {
@@ -181,13 +185,31 @@ public class APISanityHSQLDBIT extends B
                }
                
                Map<String, Object> folderProperties = new HashMap<String, 
Object>();
-               folderProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
+               folderProperties.put(PropertyIds.OBJECT_TYPE_ID, 
EnumBaseObjectTypeIds.CMIS_FOLDER.value());
                folderProperties.put(PropertyIds.NAME, "Apache ManifoldCF");
  
                //Creating sample contents on the source repo
                Folder newFolder = root.createFolder(folderProperties);
                return newFolder;
        }
+
+       private Folder createTestFolderInTheTarget(Session session) {
+               Folder root = session.getRootFolder();
+               ItemIterable<QueryResult> results = 
session.query(CMIS_QUERY_TARGET_DEFAULT_VALUE, false);
+               for (QueryResult result : results) {
+                 String repositoryId = 
cmisSourceClientSession.getRepositoryInfo().getId();
+                 String folderId = 
result.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue().toString();
+                 
cmisSourceClientSession.getBinding().getObjectService().deleteTree(repositoryId,
 folderId, true, null, false, null);
+               }
+               
+               Map<String, Object> folderProperties = new HashMap<String, 
Object>();
+               folderProperties.put(PropertyIds.OBJECT_TYPE_ID, 
EnumBaseObjectTypeIds.CMIS_FOLDER.value());
+               folderProperties.put(PropertyIds.NAME, "Target");
+ 
+               //Creating sample contents on the source repo
+               Folder newFolder = root.createFolder(folderProperties);
+               return newFolder;
+       }
   
   @After
   public void removeTestArea()
@@ -226,7 +248,7 @@ public class APISanityHSQLDBIT extends B
       connectionObject.addChild(connectionObject.getChildCount(),child);
 
       child = new ConfigurationNode("max_connections");
-      child.setValue("10");
+      child.setValue("1");
       connectionObject.addChild(connectionObject.getChildCount(),child);
       
       child = new ConfigurationNode("configuration");
@@ -306,7 +328,7 @@ public class APISanityHSQLDBIT extends B
       connectionObject.addChild(connectionObject.getChildCount(),child);
 
       child = new ConfigurationNode("max_connections");
-      child.setValue("10");
+      child.setValue("1");
       connectionObject.addChild(connectionObject.getChildCount(),child);
 
       child = new ConfigurationNode("configuration");
@@ -356,7 +378,7 @@ public class APISanityHSQLDBIT extends B
       //cmisQuery
       ConfigurationNode cmisOutputCmisQueryNode = new 
ConfigurationNode("_PARAMETER_");
       cmisOutputCmisQueryNode.setAttribute("name", 
CmisOutputConfig.CMIS_QUERY_PARAM);
-      
cmisOutputCmisQueryNode.setValue(CmisOutputConfig.CMIS_QUERY_DEFAULT_VALUE);
+      cmisOutputCmisQueryNode.setValue(CMIS_QUERY_TARGET_DEFAULT_VALUE);
       child.addChild(child.getChildCount(), cmisOutputCmisQueryNode);
       
       //createTimestampTree
@@ -500,10 +522,7 @@ public class APISanityHSQLDBIT extends B
       if(targetRepoNumberOfContents != 4)
         throw new ManifoldCFException("Wrong number of documents stored in the 
CMIS Target repo - expected 4, saw "+new 
Long(targetRepoNumberOfContents).toString());
 
-      // We also need to make sure the new document was indexed.  Have to 
think about how to do this though.
-      // MHL
-      //System.out.println("Starting delete...");
-      // Delete a file, and recrawl
+      // Delete a content and recrawl
       removeDocument(cmisSourceClientSession, "testdata2.txt");
       
       // Now, start the job, and wait until it completes.
@@ -513,6 +532,7 @@ public class APISanityHSQLDBIT extends B
       // Check to be sure we actually processed the right number of documents.
       // The test data area has 3 documents and one directory, and we have to 
count the root directory too.
       count = getJobDocumentsProcessed(jobIDString);
+      waitJobInactive(jobIDString, 240000L);
       if (count != 4)
         throw new ManifoldCFException("Wrong number of documents processed 
after delete - expected 4, saw "+new Long(count).toString());
       
@@ -619,13 +639,11 @@ public class APISanityHSQLDBIT extends B
   public void removeDocument(Session session, String name){
     String cmisQuery = StringUtils.replace(CMIS_TEST_QUERY_CHANGE_DOC, 
REPLACER, name);
     ItemIterable<QueryResult> results = session.query(cmisQuery, false);
-    String objectId = StringUtils.EMPTY;
+    String objectId = null;
     for (QueryResult result : results) {
       objectId = 
result.getPropertyById(PropertyIds.OBJECT_ID).getFirstValue().toString();
     }
-    String repositoryId = session.getRepositoryInfo().getId();
-    ObjectService objectService = session.getBinding().getObjectService();
-    objectService.deleteObject(repositoryId, objectId, true, null);
+    session.getObject(objectId).delete();
   }
 
   protected void waitJobInactive(String jobIDString, long maxTime)

Modified: 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseHSQLDB.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseHSQLDB.java?rev=1809522&r1=1809521&r2=1809522&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseHSQLDB.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseHSQLDB.java
 Sun Sep 24 15:20:41 2017
@@ -20,16 +20,26 @@ package org.apache.manifoldcf.agents.out
 
 
 /** This is a testing base class that is responsible for setting up/tearing 
down the agents framework. */
-public class BaseHSQLDB extends org.apache.manifoldcf.agents.tests.BaseHSQLDB
+public class BaseHSQLDB extends org.apache.manifoldcf.crawler.tests.BaseHSQLDB
 {
   
   protected String[] getConnectorNames()
   {
-    return new String[]{"CMIS"};
+    return new String[]{"Test Connector"};
   }
   
   protected String[] getConnectorClasses()
   {
+    return new 
String[]{"org.apache.manifoldcf.crawler.tests.TestingRepositoryConnector"};
+  }
+  
+  protected String[] getOutputNames()
+  {
+    return new String[]{"CMIS"};
+  }
+  
+  protected String[] getOutputClasses()
+  {
     return new 
String[]{"org.apache.manifoldcf.agents.output.cmisoutput.CmisOutputConnector"};
   }
 

Modified: 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseITHSQLDB.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseITHSQLDB.java?rev=1809522&r1=1809521&r2=1809522&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseITHSQLDB.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BaseITHSQLDB.java
 Sun Sep 24 15:20:41 2017
@@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUti
 import org.apache.manifoldcf.crawler.connectors.cmis.tests.CMISServer;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Test;
 
 /** Tests that run the "agents daemon" should be derived from this 
  * 

Modified: 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BasePostgresql.java
URL: 
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BasePostgresql.java?rev=1809522&r1=1809521&r2=1809522&view=diff
==============================================================================
--- 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BasePostgresql.java
 (original)
+++ 
manifoldcf/branches/CONNECTORS-1356-2.7.1/connectors/cmis/connector/src/test/java/org/apache/manifoldcf/agents/output/cmisoutput/tests/BasePostgresql.java
 Sun Sep 24 15:20:41 2017
@@ -20,7 +20,7 @@ package org.apache.manifoldcf.agents.out
 
 
 /** This is a testing base class that is responsible for setting up/tearing 
down the agents framework. */
-public class BasePostgresql extends 
org.apache.manifoldcf.agents.tests.BasePostgresql
+public class BasePostgresql extends 
org.apache.manifoldcf.crawler.tests.BasePostgresql
 {
   
   protected String[] getConnectorNames()


Reply via email to