manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From piergior...@apache.org
Subject svn commit: r1203860 [4/4] - in /incubator/lcf/branches/CONNECTORS-287: ./ connectors/alfresco/ connectors/alfresco/connector/ connectors/alfresco/connector/src/ connectors/alfresco/connector/src/main/ connectors/alfresco/connector/src/main/java/ conne...
Date Fri, 18 Nov 2011 21:42:11 GMT
Added: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java?rev=1203860&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java
(added)
+++ incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java
Fri Nov 18 21:42:08 2011
@@ -0,0 +1,621 @@
+package org.apache.manifoldcf.alfresco_tests;
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+import java.io.IOException;
+import java.rmi.RemoteException;
+
+import org.alfresco.webservice.content.ContentServiceSoapBindingStub;
+import org.alfresco.webservice.repository.QueryResult;
+import org.alfresco.webservice.repository.RepositoryFault;
+import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub;
+import org.alfresco.webservice.repository.UpdateResult;
+import org.alfresco.webservice.types.CML;
+import org.alfresco.webservice.types.CMLCreate;
+import org.alfresco.webservice.types.CMLDelete;
+import org.alfresco.webservice.types.ContentFormat;
+import org.alfresco.webservice.types.NamedValue;
+import org.alfresco.webservice.types.ParentReference;
+import org.alfresco.webservice.types.Predicate;
+import org.alfresco.webservice.types.Query;
+import org.alfresco.webservice.types.Reference;
+import org.alfresco.webservice.types.ResultSetRow;
+import org.alfresco.webservice.types.Store;
+import org.alfresco.webservice.util.AuthenticationUtils;
+import org.alfresco.webservice.util.Constants;
+import org.alfresco.webservice.util.Utils;
+import org.alfresco.webservice.util.WebServiceFactory;
+import org.apache.commons.lang.StringUtils;
+import org.apache.manifoldcf.core.interfaces.Configuration;
+import org.apache.manifoldcf.core.interfaces.ConfigurationNode;
+import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+import org.apache.manifoldcf.crawler.connectors.alfresco.AlfrescoRepositoryConnector;
+import org.apache.manifoldcf.crawler.system.ManifoldCF;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Piergiorgio Lucidi
+ */
+public class APISanityIT extends Base
+{
+  private static final String REPLACER = "?";
+  private static final String ALFRESCO_TEST_QUERY_CHANGE_DOC = "PATH:\"/app:company_home/cm:testdata/*\"
AND TYPE:\"cm:content\" AND @cm\\:name:\""+REPLACER+"\"";
+  private static final String ALFRESCO_TEST_QUERY = "PATH:\"/app:company_home/cm:testdata\"";
+  
+  private static final String ALFRESCO_ENDPOINT_TEST_SERVER = "http://localhost:9090/alfresco/api";
+  private static final String ALFRESCO_USERNAME = "admin"; 
+  private static final String ALFRESCO_PASSWORD = "admin";
+  
+  private static final Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
+  
+  public Reference getTestFolder() throws RepositoryFault, RemoteException{
+    WebServiceFactory.setEndpointAddress(ALFRESCO_ENDPOINT_TEST_SERVER);
+    AuthenticationUtils.startSession(ALFRESCO_USERNAME, ALFRESCO_PASSWORD);
+    Reference reference = new Reference();
+    try{
+      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
+      Query query = new Query(Constants.QUERY_LANG_LUCENE, ALFRESCO_TEST_QUERY);
+      QueryResult queryResult = repositoryService.query(STORE, query, false);
+      ResultSetRow row = queryResult.getResultSet().getRows(0);
+      reference.setStore(STORE);
+      reference.setUuid(row.getNode().getId());
+      return reference;
+    } finally {
+      AuthenticationUtils.endSession();
+    }
+  }
+  
+  public void createNewDocument(Reference folder, String name) throws IOException{
+    ParentReference folderReference = 
+        new ParentReference(STORE, folder.getUuid(), null, Constants.ASSOC_CONTAINS, null);
+
+    folderReference.setChildName("cm:" + name);
+    
+    NamedValue[] contentProps = new NamedValue[1]; 
+    contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name); 
+    CMLCreate create = new CMLCreate("1", folderReference, null, null, null, Constants.TYPE_CONTENT,
contentProps);
+ 
+    CML cml = new CML();
+    cml.setCreate(new CMLCreate[] {create});
+
+    WebServiceFactory.setEndpointAddress(ALFRESCO_ENDPOINT_TEST_SERVER);
+    AuthenticationUtils.startSession(ALFRESCO_USERNAME, ALFRESCO_PASSWORD);
+    
+    try{
+      
+      UpdateResult[] result = WebServiceFactory.getRepositoryService().update(cml);
+      
+      //format
+      ContentFormat contentFormat = new ContentFormat();
+      contentFormat.setEncoding("UTF-8");
+      contentFormat.setMimetype("text/plain");
+      
+      //the content
+      String content = "Alfresco Testdata "+name;
+      
+      //the new node
+      Reference reference = result[0].getDestination();
+  
+      //write the content in the new node
+      ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
+      contentService.write(reference, Constants.PROP_CONTENT, content.getBytes(), contentFormat);
+      
+    } finally{
+      AuthenticationUtils.endSession();
+    }
+    
+  }
+  
+  /**
+   * change the document content with the new one provided as an argument
+   * @param session
+   * @param name
+   * @param newContent
+   * @throws RemoteException 
+   * @throws RepositoryFault 
+   */
+  public void changeDocument(String name, String newContent) throws RepositoryFault, RemoteException{
+    String luceneQuery = StringUtils.replace(ALFRESCO_TEST_QUERY_CHANGE_DOC, REPLACER, name);
+    WebServiceFactory.setEndpointAddress(ALFRESCO_ENDPOINT_TEST_SERVER);
+    AuthenticationUtils.startSession(ALFRESCO_USERNAME, ALFRESCO_PASSWORD);
+    
+    try{
+    
+      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        
+      Query query = new Query(Constants.QUERY_LANG_LUCENE, luceneQuery);
+      QueryResult queryResult = repositoryService.query(STORE, query, false);
+      
+      ResultSetRow row = queryResult.getResultSet().getRows(0);
+      
+      Reference reference = new Reference();
+      reference.setStore(STORE);
+      reference.setUuid(row.getNode().getId());
+      
+      ContentFormat contentFormat = new ContentFormat();
+      contentFormat.setEncoding("UTF-8");
+      contentFormat.setMimetype("text/plain");
+      
+      ContentServiceSoapBindingStub contentService = WebServiceFactory.getContentService();
+      contentService.write(reference, Constants.PROP_CONTENT, newContent.getBytes(), contentFormat);
+      
+    } finally {
+      AuthenticationUtils.endSession();
+    }
+    
+  }
+  
+  public void removeDocument(String name) throws RepositoryFault, RemoteException{
+    String luceneQuery = StringUtils.replace(ALFRESCO_TEST_QUERY_CHANGE_DOC, REPLACER, name);
+    WebServiceFactory.setEndpointAddress(ALFRESCO_ENDPOINT_TEST_SERVER);
+    AuthenticationUtils.startSession(ALFRESCO_USERNAME, ALFRESCO_PASSWORD);
+    
+    try{
+    
+      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
        
+      Query query = new Query(Constants.QUERY_LANG_LUCENE, luceneQuery);
+      QueryResult queryResult = repositoryService.query(STORE, query, false);
+      
+      ResultSetRow row = queryResult.getResultSet().getRows(0);
+      
+      Reference reference = new Reference();
+      reference.setStore(STORE);
+      reference.setUuid(row.getNode().getId());
+      
+      Predicate predicate = new Predicate();
+      predicate.setStore(STORE);
+      predicate.setNodes(new Reference[]{reference});
+      
+      CMLDelete cmlDelete = new CMLDelete();
+      cmlDelete.setWhere(predicate);
+      
+      CML cml = new CML();
+      cml.setDelete(new CMLDelete[]{cmlDelete});
+      
+      repositoryService.update(cml);
+      
+    } finally {
+      AuthenticationUtils.endSession();
+    }
+  }
+  
+  @Before
+  public void createTestArea()
+    throws Exception
+  {
+    try
+    {
+      WebServiceFactory.setEndpointAddress(ALFRESCO_ENDPOINT_TEST_SERVER);
+      AuthenticationUtils.startSession(ALFRESCO_USERNAME, ALFRESCO_PASSWORD);
+      
+      UpdateResult[] result = null;
+      
+      try {
+      
+        ParentReference companyHomeParent = 
+            new ParentReference(STORE, null, "/app:company_home", Constants.ASSOC_CONTAINS,
null);
+  
+        String name = "testdata";
+        companyHomeParent.setChildName("cm:" + name);
+        
+        NamedValue[] contentProps = new NamedValue[1]; 
+        contentProps[0] = Utils.createNamedValue(Constants.PROP_NAME, name); 
+        CMLCreate create = new CMLCreate("1", companyHomeParent, null, null, null, Constants.TYPE_FOLDER,
contentProps);
+        
+        CML cml = new CML();
+        cml.setCreate(new CMLCreate[] {create});
+  
+        result = WebServiceFactory.getRepositoryService().update(cml);
+      
+      } finally {
+        AuthenticationUtils.endSession();
+      }
+      
+      
+      Reference testData = result[0].getDestination();
+      
+      createNewDocument(testData, "testdata1.txt");
+      createNewDocument(testData, "testdata2.txt");
+      
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  @After
+  public void removeTestArea()
+    throws Exception
+  {
+    WebServiceFactory.setEndpointAddress(ALFRESCO_ENDPOINT_TEST_SERVER);
+    AuthenticationUtils.startSession(ALFRESCO_USERNAME, ALFRESCO_PASSWORD);
+    
+    try{
+    
+      RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
+      Query query = new Query(Constants.QUERY_LANG_LUCENE, ALFRESCO_TEST_QUERY);
+      QueryResult queryResult = repositoryService.query(STORE, query, false);
+      
+      ResultSetRow row = queryResult.getResultSet().getRows(0);
+      
+      Reference reference = new Reference();
+      reference.setStore(STORE);
+      reference.setUuid(row.getNode().getId());
+      
+      Predicate predicate = new Predicate();
+      predicate.setStore(STORE);
+      predicate.setNodes(new Reference[]{reference});
+      
+      CMLDelete cmlDelete = new CMLDelete();
+      cmlDelete.setWhere(predicate);
+      
+      CML cml = new CML();
+      cml.setDelete(new CMLDelete[]{cmlDelete});
+    
+    } finally {
+      AuthenticationUtils.endSession();
+    }
+  }
+  
+  @Test
+  public void sanityCheck()
+    throws Exception
+  {
+    try
+    {
+      
+      int i;
+
+      // Create a basic file system connection, and save it.
+      ConfigurationNode connectionObject;
+      ConfigurationNode child;
+      Configuration requestObject;
+      Configuration result;
+      
+      connectionObject = new ConfigurationNode("repositoryconnection");
+      
+      child = new ConfigurationNode("name");
+      child.setValue("Alfresco Connection");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+      
+      child = new ConfigurationNode("class_name");
+      child.setValue("org.apache.manifoldcf.crawler.connectors.alfresco.AlfrescoRepositoryConnector");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+      
+      child = new ConfigurationNode("description");
+      child.setValue("An Alfresco Repository Connection");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+
+      child = new ConfigurationNode("max_connections");
+      child.setValue("10");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+      
+      child = new ConfigurationNode("configuration");
+      
+      //Alfresco Repository Connector parameters
+      
+      //username
+      ConfigurationNode alfrescoUsernameNode = new ConfigurationNode("_PARAMETER_");
+      alfrescoUsernameNode.setAttribute("name", AlfrescoRepositoryConnector.CONFIG_PARAM_USERNAME);
+      alfrescoUsernameNode.setValue(ALFRESCO_USERNAME);
+      child.addChild(child.getChildCount(), alfrescoUsernameNode);
+      
+      //password
+      ConfigurationNode alfrescoPasswordNode = new ConfigurationNode("_PARAMETER_");
+      alfrescoPasswordNode.setAttribute("name", AlfrescoRepositoryConnector.CONFIG_PARAM_PASSWORD);
+      alfrescoPasswordNode.setValue(ALFRESCO_PASSWORD);
+      child.addChild(child.getChildCount(), alfrescoPasswordNode);
+      
+      //endpoint
+      ConfigurationNode alfrescoEndpointNode = new ConfigurationNode("_PARAMETER_");
+      alfrescoEndpointNode.setAttribute("name", AlfrescoRepositoryConnector.CONFIG_PARAM_ENDPOINT);
+      alfrescoEndpointNode.setValue(ALFRESCO_ENDPOINT_TEST_SERVER);
+      child.addChild(child.getChildCount(), alfrescoEndpointNode);
+      
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+
+      requestObject = new Configuration();
+      requestObject.addChild(0,connectionObject);
+      
+      result = performAPIPutOperationViaNodes("repositoryconnections/Alfresco%20Connection",201,requestObject);
+      
+      i = 0;
+      while (i < result.getChildCount())
+      {
+        ConfigurationNode resultNode = result.findChild(i++);
+        if (resultNode.getType().equals("error"))
+          throw new Exception(resultNode.getValue());
+      }
+      
+      // Create a basic null output connection, and save it.
+      connectionObject = new ConfigurationNode("outputconnection");
+      
+      child = new ConfigurationNode("name");
+      child.setValue("Null Connection");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+      
+      child = new ConfigurationNode("class_name");
+      child.setValue("org.apache.manifoldcf.agents.output.nullconnector.NullConnector");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+      
+      child = new ConfigurationNode("description");
+      child.setValue("Null Connection");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+
+      child = new ConfigurationNode("max_connections");
+      child.setValue("100");
+      connectionObject.addChild(connectionObject.getChildCount(),child);
+
+      requestObject = new Configuration();
+      requestObject.addChild(0,connectionObject);
+      
+      result = performAPIPutOperationViaNodes("outputconnections/Null%20Connection",201,requestObject);
+      
+      i = 0;
+      while (i < result.getChildCount())
+      {
+        ConfigurationNode resultNode = result.findChild(i++);
+        if (resultNode.getType().equals("error"))
+          throw new Exception(resultNode.getValue());
+      }
+
+      // Create a job.
+      ConfigurationNode jobObject = new ConfigurationNode("job");
+      
+      child = new ConfigurationNode("description");
+      child.setValue("Test Job");
+      jobObject.addChild(jobObject.getChildCount(),child);
+
+      child = new ConfigurationNode("repository_connection");
+      child.setValue("Alfresco Connection");
+      jobObject.addChild(jobObject.getChildCount(),child);
+
+      child = new ConfigurationNode("output_connection");
+      child.setValue("Null Connection");
+      jobObject.addChild(jobObject.getChildCount(),child);
+
+      child = new ConfigurationNode("run_mode");
+      child.setValue("scan once");
+      jobObject.addChild(jobObject.getChildCount(),child);
+
+      child = new ConfigurationNode("start_mode");
+      child.setValue("manual");
+      jobObject.addChild(jobObject.getChildCount(),child);
+
+      child = new ConfigurationNode("hopcount_mode");
+      child.setValue("accurate");
+      jobObject.addChild(jobObject.getChildCount(),child);
+
+      child = new ConfigurationNode("document_specification");
+      
+      
+      //Job configuration
+      ConfigurationNode sn = new ConfigurationNode("startpoint");
+      sn.setAttribute("luceneQuery",ALFRESCO_TEST_QUERY);
+      
+      child.addChild(child.getChildCount(),sn);
+      jobObject.addChild(jobObject.getChildCount(),child);
+      
+      requestObject = new Configuration();
+      requestObject.addChild(0,jobObject);
+      
+      result = performAPIPostOperationViaNodes("jobs",201,requestObject);
+      
+      String jobIDString = null;
+      i = 0;
+      while (i < result.getChildCount())
+      {
+        ConfigurationNode resultNode = result.findChild(i++);
+        if (resultNode.getType().equals("error"))
+          throw new Exception(resultNode.getValue());
+        else if (resultNode.getType().equals("job_id"))
+          jobIDString = resultNode.getValue();
+      }
+      if (jobIDString == null)
+        throw new Exception("Missing job_id from return!");
+      
+      // Now, start the job, and wait until it completes.
+      startJob(jobIDString);
+      waitJobInactive(jobIDString, 360000L);
+
+      // 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.
+      long count;
+      count = getJobDocumentsProcessed(jobIDString);
+      if (count != 3)
+        throw new ManifoldCFException("Wrong number of documents processed - expected 3,
saw "+new Long(count).toString());
+      
+      // Add a file and recrawl
+      Reference testFolder = getTestFolder();
+      createNewDocument(testFolder, "testdata3.txt");
+      createNewDocument(testFolder, "testdata4.txt");
+
+      // Now, start the job, and wait until it completes.
+      startJob(jobIDString);
+      waitJobInactive(jobIDString, 360000L);
+
+      // The test data area has 4 documents and one directory, and we have to count the root
directory too.
+      count = getJobDocumentsProcessed(jobIDString);
+      if (count != 5)
+        throw new ManifoldCFException("Wrong number of documents processed after add - expected
5, saw "+new Long(count).toString());
+
+      // Change a document, and recrawl
+      changeDocument("testdata1.txt","MODIFIED - Alfresco Testdata - MODIFIED");
+      
+      // Now, start the job, and wait until it completes.
+      startJob(jobIDString);
+      waitJobInactive(jobIDString, 360000L);
+
+      // The test data area has 4 documents and one directory, and we have to count the root
directory too.
+      count = getJobDocumentsProcessed(jobIDString);
+      if (count != 5)
+        throw new ManifoldCFException("Wrong number of documents processed after change -
expected 5, saw "+new Long(count).toString());
+      
+      // We also need to make sure the new document was indexed.  Have to think about how
to do this though.
+      // MHL
+      
+      // Delete a file, and recrawl
+      removeDocument("testdata2.txt");
+      
+      // Now, start the job, and wait until it completes.
+      startJob(jobIDString);
+      waitJobInactive(jobIDString, 360000L);
+
+      // 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);
+      if (count != 4)
+        throw new ManifoldCFException("Wrong number of documents processed after delete -
expected 5, saw "+new Long(count).toString());
+
+      // Now, delete the job.
+      deleteJob(jobIDString);
+
+      waitJobDeleted(jobIDString, 360000L);
+      
+      // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections
lying around.
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  protected void startJob(String jobIDString)
+    throws Exception
+  {
+    Configuration requestObject = new Configuration();
+    
+    Configuration result = performAPIPutOperationViaNodes("start/"+jobIDString,201,requestObject);
+    int i = 0;
+    while (i < result.getChildCount())
+    {
+      ConfigurationNode resultNode = result.findChild(i++);
+      if (resultNode.getType().equals("error"))
+        throw new Exception(resultNode.getValue());
+    }
+  }
+  
+  protected void deleteJob(String jobIDString)
+    throws Exception
+  {
+    Configuration result = performAPIDeleteOperationViaNodes("jobs/"+jobIDString,200);
+    int i = 0;
+    while (i < result.getChildCount())
+    {
+      ConfigurationNode resultNode = result.findChild(i++);
+      if (resultNode.getType().equals("error"))
+        throw new Exception(resultNode.getValue());
+    }
+
+  }
+  
+  protected String getJobStatus(String jobIDString)
+    throws Exception
+  {
+    Configuration result = performAPIGetOperationViaNodes("jobstatuses/"+jobIDString,200);
+    String status = null;
+    int i = 0;
+    while (i < result.getChildCount())
+    {
+      ConfigurationNode resultNode = result.findChild(i++);
+      if (resultNode.getType().equals("error"))
+        throw new Exception(resultNode.getValue());
+      else if (resultNode.getType().equals("jobstatus"))
+      {
+        int j = 0;
+        while (j < resultNode.getChildCount())
+        {
+          ConfigurationNode childNode = resultNode.findChild(j++);
+          if (childNode.getType().equals("status"))
+            status = childNode.getValue();
+        }
+      }
+    }
+    return status;
+  }
+
+  protected long getJobDocumentsProcessed(String jobIDString)
+    throws Exception
+  {
+    Configuration result = performAPIGetOperationViaNodes("jobstatuses/"+jobIDString,200);
+    String documentsProcessed = null;
+    int i = 0;
+    while (i < result.getChildCount())
+    {
+      ConfigurationNode resultNode = result.findChild(i++);
+      if (resultNode.getType().equals("error"))
+        throw new Exception(resultNode.getValue());
+      else if (resultNode.getType().equals("jobstatus"))
+      {
+        int j = 0;
+        while (j < resultNode.getChildCount())
+        {
+          ConfigurationNode childNode = resultNode.findChild(j++);
+          if (childNode.getType().equals("documents_processed"))
+            documentsProcessed = childNode.getValue();
+        }
+      }
+    }
+    if (documentsProcessed == null)
+      throw new Exception("Expected a documents_processed field, didn't find it");
+    return new Long(documentsProcessed).longValue();
+  }
+
+  protected void waitJobInactive(String jobIDString, long maxTime)
+    throws Exception
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      String status = getJobStatus(jobIDString);
+      if (status == null)
+        throw new Exception("No such job: '"+jobIDString+"'");
+      if (status.equals("not yet run"))
+        throw new Exception("Job was never started.");
+      if (status.equals("done"))
+        return;
+      if (status.equals("error"))
+        throw new Exception("Job reports error.");
+      ManifoldCF.sleep(1000L);
+      continue;
+    }
+    throw new ManifoldCFException("ManifoldCF did not terminate in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+  
+  protected void waitJobDeleted(String jobIDString, long maxTime)
+    throws Exception
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      String status = getJobStatus(jobIDString);
+      if (status == null)
+        return;
+      ManifoldCF.sleep(1000L);
+    }
+    throw new ManifoldCFException("ManifoldCF did not delete in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+    
+
+}

Propchange: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/APISanityIT.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java?rev=1203860&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java
(added)
+++ incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java
Fri Nov 18 21:42:08 2011
@@ -0,0 +1,506 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.alfresco_tests;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.manifoldcf.core.interfaces.Configuration;
+import org.apache.manifoldcf.core.interfaces.ILockManager;
+import org.apache.manifoldcf.core.interfaces.IThreadContext;
+import org.apache.manifoldcf.core.interfaces.LockManagerFactory;
+import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
+import org.apache.manifoldcf.core.interfaces.ThreadContextFactory;
+import org.apache.manifoldcf.crawler.interfaces.IJobDescription;
+import org.apache.manifoldcf.crawler.interfaces.IJobManager;
+import org.apache.manifoldcf.crawler.interfaces.JobManagerFactory;
+import org.apache.manifoldcf.crawler.interfaces.JobStatus;
+import org.apache.manifoldcf.crawler.system.ManifoldCF;
+import org.junit.After;
+import org.junit.Before;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.plus.naming.Resource;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+/** Tests that run the "agents daemon" should be derived from this 
+ * 
+ *  @author Piergiorgio Lucidi
+ * 
+ * */
+public class Base extends org.apache.manifoldcf.crawler.tests.ConnectorBase
+{
+  public static final String agentShutdownSignal = "agent-process";
+  public static final int testPort = 8346;
+  
+  protected DaemonThread daemonThread = null;
+  protected Server server = null;
+  protected Server alfrescoServer = null;
+
+  
+  protected String[] getConnectorNames()
+  {
+    return new String[]{"Alfresco"};
+  }
+  
+  protected String[] getConnectorClasses()
+  {
+    return new String[]{"org.apache.manifoldcf.crawler.connectors.alfresco.AlfrescoRepositoryConnector"};
+  }
+  
+  protected String[] getOutputNames()
+  {
+    return new String[]{"Null Output"};
+  }
+  
+  protected String[] getOutputClasses()
+  {
+    return new String[]{"org.apache.manifoldcf.agents.output.nullconnector.NullConnector"};
+  }
+  
+  // API support
+  
+  // These methods allow communication with the ManifoldCF api webapp, via the locally-instantiated
jetty
+  
+  /** Construct a command url.
+  */
+  protected String makeAPIURL(String command)
+  {
+    return "http://localhost:"+Integer.toString(testPort)+"/mcf-api-service/json/"+command;
+  }
+  
+  /** Perform an json API GET operation.
+  *@param apiURL is the operation.
+  *@param expectedResponse is the expected response code.
+  *@return the json response.
+  */
+  protected String performAPIGetOperation(String apiURL, int expectedResponse)
+    throws Exception
+  {
+    HttpClient client = new HttpClient();
+    GetMethod method = new GetMethod(apiURL);
+    int response = client.executeMethod(method);
+    byte[] responseData = method.getResponseBody();
+    String responseString = new String(responseData,"utf-8");
+    if (response != expectedResponse)
+      throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+",
saw "+Integer.toString(response)+": "+responseString);
+    // We presume that the data is utf-8, since that's what the API uses throughout.
+    return responseString;
+  }
+
+  /** Perform an json API DELETE operation.
+  *@param apiURL is the operation.
+  *@param expectedResponse is the expected response code.
+  *@return the json response.
+  */
+  protected String performAPIDeleteOperation(String apiURL, int expectedResponse)
+    throws Exception
+  {
+    HttpClient client = new HttpClient();
+    DeleteMethod method = new DeleteMethod(apiURL);
+    int response = client.executeMethod(method);
+    byte[] responseData = method.getResponseBody();
+    String responseString = new String(responseData,"utf-8");
+    if (response != expectedResponse)
+      throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+",
saw "+Integer.toString(response)+": "+responseString);
+    // We presume that the data is utf-8, since that's what the API uses throughout.
+    return responseString;
+  }
+
+  /** Perform an json API PUT operation.
+  *@param apiURL is the operation.
+  *@param input is the input JSON.
+  *@param expectedResponse is the expected response code.
+  *@return the json response.
+  */
+  protected String performAPIPutOperation(String apiURL, int expectedResponse, String input)
+    throws Exception
+  {
+    HttpClient client = new HttpClient();
+    PutMethod method = new PutMethod(apiURL);
+    method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
+    method.setRequestBody(input);
+    int response = client.executeMethod(method);
+    byte[] responseData = method.getResponseBody();
+    String responseString = new String(responseData,"utf-8");
+    if (response != expectedResponse)
+      throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+",
saw "+Integer.toString(response)+": "+responseString);
+    // We presume that the data is utf-8, since that's what the API uses throughout.
+    return responseString;
+  }
+
+  /** Perform an json API POST operation.
+  *@param apiURL is the operation.
+  *@param input is the input JSON.
+  *@param expectedResponse is the expected response code.
+  *@return the json response.
+  */
+  protected String performAPIPostOperation(String apiURL, int expectedResponse, String input)
+    throws Exception
+  {
+    HttpClient client = new HttpClient();
+    PostMethod method = new PostMethod(apiURL);
+    method.setRequestHeader("Content-type", "text/plain; charset=UTF-8");
+    method.setRequestBody(input);
+    int response = client.executeMethod(method);
+    byte[] responseData = method.getResponseBody();
+    String responseString = new String(responseData,"utf-8");
+    if (response != expectedResponse)
+      throw new Exception("API http error; expected "+Integer.toString(expectedResponse)+",
saw "+Integer.toString(response)+": "+responseString);
+    // We presume that the data is utf-8, since that's what the API uses throughout.
+    return responseString;
+  }
+
+  /** Perform a json GET API operation, using Configuration structures to represent the json.
 This is for testing convenience,
+  * mostly.
+  */
+  protected Configuration performAPIGetOperationViaNodes(String command, int expectedResponse)
+    throws Exception
+  {
+    String result = performAPIGetOperation(makeAPIURL(command),expectedResponse);
+    Configuration cfg = new Configuration();
+    cfg.fromJSON(result);
+    return cfg;
+  }
+
+  /** Perform a json DELETE API operation, using Configuration structures to represent the
json.  This is for testing convenience,
+  * mostly.
+  */
+  protected Configuration performAPIDeleteOperationViaNodes(String command, int expectedResponse)
+    throws Exception
+  {
+    String result = performAPIDeleteOperation(makeAPIURL(command),expectedResponse);
+    Configuration cfg = new Configuration();
+    cfg.fromJSON(result);
+    return cfg;
+  }
+
+  /** Perform a json PUT API operation, using Configuration structures to represent the json.
 This is for testing convenience,
+  * mostly.
+  */
+  protected Configuration performAPIPutOperationViaNodes(String command, int expectedResponse,
Configuration argument)
+    throws Exception
+  {
+    String argumentJson;
+    if (argument != null)
+      argumentJson = argument.toJSON();
+    else
+      argumentJson = null;
+    
+    String result = performAPIPutOperation(makeAPIURL(command),expectedResponse,argumentJson);
+    Configuration cfg = new Configuration();
+    cfg.fromJSON(result);
+    return cfg;
+  }
+
+  /** Perform a json POST API operation, using Configuration structures to represent the
json.  This is for testing convenience,
+  * mostly.
+  */
+  protected Configuration performAPIPostOperationViaNodes(String command, int expectedResponse,
Configuration argument)
+    throws Exception
+  {
+    String argumentJson;
+    if (argument != null)
+      argumentJson = argument.toJSON();
+    else
+      argumentJson = null;
+    
+    String result = performAPIPostOperation(makeAPIURL(command),expectedResponse,argumentJson);
+    Configuration cfg = new Configuration();
+    cfg.fromJSON(result);
+    return cfg;
+  }
+
+  // Setup/teardown
+  
+  @Before
+  public void setUp()
+    throws Exception
+  {
+    super.setUp();
+    // Start jetty
+    server = new Server( testPort );    
+    server.setStopAtShutdown( true );
+    
+    String crawlerWarPath = "../../framework/dist/web/war/mcf-crawler-ui.war";
+    String authorityserviceWarPath = "../../framework/dist/web/war/mcf-authority-service.war";
+    String apiWarPath = "../../framework/dist/web/war/mcf-api-service.war";
+
+    if (System.getProperty("crawlerWarPath") != null)
+    	crawlerWarPath = System.getProperty("crawlerWarPath");
+    if (System.getProperty("authorityserviceWarPath") != null)
+    	authorityserviceWarPath = System.getProperty("authorityserviceWarPath");
+    if (System.getProperty("apiWarPath") != null)
+    	apiWarPath = System.getProperty("apiWarPath");
+
+    // Initialize the servlets
+    WebAppContext lcfCrawlerUI = new WebAppContext(crawlerWarPath,"/mcf-crawler-ui");
+    // This will cause jetty to ignore all of the framework and jdbc jars in the war, which
is what we want.
+    lcfCrawlerUI.setParentLoaderPriority(true);
+    server.addHandler(lcfCrawlerUI);
+    WebAppContext lcfAuthorityService = new WebAppContext(authorityserviceWarPath,"/mcf-authority-service");
+    // This will cause jetty to ignore all of the framework and jdbc jars in the war, which
is what we want.
+    lcfAuthorityService.setParentLoaderPriority(true);
+    server.addHandler(lcfAuthorityService);
+    WebAppContext lcfApi = new WebAppContext(apiWarPath,"/mcf-api-service");
+    lcfApi.setParentLoaderPriority(true);
+    server.addHandler(lcfApi);
+    server.start();
+
+    alfrescoServer = new Server(9090);
+    alfrescoServer.setStopAtShutdown(true);
+
+    String alfrescoServerWarPath = "../../tests/alfresco/alfresco-war/target/alfresco.war";
+
+    if (System.getProperty("alfrescoServerWarPath") != null)
+      alfrescoServerWarPath = System.getProperty("alfrescoServerWarPath");
+    
+    //Initialize Alfresco Server bindings
+    WebAppContext alfrescoServerApi = new WebAppContext(alfrescoServerWarPath,"/alfresco");
+    alfrescoServerApi.setParentLoaderPriority(false);
+    alfrescoServer.addHandler(alfrescoServerApi);
+    
+    Class h2DataSource = Thread.currentThread().getContextClassLoader().loadClass("org.h2.jdbcx.JdbcDataSource");
+    Object o = h2DataSource.newInstance();
+    String jdbcUrl = "jdbc:h2:.alf_data_jetty/h2_data/alf_jetty";
+    String jdbcUsername = "alfresco";
+    String jdbcPassword = "alfresco";
+    String jdbcJndiName = "jdbc/dataSource";
+    h2DataSource.getMethod("setURL", new Class[] {String.class}).invoke(o, new Object[] {jdbcUrl});
+    h2DataSource.getMethod("setUser", new Class[] {String.class}).invoke(o, new Object[]
{jdbcUsername});
+    h2DataSource.getMethod("setPassword", new Class[] {String.class}).invoke(o, new Object[]
{jdbcPassword});
+    
+    Resource jdbcResource = new Resource(jdbcJndiName, o);
+    
+    alfrescoServer.start();
+    boolean entered = false;
+    
+    while(server.isStarted() 
+        && alfrescoServer.isStarted() 
+        && alfrescoServerApi.isStarted()
+        && lcfApi.isStarted()
+        && lcfAuthorityService.isStarted()
+        && lcfCrawlerUI.isStarted()
+        && !entered){
+      entered = true;
+      ManifoldCF.sleep(5000);
+      // If all worked, then we can start the daemon.
+      // Clear the agents shutdown signal.
+      IThreadContext tc = ThreadContextFactory.make();
+      ILockManager lockManager = LockManagerFactory.make(tc);
+      lockManager.clearGlobalFlag(agentShutdownSignal);
+  
+      daemonThread = new DaemonThread();
+      daemonThread.start();
+    }
+  }
+  
+  @After
+  public void cleanUp()
+    throws Exception
+  {
+    initialize();
+    if (isInitialized())
+    {
+      Exception currentException = null;
+      IThreadContext tc = ThreadContextFactory.make();
+
+      // Delete all jobs (and wait for them to go away)
+      if (daemonThread != null)
+      {
+        IJobManager jobManager = JobManagerFactory.make(tc);
+        
+        // Get a list of the current active jobs
+        IJobDescription[] jobs = jobManager.getAllJobs();
+        int i = 0;
+        while (i < jobs.length)
+        {
+          IJobDescription desc = jobs[i++];
+          // Abort this job, if it is running
+          try
+          {
+            jobManager.manualAbort(desc.getID());
+          }
+          catch (ManifoldCFException e)
+          {
+            // This generally means that the job was not running
+          }
+        }
+        i = 0;
+        while (i < jobs.length)
+        {
+          IJobDescription desc = jobs[i++];
+          // Wait for this job to stop
+          while (true)
+          {
+            JobStatus status = jobManager.getStatus(desc.getID(),false);
+            if (status != null)
+            {
+              int statusValue = status.getStatus();
+              switch (statusValue)
+              {
+              case JobStatus.JOBSTATUS_NOTYETRUN:
+              case JobStatus.JOBSTATUS_COMPLETED:
+              case JobStatus.JOBSTATUS_ERROR:
+                break;
+              default:
+                ManifoldCF.sleep(10000);
+                continue;
+              }
+            }
+            break;
+          }
+        }
+
+        // Now, delete them all
+        i = 0;
+        while (i < jobs.length)
+        {
+          IJobDescription desc = jobs[i++];
+          try
+          {
+            jobManager.deleteJob(desc.getID());
+          }
+          catch (ManifoldCFException e)
+          {
+            // This usually means that the job is already being deleted
+          }
+        }
+
+        i = 0;
+        while (i < jobs.length)
+        {
+          IJobDescription desc = jobs[i++];
+          // Wait for this job to disappear
+          while (true)
+          {
+            JobStatus status = jobManager.getStatus(desc.getID(),false);
+            if (status != null)
+            {
+              ManifoldCF.sleep(10000);
+              continue;
+            }
+            break;
+          }
+        }
+
+        // Shut down daemon
+        ILockManager lockManager = LockManagerFactory.make(tc);
+        lockManager.setGlobalFlag(agentShutdownSignal);
+      
+        // Wait for daemon thread to exit.
+        while (true)
+        {
+          if (daemonThread.isAlive())
+          {
+            Thread.sleep(1000L);
+            continue;
+          }
+          break;
+        }
+
+        Exception e = daemonThread.getDaemonException();
+        if (e != null)
+          currentException = e;
+      }
+      
+      if (server != null)
+      {
+        server.stop();
+        server.join();
+        server = null;
+      }
+      
+      // Clean up everything else
+      try
+      {
+        super.cleanUp();
+      }
+      catch (Exception e)
+      {
+        if (currentException == null)
+          currentException = e;
+      }
+      if (currentException != null)
+        throw currentException;
+    }
+  }
+  
+  protected static class DaemonThread extends Thread
+  {
+    protected Exception daemonException = null;
+    
+    public DaemonThread()
+    {
+      setName("Daemon thread");
+    }
+    
+    public void run()
+    {
+      IThreadContext tc = ThreadContextFactory.make();
+      // Now, start the server, and then wait for the shutdown signal.  On shutdown, we have
to actually do the cleanup,
+      // because the JVM isn't going away.
+      try
+      {
+        ILockManager lockManager = LockManagerFactory.make(tc);
+        while (true)
+        {
+          // Any shutdown signal yet?
+          if (lockManager.checkGlobalFlag(agentShutdownSignal))
+            break;
+            
+          // Start whatever agents need to be started
+          ManifoldCF.startAgents(tc);
+
+          try
+          {
+            ManifoldCF.sleep(5000);
+          }
+          catch (InterruptedException e)
+          {
+            break;
+          }
+        }
+      }
+      catch (ManifoldCFException e)
+      {
+        daemonException = e;
+      }
+      finally
+      {
+        try
+        {
+          ManifoldCF.stopAgents(tc);
+        }
+        catch (ManifoldCFException e)
+        {
+          daemonException = e;
+        }
+      }
+    }
+    
+    public Exception getDaemonException()
+    {
+      return daemonException;
+    }
+    
+  }
+
+}

Propchange: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/lcf/branches/CONNECTORS-287/tests/alfresco/src/test/java/org/apache/manifoldcf/alfresco_tests/Base.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/lcf/branches/CONNECTORS-287/tests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-287/tests/pom.xml?rev=1203860&r1=1203859&r2=1203860&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-287/tests/pom.xml (original)
+++ incubator/lcf/branches/CONNECTORS-287/tests/pom.xml Fri Nov 18 21:42:08 2011
@@ -24,19 +24,17 @@
     <version>0.4.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
-
-  <groupId>org.apache.manifoldcf</groupId>
   <artifactId>mcf-tests</artifactId>
-  <version>0.4.0-SNAPSHOT</version>
-
   <name>ManifoldCF - Tests</name>
   <packaging>pom</packaging>
-
   <modules>
+    <module>alfresco</module>
+    <!-- 
     <module>wiki</module>
     <module>cmis</module>
     <module>filesystem</module>
     <module>sharepoint</module>
+    -->
   </modules>
   <build>
     <defaultGoal>integration-test</defaultGoal>



Mime
View raw message