mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
42804: Merged BRANCHES/DEV/BELARUS/V4.1-BUG-FIX-2012_10_17 to BRANCHES/DEV/V4.1-BUG-FIX: 42748: ALF-14200: Adding Invalid Aspects Via CMIS ATOM API Results in NullPointerException 42810: Fix for ALF-15276 - sys:locale Attribute No Longer Available From jsnode 42814: ALF-15276 - small improvement to remove duplicated data from response 42824: ALF-15048: Merged PATCHES/V4.0.2 to V4.1-BUG-FIX 42724: ALF-16048: CLONE - Version history doesn't go beyond two versions (0.1 and 0.2) when dragged and dropped via CIFS from Mac Lion OSx 42739: ALF-16048: New files missing from previous check in 42742: ALF-16048: Another missing file. 42839: ALF-16417: Fix "Hybrid Sync - can retain invalid cloud tickets in a local cache" - retry once for invalid auth - also externalise the implicit/default cache config 42849: NodeDAO: Added new method to retrieve specific store ID - public Pair<Long, StoreRef> getStore(StoreRef storeRef); 42857: Merged DEV to V4.1-BUG-FIX 42821: ALF-13506 : WCMQS Example Application Caching Causes Changes to Inconsistently Appear on the Editorial Web Site Concurrency was improved for AssetImpl class. The returned values of the collections were made unmodifiable in the classes which implement Resource interface. 42872: ALF-15601: "Performance issue using CMIS method getChildren() - gets version history" - avoids getting the version history (an expensive operation) if possible i.e. in the case of current version (live) nodes like for getChildren 42900: Merged DEV to V4.1-BUG-FIX 42734: ALF-15335 : 'external' authentication subsystem debug information too scarce Extended debug information in the authentication subsystem. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42904 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
206 lines
8.0 KiB
Java
206 lines
8.0 KiB
Java
/*
|
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
|
*
|
|
* This file is part of Alfresco
|
|
*
|
|
* Alfresco is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Alfresco is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package org.alfresco.opencmis;
|
|
|
|
import java.util.Calendar;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.repo.content.filestore.FileContentWriter;
|
|
import org.alfresco.service.cmr.repository.ContentReader;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.util.ApplicationContextHelper;
|
|
import org.alfresco.util.GUID;
|
|
import org.alfresco.util.TempFileProvider;
|
|
import org.apache.chemistry.opencmis.client.api.Document;
|
|
import org.apache.chemistry.opencmis.client.api.Folder;
|
|
import org.apache.chemistry.opencmis.client.api.Repository;
|
|
import org.apache.chemistry.opencmis.client.api.Session;
|
|
import org.apache.chemistry.opencmis.client.api.SessionFactory;
|
|
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.enums.BindingType;
|
|
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
|
|
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
|
|
import org.apache.chemistry.opencmis.commons.impl.server.AbstractServiceFactory;
|
|
import org.apache.chemistry.opencmis.commons.server.CallContext;
|
|
import org.apache.chemistry.opencmis.commons.server.CmisService;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
/**
|
|
* Tests basic local CMIS interaction
|
|
*
|
|
* @author Derek Hulley
|
|
* @since 4.0
|
|
*/
|
|
public class OpenCmisLocalTest extends TestCase
|
|
{
|
|
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
|
|
|
|
/**
|
|
* Test class to provide the service factory
|
|
*
|
|
* @author Derek Hulley
|
|
* @since 4.0
|
|
*/
|
|
public static class TestCmisServiceFactory extends AbstractServiceFactory
|
|
{
|
|
private static AlfrescoCmisServiceFactory serviceFactory = (AlfrescoCmisServiceFactory) ctx.getBean("CMISServiceFactory");
|
|
@Override
|
|
public void init(Map<String, String> parameters)
|
|
{
|
|
serviceFactory.init(parameters);
|
|
}
|
|
|
|
@Override
|
|
public void destroy()
|
|
{
|
|
}
|
|
|
|
@Override
|
|
public CmisService getService(CallContext context)
|
|
{
|
|
return serviceFactory.getService(context);
|
|
}
|
|
|
|
}
|
|
|
|
private Repository getRepository(String user, String password)
|
|
{
|
|
// default factory implementation
|
|
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
|
|
Map<String, String> parameters = new HashMap<String, String>();
|
|
|
|
// user credentials
|
|
parameters.put(SessionParameter.USER, "admin");
|
|
parameters.put(SessionParameter.PASSWORD, "admin");
|
|
|
|
// connection settings
|
|
parameters.put(SessionParameter.BINDING_TYPE, BindingType.LOCAL.value());
|
|
parameters.put(SessionParameter.LOCAL_FACTORY, "org.alfresco.opencmis.OpenCmisLocalTest$TestCmisServiceFactory");
|
|
|
|
// create session
|
|
List<Repository> repositories = sessionFactory.getRepositories(parameters);
|
|
return repositories.size() > 0 ? repositories.get(0) : null;
|
|
}
|
|
|
|
public void setUp() throws Exception
|
|
{
|
|
}
|
|
|
|
public void testVoid()
|
|
{
|
|
|
|
}
|
|
|
|
public void DISABLED_testSetUp() throws Exception
|
|
{
|
|
Repository repository = getRepository("admin", "admin");
|
|
assertNotNull("No repository available for testing", repository);
|
|
}
|
|
|
|
public void DISABLED_testBasicFileOps()
|
|
{
|
|
Repository repository = getRepository("admin", "admin");
|
|
Session session = repository.createSession();
|
|
Folder rootFolder = session.getRootFolder();
|
|
// create folder
|
|
Map<String,String> folderProps = new HashMap<String, String>();
|
|
{
|
|
folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
|
|
folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate());
|
|
}
|
|
Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext());
|
|
|
|
Map<String, String> fileProps = new HashMap<String, String>();
|
|
{
|
|
fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
|
|
fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
|
|
}
|
|
ContentStreamImpl fileContent = new ContentStreamImpl();
|
|
{
|
|
ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt"));
|
|
writer.putContent("Ipsum and so on");
|
|
ContentReader reader = writer.getReader();
|
|
fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
|
fileContent.setStream(reader.getContentInputStream());
|
|
}
|
|
folder.createDocument(fileProps, fileContent, VersioningState.MAJOR);
|
|
}
|
|
|
|
public void testALF10085() throws InterruptedException
|
|
{
|
|
Repository repository = getRepository("admin", "admin");
|
|
Session session = repository.createSession();
|
|
Folder rootFolder = session.getRootFolder();
|
|
|
|
Map<String, String> props = new HashMap<String, String>();
|
|
{
|
|
props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
|
|
props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
|
|
}
|
|
Document doc1 = rootFolder.createDocument(props, null, null);
|
|
|
|
props = new HashMap<String, String>();
|
|
{
|
|
props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
|
|
props.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
|
|
}
|
|
Document doc2 = rootFolder.createDocument(props, null, null);
|
|
|
|
Thread.sleep(6000);
|
|
|
|
session.getObject(doc1);
|
|
|
|
doc1.refresh();
|
|
Calendar doc1LastModifiedBefore = (Calendar)doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
|
|
assertNotNull(doc1LastModifiedBefore);
|
|
|
|
doc2.refresh();
|
|
Calendar doc2LastModifiedBefore = (Calendar)doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
|
|
assertNotNull(doc2LastModifiedBefore);
|
|
|
|
// Add relationship A to B
|
|
props = new HashMap<String, String>();
|
|
{
|
|
props.put(PropertyIds.OBJECT_TYPE_ID, "R:cmiscustom:assoc");
|
|
props.put(PropertyIds.NAME, "A Relationship");
|
|
props.put(PropertyIds.SOURCE_ID, doc1.getId());
|
|
props.put(PropertyIds.TARGET_ID, doc2.getId());
|
|
}
|
|
session.createRelationship(props);
|
|
|
|
doc1.refresh();
|
|
Calendar doc1LastModifiedAfter = (Calendar)doc1.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
|
|
assertNotNull(doc1LastModifiedAfter);
|
|
|
|
doc2.refresh();
|
|
Calendar doc2LastModifiedAfter = (Calendar)doc2.getProperty(PropertyIds.LAST_MODIFICATION_DATE).getFirstValue();
|
|
assertNotNull(doc2LastModifiedAfter);
|
|
|
|
assertEquals(doc1LastModifiedBefore, doc1LastModifiedAfter);
|
|
assertEquals(doc2LastModifiedBefore, doc2LastModifiedAfter);
|
|
}
|
|
}
|