You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by ma...@apache.org on 2014/10/20 12:59:46 UTC
svn commit: r1633098 - in
/manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript: ./
connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/
Author: maoo
Date: Mon Oct 20 10:59:45 2014
New Revision: 1633098
URL: http://svn.apache.org/r1633098
Log:
added OpenCmis client (CMISUtils) on ITs to load some content into Alfresco
Added:
manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/CMISUtils.java
Modified:
manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/APISanityHSQLDBIT.java
manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/BaseITHSQLDB.java
manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/pom.xml
Modified: manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/APISanityHSQLDBIT.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/APISanityHSQLDBIT.java?rev=1633098&r1=1633097&r2=1633098&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/APISanityHSQLDBIT.java (original)
+++ manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/APISanityHSQLDBIT.java Mon Oct 20 10:59:45 2014
@@ -27,21 +27,31 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
public class APISanityHSQLDBIT extends BaseITHSQLDB
{
-
- private static final String REPLACER = "?";
- private static final String ALFRESCO_TEST_QUERY = "PATH:\"/app:company_home/cm:testdata\"";
-
- private static final String ALFRESCO_USERNAME = "admin";
- private static final String ALFRESCO_PASSWORD = "admin";
- private static final String ALFRESCO_PROTOCOL = "http";
- private static final String ALFRESCO_HOST = "localhost";
- private static final String ALFRESCO_PORT = "9090";
- private static final String ALFRESCO_CONTEXT = "/alfresco";
- private static final int SOCKET_TIMEOUT = 120000;
- private static final String ALFRESCO_ENDPOINT_TEST_SERVER =
- ALFRESCO_PROTOCOL+"://"+ALFRESCO_HOST+":"+ALFRESCO_PORT+ALFRESCO_CONTEXT;
+ private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHss");
+
+ //@TODO - Should be moved into AlfrescoConnector.java
+ public static final String ALFRESCO_PROTOCOL_PARAM = "protocol";
+ public static final String ALFRESCO_HOSTNAME_PARAM = "hostname";
+ public static final String ALFRESCO_PORT_PARAM = "port";
+ public static final String ALFRESCO_ENDPOINT_PARAM = "/alfresco/service";
+ public static final String ALFRESCO_STOREPROTOCOL_PARAM = "storeprotocol";
+ public static final String ALFRESCO_STOREID_PARAM = "storeid";
+ public static final String ALFRESCO_USERNAME_PARAM = "username";
+ public static final String ALFRESCO_PASSWORD_PARAM = "password";
+
+ public static final String ALFRESCO_PROTOCOL = "http";
+ public static final String ALFRESCO_HOSTNAME = "localhost";
+ public static final String ALFRESCO_PORT = "9090";
+ public static final String ALFRESCO_ENDPOINT = "/alfresco/service";
+ public static final String ALFRESCO_STOREPROTOCOL = "workspace";
+ public static final String ALFRESCO_STOREID = "SpacesStore";
+ public static final String ALFRESCO_USERNAME = "admin";
+ public static final String ALFRESCO_PASSWORD = "admin";
@Before
public void createTestArea()
@@ -51,7 +61,14 @@ public class APISanityHSQLDBIT extends B
try
{
- //@TODO - Add cmis client logic to push some documents into Alfresco
+ //Adding a document in Alfresco via CMIS
+ CMISUtils cdc = new CMISUtils();
+ cdc.setServiceUrl(ALFRESCO_PROTOCOL+"://"+ALFRESCO_HOSTNAME+":"+ALFRESCO_PORT + "/alfresco/api/-default-/public/cmis/versions/1.1/atom");
+ cdc.setUser("admin");
+ cdc.setPassword("admin");
+ cdc.createDocument("test" + "." + sdf.format(new Date()), "cmis:document");
+
+ //@TODO - Add more logic to push documents into Alfresco
}
catch (Exception e)
{
@@ -92,7 +109,7 @@ public class APISanityHSQLDBIT extends B
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("description");
- child.setValue("An Alfresco Repository Connector");
+ child.setValue("Alfresco Repository Connector");
connectionObject.addChild(connectionObject.getChildCount(),child);
child = new ConfigurationNode("max_connections");
@@ -102,29 +119,17 @@ public class APISanityHSQLDBIT extends B
child = new ConfigurationNode("configuration");
//Alfresco Repository Connector parameters
-
- //username
- ConfigurationNode alfrescoUsernameNode = new ConfigurationNode("_PARAMETER_");
- alfrescoUsernameNode.setAttribute("name", ALFRESCO_USERNAME);
- alfrescoUsernameNode.setValue(ALFRESCO_USERNAME);
- child.addChild(child.getChildCount(), alfrescoUsernameNode);
-
- //password
- ConfigurationNode alfrescoPasswordNode = new ConfigurationNode("_PARAMETER_");
- alfrescoPasswordNode.setAttribute("name", ALFRESCO_PASSWORD);
- alfrescoPasswordNode.setValue(ALFRESCO_PASSWORD);
- child.addChild(child.getChildCount(), alfrescoPasswordNode);
-
+
//protocol
ConfigurationNode alfrescoProtocolNode = new ConfigurationNode("_PARAMETER_");
- alfrescoProtocolNode.setAttribute("name", ALFRESCO_PROTOCOL);
+ alfrescoProtocolNode.setAttribute("name", ALFRESCO_PROTOCOL_PARAM);
alfrescoProtocolNode.setValue(ALFRESCO_PROTOCOL);
child.addChild(child.getChildCount(), alfrescoProtocolNode);
//server
ConfigurationNode alfrescoServerNode = new ConfigurationNode("_PARAMETER_");
- alfrescoServerNode.setAttribute("name", ALFRESCO_HOST);
- alfrescoServerNode.setValue(ALFRESCO_HOST);
+ alfrescoServerNode.setAttribute("name", ALFRESCO_HOSTNAME_PARAM);
+ alfrescoServerNode.setValue(ALFRESCO_HOSTNAME);
child.addChild(child.getChildCount(), alfrescoServerNode);
//port
@@ -133,18 +138,36 @@ public class APISanityHSQLDBIT extends B
alfrescoPortNode.setValue(ALFRESCO_PORT);
child.addChild(child.getChildCount(), alfrescoPortNode);
- //path
- ConfigurationNode alfrescoPathNode = new ConfigurationNode("_PARAMETER_");
- alfrescoPathNode.setAttribute("name", ALFRESCO_CONTEXT);
- alfrescoPathNode.setValue(ALFRESCO_CONTEXT);
- child.addChild(child.getChildCount(), alfrescoPathNode);
-
- //socketTimeout
- ConfigurationNode socketTimeoutNode = new ConfigurationNode("_PARAMETER_");
- socketTimeoutNode.setAttribute("name", "60000");
- socketTimeoutNode.setValue(String.valueOf(SOCKET_TIMEOUT));
- child.addChild(child.getChildCount(), socketTimeoutNode);
-
+ //endpoint
+ ConfigurationNode alfrescoEndpointNode = new ConfigurationNode("_PARAMETER_");
+ alfrescoEndpointNode.setAttribute("name", ALFRESCO_ENDPOINT_PARAM);
+ alfrescoEndpointNode.setValue(ALFRESCO_ENDPOINT);
+ child.addChild(child.getChildCount(), alfrescoEndpointNode);
+
+ //storeProtocol
+ ConfigurationNode alfrescoStoreProtocol = new ConfigurationNode("_PARAMETER_");
+ alfrescoStoreProtocol.setAttribute("name", ALFRESCO_STOREPROTOCOL_PARAM);
+ alfrescoStoreProtocol.setValue(ALFRESCO_STOREPROTOCOL);
+ child.addChild(child.getChildCount(), alfrescoStoreProtocol);
+
+ //storeId
+ ConfigurationNode alfrescoStoreId = new ConfigurationNode("_PARAMETER_");
+ alfrescoStoreId.setAttribute("name", ALFRESCO_STOREID_PARAM);
+ alfrescoStoreId.setValue(ALFRESCO_STOREID);
+ child.addChild(child.getChildCount(), alfrescoStoreId);
+
+ //username
+ ConfigurationNode alfrescoUsernameNode = new ConfigurationNode("_PARAMETER_");
+ alfrescoUsernameNode.setAttribute("name", ALFRESCO_USERNAME_PARAM);
+ alfrescoUsernameNode.setValue(ALFRESCO_USERNAME);
+ child.addChild(child.getChildCount(), alfrescoUsernameNode);
+
+ //password
+ ConfigurationNode alfrescoPasswordNode = new ConfigurationNode("_PARAMETER_");
+ alfrescoPasswordNode.setAttribute("name", ALFRESCO_PASSWORD_PARAM);
+ alfrescoPasswordNode.setValue(ALFRESCO_PASSWORD);
+ child.addChild(child.getChildCount(), alfrescoPasswordNode);
+
connectionObject.addChild(connectionObject.getChildCount(),child);
requestObject = new Configuration();
Modified: manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/BaseITHSQLDB.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/BaseITHSQLDB.java?rev=1633098&r1=1633097&r2=1633098&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/BaseITHSQLDB.java (original)
+++ manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/BaseITHSQLDB.java Mon Oct 20 10:59:45 2014
@@ -18,6 +18,7 @@
*/
package org.apache.manifoldcf.crawler.connectors.alfrescowebscript.tests;
+import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
@@ -60,10 +61,15 @@ public class BaseITHSQLDB extends org.ap
if (System.getProperty("alfrescoServerWarPath") != null)
alfrescoServerWarPath = System.getProperty("alfrescoServerWarPath");
-
+
ContextHandlerCollection contexts = new ContextHandlerCollection();
alfrescoServer.setHandler(contexts);
+
WebAppContext alfrescoServerApi = new WebAppContext(alfrescoServerWarPath,"/alfresco");
+ alfrescoServerApi.setParentLoaderPriority(false);
+ HashLoginService dummyLoginService = new HashLoginService("TEST-SECURITY-REALM");
+ alfrescoServerApi.getSecurityHandler().setLoginService(dummyLoginService);
+ contexts.addHandler(alfrescoServerApi);
alfrescoServer.start();
boolean entered = false;
Added: manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/CMISUtils.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/CMISUtils.java?rev=1633098&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/CMISUtils.java (added)
+++ manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/CMISUtils.java Mon Oct 20 10:59:45 2014
@@ -0,0 +1,98 @@
+package org.apache.manifoldcf.crawler.connectors.alfrescowebscript.tests;
+
+
+import org.apache.chemistry.opencmis.client.api.*;
+import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
+import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.enums.BindingType;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class CMISUtils {
+
+ private String serviceUrl = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
+ private String user;
+ private String password;
+ private String folderName = "";
+
+ private Session session = null;
+ public Session getSession() {
+ if (session == null) {
+ SessionFactory factory = SessionFactoryImpl.newInstance();
+ Map<String, String> parameter = new HashMap<String, String>();
+ parameter.put(SessionParameter.USER, getUser());
+ parameter.put(SessionParameter.PASSWORD, getPassword());
+ parameter.put(SessionParameter.ATOMPUB_URL, getServiceUrl());
+ parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
+ List<Repository> repositories = factory.getRepositories(parameter);
+ this.session = repositories.get(0).createSession();
+ }
+ return this.session;
+ }
+
+ public Document createDocument(String docName, String contentType) {
+ Session session = getSession();
+ Folder folder = (Folder) session.getObjectByPath("/" + getFolderName());
+ String timeStamp = new Long(System.currentTimeMillis()).toString();
+ String filename = docName + " (" + timeStamp + ")";
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.OBJECT_TYPE_ID, contentType);
+ properties.put(PropertyIds.NAME, filename);
+ properties.put(PropertyIds.IS_MAJOR_VERSION, true);
+ properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, true);
+
+ String docText = "Lorem ipsum";
+ byte[] content = docText.getBytes();
+ InputStream stream = new ByteArrayInputStream(content);
+ ContentStream contentStream = session.getObjectFactory().createContentStream(
+ filename,
+ Long.valueOf(content.length),
+ "text/plain",
+ stream);
+ Document doc = folder.createDocument(
+ properties,
+ contentStream,
+ VersioningState.MAJOR);
+
+ return doc;
+ }
+
+ public String getServiceUrl() {
+ return serviceUrl;
+ }
+
+ public void setServiceUrl(String serviceUrl) {
+ this.serviceUrl = serviceUrl;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getFolderName() {
+ return folderName;
+ }
+
+ public void setFolderName(String folderName) {
+ this.folderName = folderName;
+ }
+}
Modified: manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/pom.xml
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/pom.xml?rev=1633098&r1=1633097&r2=1633098&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/pom.xml (original)
+++ manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript/pom.xml Mon Oct 20 10:59:45 2014
@@ -241,6 +241,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.chemistry.opencmis</groupId>
+ <artifactId>chemistry-opencmis-client-impl</artifactId>
+ <version>0.10.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mcf-core</artifactId>
<version>${project.version}</version>
@@ -375,14 +381,14 @@
<artifactId>jsp-api-2.1-glassfish</artifactId>
<version>${glassfish.version}</version>
<scope>test</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-glassfish</artifactId>
<version>${glassfish.version}</version>
<scope>test</scope>
</dependency>
-
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -418,4 +424,4 @@
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>