Return-Path: X-Original-To: apmail-manifoldcf-commits-archive@www.apache.org Delivered-To: apmail-manifoldcf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 515EC17CDF for ; Mon, 20 Oct 2014 11:00:08 +0000 (UTC) Received: (qmail 85445 invoked by uid 500); 20 Oct 2014 11:00:08 -0000 Delivered-To: apmail-manifoldcf-commits-archive@manifoldcf.apache.org Received: (qmail 85395 invoked by uid 500); 20 Oct 2014 11:00:08 -0000 Mailing-List: contact commits-help@manifoldcf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@manifoldcf.apache.org Delivered-To: mailing list commits@manifoldcf.apache.org Received: (qmail 85382 invoked by uid 99); 20 Oct 2014 11:00:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Oct 2014 11:00:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Oct 2014 11:00:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2DC062388993; Mon, 20 Oct 2014 10:59:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1633098 - in /manifoldcf/branches/CONNECTORS-1060/connectors/alfresco-webscript: ./ connector/src/test/java/org/apache/manifoldcf/crawler/connectors/alfrescowebscript/tests/ Date: Mon, 20 Oct 2014 10:59:46 -0000 To: commits@manifoldcf.apache.org From: maoo@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141020105946.2DC062388993@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 parameter = new HashMap(); + 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 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 properties = new HashMap(); + 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 @@ + org.apache.chemistry.opencmis + chemistry-opencmis-client-impl + 0.10.0 + test + + ${project.groupId} mcf-core ${project.version} @@ -375,14 +381,14 @@ jsp-api-2.1-glassfish ${glassfish.version} test - + org.mortbay.jetty jsp-2.1-glassfish ${glassfish.version} test - + org.slf4j slf4j-api @@ -418,4 +424,4 @@ - \ No newline at end of file +